26 Ranges library [ranges]

26.7 Range adaptors [range.adaptors]

26.7.27 Chunk view [range.chunk]

26.7.27.6 Class template chunk_­view for forward ranges [range.chunk.view.fwd]

namespace std::ranges { template<view V> requires forward_­range<V> class chunk_view<V> : public view_interface<chunk_view<V>> { V base_; // exposition only range_difference_t<V> n_; // exposition only // [range.chunk.fwd.iter], class template chunk_­view​::​iterator template<bool> class iterator; // exposition only public: constexpr explicit chunk_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>) { return iterator<false>(this, ranges::begin(base_)); } constexpr auto begin() const requires forward_­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>) { auto missing = (n_ - ranges::distance(base_) % n_) % n_; 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 forward_­range<const V> { if constexpr (common_­range<const V> && sized_­range<const V>) { auto missing = (n_ - ranges::distance(base_) % n_) % n_; 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>; }; }
constexpr explicit chunk_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 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_), n_));