25 Ranges library [ranges]

25.7 Range adaptors [range.adaptors]

25.7.32 Stride view [range.stride]

25.7.32.2 Class template stride_view [range.stride.view]

namespace std::ranges { template<input_range V> requires view<V> class stride_view : public view_interface<stride_view<V>> { V base_; // exposition only range_difference_t<V> stride_; // exposition only // [range.stride.iterator], class template stride_view​::​iterator template<bool> class iterator; // exposition only public: constexpr explicit stride_view(V base, range_difference_t<V> stride); constexpr V base() const & requires copy_constructible<V> { return base_; } constexpr V base() && { return std::move(base_); } constexpr range_difference_t<V> stride() const noexcept; constexpr auto begin() requires (!simple-view<V>) { return iterator<false>(this, ranges::begin(base_)); } constexpr auto begin() const requires range<const V> { return iterator<true>(this, ranges::begin(base_)); } constexpr auto end() requires (!simple-view<V>) { if constexpr (common_range<V> && sized_range<V> && forward_range<V>) { auto missing = (stride_ - ranges::distance(base_) % stride_) % stride_; return iterator<false>(this, ranges::end(base_), missing); } else if constexpr (common_range<V> && !bidirectional_range<V>) { return iterator<false>(this, ranges::end(base_)); } else { return default_sentinel; } } constexpr auto end() const requires range<const V> { if constexpr (common_range<const V> && sized_range<const V> && forward_range<const V>) { auto missing = (stride_ - ranges::distance(base_) % stride_) % stride_; return iterator<true>(this, ranges::end(base_), missing); } else if constexpr (common_range<const V> && !bidirectional_range<const V>) { return iterator<true>(this, ranges::end(base_)); } else { return default_sentinel; } } constexpr auto size() requires sized_range<V>; constexpr auto size() const requires sized_range<const V>; }; template<class R> stride_view(R&&, range_difference_t<R>) -> stride_view<views::all_t<R>>; }
constexpr stride_view(V base, range_difference_t<V> stride);
Preconditions: stride > 0 is true.
Effects: Initializes base_ with std​::​move(base) and stride_ with stride.
constexpr range_difference_t<V> stride() const noexcept;
Returns: stride_.
constexpr auto size() requires sized_range<V>; constexpr auto size() const requires sized_range<const V>;
Effects: Equivalent to: return to-unsigned-like(div-ceil(ranges::distance(base_), stride_));