[range.chunk.by.view]

# 25 Ranges library [[ranges]](./#ranges)

## 25.7 Range adaptors [[range.adaptors]](range.adaptors#range.chunk.by.view)

### 25.7.31 Chunk by view [[range.chunk.by]](range.chunk.by#view)

#### 25.7.31.2 Class template chunk_by_view [range.chunk.by.view]

[ð](#lib:chunk_by_view)

namespace std::ranges {template<[forward_range](range.refinements#concept:forward_range "25.4.6 Other range refinements [range.refinements]") V, [indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<iterator_t<V>, iterator_t<V>> Pred>requires [view](range.view#concept:view "25.4.5 Views [range.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]](range.chunk.by.iter "25.7.31.3 Class chunk_­by_­view​::​iterator"), class chunk_by_view​::​*iterator*class *iterator*; // *exposition only*public: chunk_by_view() requires [default_initializable](concept.default.init#concept:default_initializable "18.4.12 Concept default_­initializable [concept.default.init]")<V> && [default_initializable](concept.default.init#concept:default_initializable "18.4.12 Concept default_­initializable [concept.default.init]")<Pred> = default; constexpr explicit chunk_by_view(V base, Pred pred); constexpr V base() const & requires [copy_constructible](concept.copyconstructible#concept:copy_constructible "18.4.14 Concept copy_­constructible [concept.copyconstructible]")<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](range.refinements#concept:bidirectional_range "25.4.6 Other range refinements [range.refinements]")<V>; }; template<class R, class Pred> chunk_by_view(R&&, Pred) -> chunk_by_view<views::all_t<R>, Pred>;}

[ð](#lib:chunk_by_view,constructor)

`constexpr explicit chunk_by_view(V base, Pred pred);
`

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L15654)

*Effects*: Initializes *base_* with std​::​move(base) and*pred_* with std​::​move(pred)[.](#1.sentence-1)

[ð](#lib:pred,chunk_by_view)

`constexpr const Pred& pred() const;
`

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L15666)

*Effects*: Equivalent to: return **pred_*;

[ð](#lib:begin,chunk_by_view)

`constexpr iterator begin();
`

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L15677)

*Preconditions*: *pred_*.has_value() is true[.](#3.sentence-1)

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L15681)

*Returns*: *iterator*(*this, ranges​::​begin(*base_*), *find-next*(ranges​::​begin(*base_*)))[.](#4.sentence-1)

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L15685)

*Remarks*: In order to provide
the amortized constant-time complexity required by the [range](range.range#concept:range "25.4.2 Ranges [range.range]") concept,
this function caches the result within the chunk_by_view for use on subsequent calls[.](#5.sentence-1)

[ð](#lib:end,chunk_by_view)

`constexpr auto end();
`

[6](#6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L15699)

*Effects*: Equivalent to:if constexpr ([common_range](range.refinements#concept:common_range "25.4.6 Other range refinements [range.refinements]")<V>) {return *iterator*(*this, ranges::end(*base_*), ranges::end(*base_*));} else {return default_sentinel;}

[ð](#lib:find-next,chunk_by_view)

`constexpr iterator_t<V> find-next(iterator_t<V> current);
`

[7](#7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L15717)

*Preconditions*: *pred_*.has_value() is true[.](#7.sentence-1)

[8](#8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L15721)

*Returns*: ranges::next(ranges::adjacent_find(current, ranges::end(*base_*), not_fn(ref(**pred_*))), 1, ranges::end(*base_*))

[ð](#lib:find-prev,chunk_by_view)

`constexpr iterator_t<V> find-prev(iterator_t<V> current) requires [bidirectional_range](range.refinements#concept:bidirectional_range "25.4.6 Other range refinements [range.refinements]")<V>;
`

[9](#9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L15735)

*Preconditions*: 

- [(9.1)](#9.1)

  current is not equal to ranges​::​begin(*base_*)[.](#9.1.sentence-1)

- [(9.2)](#9.2)

  *pred_*.has_value() is true[.](#9.2.sentence-1)

[10](#10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L15744)

*Returns*: An iterator i in the range [ranges​::​begin(*base_*), current) such that:

- [(10.1)](#10.1)

ranges​::​adjacent_find(i, current, not_fn(ref(**pred_*))) is equal to current; and

- [(10.2)](#10.2)

if i is not equal to ranges​::​begin(*base_*),
then bool(invoke(**pred_*, *ranges​::​prev(i), *i)) is false[.](#10.sentence-1)
