[range.slide.view]

# 25 Ranges library [[ranges]](./#ranges)

## 25.7 Range adaptors [[range.adaptors]](range.adaptors#range.slide.view)

### 25.7.30 Slide view [[range.slide]](range.slide#view)

#### 25.7.30.2 Class template slide_view [range.slide.view]

[ð](#lib:slide_view)

namespace std::ranges {template<class V>concept [*slide-caches-nothing*](#concept:slide-caches-nothing "25.7.30.2 Class template slide_­view [range.slide.view]") = [random_access_range](range.refinements#concept:random_access_range "25.4.6 Other range refinements [range.refinements]")<V> && [sized_range](range.sized#concept:sized_range "25.4.4 Sized ranges [range.sized]")<V>; // *exposition only*template<class V>concept [*slide-caches-last*](#concept:slide-caches-last "25.7.30.2 Class template slide_­view [range.slide.view]") = // *exposition only*![*slide-caches-nothing*](#concept:slide-caches-nothing "25.7.30.2 Class template slide_­view [range.slide.view]")<V> && [bidirectional_range](range.refinements#concept:bidirectional_range "25.4.6 Other range refinements [range.refinements]")<V> && [common_range](range.refinements#concept:common_range "25.4.6 Other range refinements [range.refinements]")<V>; template<class V>concept [*slide-caches-first*](#concept:slide-caches-first "25.7.30.2 Class template slide_­view [range.slide.view]") = // *exposition only*![*slide-caches-nothing*](#concept:slide-caches-nothing "25.7.30.2 Class template slide_­view [range.slide.view]")<V> && ![*slide-caches-last*](#concept:slide-caches-last "25.7.30.2 Class template slide_­view [range.slide.view]")<V>; template<[forward_range](range.refinements#concept:forward_range "25.4.6 Other range refinements [range.refinements]") V>requires [view](range.view#concept:view "25.4.5 Views [range.view]")<V>class slide_view : public view_interface<slide_view<V>> { V *base_*; // *exposition only* range_difference_t<V> *n_*; // *exposition only*// [[range.slide.iterator]](range.slide.iterator "25.7.30.3 Class template slide_­view​::​iterator"), class template slide_view​::​*iterator*template<bool> class *iterator*; // *exposition only*// [[range.slide.sentinel]](range.slide.sentinel "25.7.30.4 Class slide_­view​::​sentinel"), class slide_view​::​*sentinel*class *sentinel*; // *exposition only*public:constexpr explicit slide_view(V base, range_difference_t<V> n); constexpr V base() const & requires [copy_constructible](concept.copyconstructible#concept:copy_constructible "18.4.14 Concept copy_­constructible [concept.copyconstructible]")<V> { return *base_*; }constexpr V base() && { return std::move(*base_*); }constexpr auto begin()requires (!([*simple-view*](range.utility.helpers#concept:simple-view "25.5.2 Helper concepts [range.utility.helpers]")<V> && [*slide-caches-nothing*](#concept:slide-caches-nothing "25.7.30.2 Class template slide_­view [range.slide.view]")<const V>)); constexpr auto begin() const requires [*slide-caches-nothing*](#concept:slide-caches-nothing "25.7.30.2 Class template slide_­view [range.slide.view]")<const V>; constexpr auto end()requires (!([*simple-view*](range.utility.helpers#concept:simple-view "25.5.2 Helper concepts [range.utility.helpers]")<V> && [*slide-caches-nothing*](#concept:slide-caches-nothing "25.7.30.2 Class template slide_­view [range.slide.view]")<const V>)); constexpr auto end() const requires [*slide-caches-nothing*](#concept:slide-caches-nothing "25.7.30.2 Class template slide_­view [range.slide.view]")<const V>; constexpr auto size() requires [sized_range](range.sized#concept:sized_range "25.4.4 Sized ranges [range.sized]")<V>; constexpr auto size() const requires [sized_range](range.sized#concept:sized_range "25.4.4 Sized ranges [range.sized]")<const V>; constexpr auto reserve_hintsize() requires [approximately_sized_range](range.approximately.sized#concept:approximately_sized_range "25.4.3 Approximately sized ranges [range.approximately.sized]")<V>; constexpr auto reserve_hintsize() const requires [approximately_sized_range](range.approximately.sized#concept:approximately_sized_range "25.4.3 Approximately sized ranges [range.approximately.sized]")<const V>; }; template<class R> slide_view(R&&, range_difference_t<R>) -> slide_view<views::all_t<R>>;}

[ð](#lib:slide_view,constructor_)

`constexpr explicit slide_view(V base, range_difference_t<V> n);
`

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L14960)

*Preconditions*: n > 0 is true[.](#1.sentence-1)

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L14964)

*Effects*: Initializes *base_* with std​::​move(base) and*n_* with n[.](#2.sentence-1)

[ð](#lib:begin,slide_view)

`constexpr auto begin()
  requires (!([simple-view](range.utility.helpers#concept:simple-view "25.5.2 Helper concepts [range.utility.helpers]")<V> && [slide-caches-nothing](#concept:slide-caches-nothing "25.7.30.2 Class template slide_­view [range.slide.view]")<const V>));
`

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L14977)

*Returns*: 

- [(3.1)](#3.1)

If V models [*slide-caches-first*](#concept:slide-caches-first "25.7.30.2 Class template slide_­view [range.slide.view]"),*iterator*<false>(ranges::begin(*base_*),
 ranges::next(ranges::begin(*base_*), *n_* - 1, ranges::end(*base_*)), *n_*)

- [(3.2)](#3.2)

Otherwise, *iterator*<false>(ranges​::​begin(*base_*), *n_*)[.](#3.sentence-1)

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L14990)

*Remarks*: In order to provide the amortized constant-time complexity
required by the [range](range.range#concept:range "25.4.2 Ranges [range.range]") concept,
this function caches the result within the slide_view for use on subsequent calls
when V models [*slide-caches-first*](#concept:slide-caches-first "25.7.30.2 Class template slide_­view [range.slide.view]")[.](#4.sentence-1)

[ð](#lib:begin,slide_view_)

`constexpr auto begin() const requires [slide-caches-nothing](#concept:slide-caches-nothing "25.7.30.2 Class template slide_­view [range.slide.view]")<const V>;
`

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L15005)

*Returns*: *iterator*<true>(ranges​::​begin(*base_*), *n_*)[.](#5.sentence-1)

[ð](#lib:end,slide_view)

`constexpr auto end()
  requires (!([simple-view](range.utility.helpers#concept:simple-view "25.5.2 Helper concepts [range.utility.helpers]")<V> && [slide-caches-nothing](#concept:slide-caches-nothing "25.7.30.2 Class template slide_­view [range.slide.view]")<const V>));
`

[6](#6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L15017)

*Returns*: 

- [(6.1)](#6.1)

If V models [*slide-caches-nothing*](#concept:slide-caches-nothing "25.7.30.2 Class template slide_­view [range.slide.view]"),*iterator*<false>(ranges::begin(*base_*) + range_difference_t<V>(size()), *n_*)

- [(6.2)](#6.2)

Otherwise, if V models [*slide-caches-last*](#concept:slide-caches-last "25.7.30.2 Class template slide_­view [range.slide.view]"),*iterator*<false>(ranges::prev(ranges::end(*base_*), *n_* - 1, ranges::begin(*base_*)), *n_*)

- [(6.3)](#6.3)

Otherwise, if V models [common_range](range.refinements#concept:common_range "25.4.6 Other range refinements [range.refinements]"),*iterator*<false>(ranges::end(*base_*), ranges::end(*base_*), *n_*)

- [(6.4)](#6.4)

Otherwise, *sentinel*(ranges​::​end(*base_*))[.](#6.sentence-1)

[7](#7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L15039)

*Remarks*: In order to provide the amortized constant-time complexity
required by the [range](range.range#concept:range "25.4.2 Ranges [range.range]") concept,
this function caches the result within the slide_view for use on subsequent calls
when V models [*slide-caches-last*](#concept:slide-caches-last "25.7.30.2 Class template slide_­view [range.slide.view]")[.](#7.sentence-1)

[ð](#lib:end,slide_view_)

`constexpr auto end() const requires [slide-caches-nothing](#concept:slide-caches-nothing "25.7.30.2 Class template slide_­view [range.slide.view]")<const V>;
`

[8](#8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L15054)

*Returns*: begin() + range_difference_t<const V>(size())[.](#8.sentence-1)

[ð](#lib:size,slide_view)

`constexpr auto size() requires [sized_range](range.sized#concept:sized_range "25.4.4 Sized ranges [range.sized]")<V>;
constexpr auto size() const requires [sized_range](range.sized#concept:sized_range "25.4.4 Sized ranges [range.sized]")<const V>;
`

[9](#9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L15066)

*Effects*: Equivalent to:auto sz = ranges::distance(*base_*) - *n_* + 1;if (sz < 0) sz = 0;return *to-unsigned-like*(sz);

[ð](#lib:reserve_hint,slide_view)

`constexpr auto reserve_hint() requires [approximately_sized_range](range.approximately.sized#concept:approximately_sized_range "25.4.3 Approximately sized ranges [range.approximately.sized]")<V>;
constexpr auto reserve_hint() const requires [approximately_sized_range](range.approximately.sized#concept:approximately_sized_range "25.4.3 Approximately sized ranges [range.approximately.sized]")<const V>;
`

[10](#10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L15083)

*Effects*: Equivalent to:auto sz = static_cast<range_difference_t<decltype((*base_*))>>(ranges::reserve_hint(*base_*)) -*n_* + 1;if (sz < 0) sz = 0;return *to-unsigned-like*(sz);
