26 Ranges library [ranges]

26.7 Range adaptors [range.adaptors]

26.7.28 Slide view [range.slide]

26.7.28.2 Class template slide_­view [range.slide.view]

namespace std::ranges { template<class V> concept slide-caches-nothing = random_­access_­range<V> && sized_­range<V>; // exposition only template<class V> concept slide-caches-last = // exposition only !slide-caches-nothing<V> && bidirectional_­range<V> && common_­range<V>; template<class V> concept slide-caches-first = // exposition only !slide-caches-nothing<V> && !slide-caches-last<V>; template<forward_­range V> requires 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], class template slide_­view​::​iterator template<bool> class iterator; // exposition only // [range.slide.sentinel], class slide_­view​::​sentinel class sentinel; // exposition only public: constexpr explicit slide_view(V base, range_difference_t<V> n); constexpr auto begin() requires (!(simple-view<V> && slide-caches-nothing<const V>)); constexpr auto begin() const requires slide-caches-nothing<const V>; constexpr auto end() requires (!(simple-view<V> && slide-caches-nothing<const V>)); constexpr auto end() const requires slide-caches-nothing<const V>; constexpr auto size() requires sized_­range<V>; constexpr auto size() const requires sized_­range<const V>; }; template<class R> slide_view(R&&, range_difference_t<R>) -> slide_view<views::all_t<R>>; }
constexpr explicit slide_view(V base, range_difference_t<V> n);
Preconditions: n > 0 is true.
Effects: Initializes base_­ with std​::​move(base) and n_­ with n.
constexpr auto begin() requires (!(simple-view<V> && slide-caches-nothing<const V>));
Returns:
  • If V models slide-caches-first, iterator<false>(ranges::begin(base_), ranges::next(ranges::begin(base_), n_ - 1, ranges::end(base_)), n_)
  • Otherwise, iterator<false>(ranges​::​begin(base_­), n_­).
Remarks: In order to provide the amortized constant-time complexity required by the range concept, this function caches the result within the slide_­view for use on subsequent calls when V models slide-caches-first.
constexpr auto begin() const requires slide-caches-nothing<const V>;
Returns: iterator<true>(ranges​::​begin(base_­), n_­).
constexpr auto end() requires (!(simple-view<V> && slide-caches-nothing<const V>));
Returns:
  • If V models slide-caches-nothing, iterator<false>(ranges::begin(base_) + range_difference_t<V>(size()), n_)
  • Otherwise, if V models slide-caches-last, iterator<false>(ranges::prev(ranges::end(base_), n_ - 1, ranges::begin(base_)), n_)
  • Otherwise, if V models common_­range, iterator<false>(ranges::end(base_), ranges::end(base_), n_)
  • Otherwise, sentinel(ranges​::​end(base_­)).
Remarks: In order to provide the amortized constant-time complexity required by the range concept, this function caches the result within the slide_­view for use on subsequent calls when V models slide-caches-last.
constexpr auto end() const requires slide-caches-nothing<const V>;
Returns: begin() + range_­difference_­t<const V>(size()).
constexpr auto size() requires sized_­range<V>; constexpr auto size() const requires sized_­range<const V>;
Effects: Equivalent to: auto sz = ranges::distance(base_) - n_ + 1; if (sz < 0) sz = 0; return to-unsigned-like(sz);