26 Ranges library [ranges]

26.7 Range adaptors [range.adaptors]

26.7.26 Chunk by view [range.chunk.by]

26.7.26.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 copyable-box<Pred> 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.