26 Ranges library [ranges]

26.7 Range adaptors [range.adaptors]

26.7.30 Chunk by view [range.chunk.by]

26.7.30.2 Class template chunk_by_view [range.chunk.by.view]

namespace std::ranges { template<forward_range V, indirect_binary_predicate<iterator_t<V>, iterator_t<V>> Pred> requires view<V> && is_object_v<Pred> class chunk_by_view : public view_interface<chunk_by_view<V, Pred>> { V base_ = V(); // exposition only movable-box<Pred> pred_; // exposition only // [range.chunk.by.iter], class chunk_by_view​::​iterator class iterator; // exposition only public: chunk_by_view() requires default_initializable<V> && default_initializable<Pred> = default; constexpr explicit chunk_by_view(V base, Pred pred); constexpr V base() const & requires copy_constructible<V> { return base_; } constexpr V base() && { return std::move(base_); } constexpr const Pred& pred() const; constexpr iterator begin(); constexpr auto end(); constexpr iterator_t<V> find-next(iterator_t<V>); // exposition only constexpr iterator_t<V> find-prev(iterator_t<V>) // exposition only requires bidirectional_range<V>; }; template<class R, class Pred> chunk_by_view(R&&, Pred) -> chunk_by_view<views::all_t<R>, Pred>; }
constexpr explicit chunk_by_view(V base, Pred pred);
Effects: Initializes base_ with std​::​move(base) and pred_ with std​::​move(pred).
constexpr const Pred& pred() const;
Effects: Equivalent to: return *pred_;
constexpr iterator begin();
Preconditions: pred_.has_value() is true.
Returns: iterator(*this, ranges​::​begin(base_), find-next(ranges​::​begin(base_))).
Remarks: In order to provide the amortized constant-time complexity required by the range concept, this function caches the result within the chunk_by_view for use on subsequent calls.
constexpr auto end();
Effects: Equivalent to: if constexpr (common_range<V>) { return iterator(*this, ranges::end(base_), ranges::end(base_)); } else { return default_sentinel; }
constexpr iterator_t<V> find-next(iterator_t<V> current);
Preconditions: pred_.has_value() is true.
Returns: ranges::next(ranges::adjacent_find(current, ranges::end(base_), not_fn(ref(*pred_))), 1, ranges::end(base_))
constexpr iterator_t<V> find-prev(iterator_t<V> current) requires bidirectional_range<V>;
Preconditions:
  • current is not equal to ranges​::​begin(base_).
  • pred_.has_value() is true.
Returns: An iterator i in the range [ranges​::​begin(base_), current) such that:
  • ranges​::​adjacent_find(i, current, not_fn(ref(*pred_))) is equal to current; and
  • if i is not equal to ranges​::​begin(base_), then bool(invoke(*pred_, *ranges​::​prev(i), *i)) is false.