26 Ranges library [ranges]

26.7 Range adaptors [range.adaptors]

26.7.30 Slide view [range.slide]

26.7.30.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 V base() const & requires copy_constructible<V> { return base_; } constexpr V base() && { return std::move(base_); } 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);