[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 {templateconcept [*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]") && [sized_range](range.sized#concept:sized_range "25.4.4 Sized ranges [range.sized]"); // *exposition only*templateconcept [*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]") && [bidirectional_range](range.refinements#concept:bidirectional_range "25.4.6 Other range refinements [range.refinements]") && [common_range](range.refinements#concept:common_range "25.4.6 Other range refinements [range.refinements]"); templateconcept [*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]") && ![*slide-caches-last*](#concept:slide-caches-last "25.7.30.2 Class template slide_­view [range.slide.view]"); 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]")class slide_view : public view_interface> { V *base_*; // *exposition only* range_difference_t *n_*; // *exposition only*// [[range.slide.iterator]](range.slide.iterator "25.7.30.3 Class template slide_­view​::​iterator"), class template slide_view​::​*iterator*template 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 n); constexpr V base() const & requires [copy_constructible](concept.copyconstructible#concept:copy_constructible "18.4.14 Concept copy_­constructible [concept.copyconstructible]") { 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]") && [*slide-caches-nothing*](#concept:slide-caches-nothing "25.7.30.2 Class template slide_­view [range.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]"); constexpr auto end()requires (!([*simple-view*](range.utility.helpers#concept:simple-view "25.5.2 Helper concepts [range.utility.helpers]") && [*slide-caches-nothing*](#concept:slide-caches-nothing "25.7.30.2 Class template slide_­view [range.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]"); constexpr auto size() requires [sized_range](range.sized#concept:sized_range "25.4.4 Sized ranges [range.sized]"); constexpr auto size() const requires [sized_range](range.sized#concept:sized_range "25.4.4 Sized ranges [range.sized]"); constexpr auto reserve_hintsize() requires [approximately_sized_range](range.approximately.sized#concept:approximately_sized_range "25.4.3 Approximately sized ranges [range.approximately.sized]"); 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]"); }; template slide_view(R&&, range_difference_t) -> slide_view>;} [🔗](#lib:slide_view,constructor_) `constexpr explicit slide_view(V base, range_difference_t 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]") && [slide-caches-nothing](#concept:slide-caches-nothing "25.7.30.2 Class template slide_­view [range.slide.view]"))); ` [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*(ranges::begin(*base_*), ranges::next(ranges::begin(*base_*), *n_* - 1, ranges::end(*base_*)), *n_*) - [(3.2)](#3.2) Otherwise, *iterator*(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]"); ` [5](#5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L15005) *Returns*: *iterator*(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]") && [slide-caches-nothing](#concept:slide-caches-nothing "25.7.30.2 Class template slide_­view [range.slide.view]"))); ` [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*(ranges::begin(*base_*) + range_difference_t(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*(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*(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]"); ` [8](#8) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L15054) *Returns*: begin() + range_difference_t(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]"); constexpr auto size() const requires [sized_range](range.sized#concept:sized_range "25.4.4 Sized ranges [range.sized]"); ` [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]"); 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]"); ` [10](#10) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L15083) *Effects*: Equivalent to:auto sz = static_cast>(ranges::reserve_hint(*base_*)) -*n_* + 1;if (sz < 0) sz = 0;return *to-unsigned-like*(sz);