[alg.nonmodifying] # 26 Algorithms library [[algorithms]](./#algorithms) ## 26.6 Non-modifying sequence operations [alg.nonmodifying] ### [26.6.1](#alg.all.of) All of [[alg.all.of]](alg.all.of) [🔗](#lib:all_of) `template constexpr bool all_of(InputIterator first, InputIterator last, Predicate pred); template bool all_of(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, Predicate pred); template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]") S, class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")> Pred> constexpr bool ranges::all_of(I first, S last, Pred pred, Proj proj = {}); template<[input_range](range.refinements#concept:input_range "25.4.6 Other range refinements [range.refinements]") R, class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]"), Proj>> Pred> constexpr bool ranges::all_of(R&& r, Pred pred, Proj proj = {}); template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_­access_­iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]") S, class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")> Pred> bool ranges::all_of(Ep&& exec, I first, S last, Pred pred, Proj proj = {}); template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]"), Proj>> Pred> bool ranges::all_of(Ep&& exec, R&& r, Pred pred, Proj proj = {}); ` [1](#alg.all.of-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4408) Let E be: - [(1.1)](#alg.all.of-1.1) pred(*i) for the overloads in namespace std; - [(1.2)](#alg.all.of-1.2) invoke(pred, invoke(proj, *i)) for the overloads in namespace ranges[.](#alg.all.of-1.sentence-1) [2](#alg.all.of-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4418) *Returns*: false if E is false for some iterator i in the range [first, last), andtrue otherwise[.](#alg.all.of-2.sentence-1) [3](#alg.all.of-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4424) *Complexity*: At most last - first applications of the predicate and any projection[.](#alg.all.of-3.sentence-1) ### [26.6.2](#alg.any.of) Any of [[alg.any.of]](alg.any.of) [🔗](#lib:any_of) `template constexpr bool any_of(InputIterator first, InputIterator last, Predicate pred); template bool any_of(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, Predicate pred); template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]") S, class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")> Pred> constexpr bool ranges::any_of(I first, S last, Pred pred, Proj proj = {}); template<[input_range](range.refinements#concept:input_range "25.4.6 Other range refinements [range.refinements]") R, class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]"), Proj>> Pred> constexpr bool ranges::any_of(R&& r, Pred pred, Proj proj = {}); template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_­access_­iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]") S, class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")> Pred> bool ranges::any_of(Ep&& exec, I first, S last, Pred pred, Proj proj = {}); template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]"), Proj>> Pred> bool ranges::any_of(Ep&& exec, R&& r, Pred pred, Proj proj = {}); ` [1](#alg.any.of-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4455) Let E be: - [(1.1)](#alg.any.of-1.1) pred(*i) for the overloads in namespace std; - [(1.2)](#alg.any.of-1.2) invoke(pred, invoke(proj, *i)) for the overloads in namespace ranges[.](#alg.any.of-1.sentence-1) [2](#alg.any.of-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4465) *Returns*: true if E is true for some iterator i in the range [first, last), and false otherwise[.](#alg.any.of-2.sentence-1) [3](#alg.any.of-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4470) *Complexity*: At most last - first applications of the predicate and any projection[.](#alg.any.of-3.sentence-1) ### [26.6.3](#alg.none.of) None of [[alg.none.of]](alg.none.of) [🔗](#lib:none_of) `template constexpr bool none_of(InputIterator first, InputIterator last, Predicate pred); template bool none_of(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, Predicate pred); template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]") S, class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")> Pred> constexpr bool ranges::none_of(I first, S last, Pred pred, Proj proj = {}); template<[input_range](range.refinements#concept:input_range "25.4.6 Other range refinements [range.refinements]") R, class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]"), Proj>> Pred> constexpr bool ranges::none_of(R&& r, Pred pred, Proj proj = {}); template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_­access_­iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]") S, class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")> Pred> bool ranges::none_of(Ep&& exec, I first, S last, Pred pred, Proj proj = {}); template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]"), Proj>> Pred> bool ranges::none_of(Ep&& exec, R&& r, Pred pred, Proj proj = {}); ` [1](#alg.none.of-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4502) Let E be: - [(1.1)](#alg.none.of-1.1) pred(*i) for the overloads in namespace std; - [(1.2)](#alg.none.of-1.2) invoke(pred, invoke(proj, *i)) for the overloads in namespace ranges[.](#alg.none.of-1.sentence-1) [2](#alg.none.of-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4512) *Returns*: false if E is true for some iterator i in the range [first, last), andtrue otherwise[.](#alg.none.of-2.sentence-1) [3](#alg.none.of-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4518) *Complexity*: At most last - first applications of the predicate and any projection[.](#alg.none.of-3.sentence-1) ### [26.6.4](#alg.contains) Contains [[alg.contains]](alg.contains) [🔗](#lib:contains) `template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]") S, class Proj = identity, class T = projected_value_t> requires [indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]"), const T*> constexpr bool ranges::contains(I first, S last, const T& value, Proj proj = {}); template<[input_range](range.refinements#concept:input_range "25.4.6 Other range refinements [range.refinements]") R, class Proj = identity, class T = projected_value_t, Proj>> requires [indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]"), Proj>, const T*> constexpr bool ranges::contains(R&& r, const T& value, Proj proj = {}); ` [1](#alg.contains-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4537) *Returns*: ranges​::​find(std​::​move(first), last, value, proj) != last[.](#alg.contains-1.sentence-1) [🔗](#alg.contains-itemdecl:2) `template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_­access_­iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]") S, class Proj = identity, class T = projected_value_t> requires [indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]"), const T*> bool ranges::contains(Ep&& exec, I first, S last, const T& value, Proj proj = {}); template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, class Proj = identity, class T = projected_value_t, Proj>> requires [indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]"), Proj>, const T*> bool ranges::contains(Ep&& exec, R&& r, const T& value, Proj proj = {}); ` [2](#alg.contains-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4555) *Returns*: ranges​::​find(std​::​forward(exec), first, last, value, proj) != last[.](#alg.contains-2.sentence-1) [🔗](#lib:contains_subrange) `template<[forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11 Concept forward_­iterator [iterator.concept.forward]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]") S1, [forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11 Concept forward_­iterator [iterator.concept.forward]") I2, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]") S2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5 Concept indirectly_­comparable [alg.req.ind.cmp]") constexpr bool ranges::contains_subrange(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); template<[forward_range](range.refinements#concept:forward_range "25.4.6 Other range refinements [range.refinements]") R1, [forward_range](range.refinements#concept:forward_range "25.4.6 Other range refinements [range.refinements]") R2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5 Concept indirectly_­comparable [alg.req.ind.cmp]"), iterator_t, Pred, Proj1, Proj2> constexpr bool ranges::contains_subrange(R1&& r1, R2&& r2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); ` [3](#alg.contains-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4576) *Returns*: first2 == last2 || !ranges::search(first1, last1, first2, last2, pred, proj1, proj2).empty() [🔗](#alg.contains-itemdecl:4) `template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_­access_­iterator [iterator.concept.random.access]") I1, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]") S1, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_­access_­iterator [iterator.concept.random.access]") I2, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]") S2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5 Concept indirectly_­comparable [alg.req.ind.cmp]") bool ranges::contains_subrange(Ep&& exec, I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R1, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5 Concept indirectly_­comparable [alg.req.ind.cmp]"), iterator_t, Pred, Proj1, Proj2> bool ranges::contains_subrange(Ep&& exec, R1&& r1, R2&& r2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); ` [4](#alg.contains-4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4599) *Returns*: first2 == last2 || !ranges::search(std::forward(exec), first1, last1, first2, last2, pred, proj1, proj2).empty() ### [26.6.5](#alg.foreach) For each [[alg.foreach]](alg.foreach) [🔗](#lib:for_each) `template constexpr Function for_each(InputIterator first, InputIterator last, Function f); ` [1](#alg.foreach-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4616) *Preconditions*: Function meets the [*Cpp17MoveConstructible*](utility.arg.requirements#:Cpp17MoveConstructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") requirements (Table [31](utility.arg.requirements#tab:cpp17.moveconstructible "Table 31: Cpp17MoveConstructible requirements"))[.](#alg.foreach-1.sentence-1) [*Note [1](#alg.foreach-note-1)*: Function need not meet the requirements of[*Cpp17CopyConstructible*](utility.arg.requirements#:Cpp17CopyConstructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") (Table [32](utility.arg.requirements#tab:cpp17.copyconstructible "Table 32: Cpp17CopyConstructible requirements (in addition to Cpp17MoveConstructible)"))[.](#alg.foreach-1.sentence-2) — *end note*] [2](#alg.foreach-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4625) *Effects*: Applies f to the result of dereferencing every iterator in the range [first, last), starting from first and proceeding to last - 1[.](#alg.foreach-2.sentence-1) [*Note [2](#alg.foreach-note-2)*: If the type of first meets the requirements of a mutable iterator,f can apply non-constant functions through the dereferenced iterator[.](#alg.foreach-2.sentence-2) — *end note*] [3](#alg.foreach-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4635) *Returns*: f[.](#alg.foreach-3.sentence-1) [4](#alg.foreach-4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4639) *Complexity*: Applies f exactly last - first times[.](#alg.foreach-4.sentence-1) [5](#alg.foreach-5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4643) *Remarks*: If f returns a result, the result is ignored[.](#alg.foreach-5.sentence-1) [🔗](#lib:for_each_) `template void for_each(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, Function f); ` [6](#alg.foreach-6) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4657) *Preconditions*: Function meets the [*Cpp17CopyConstructible*](utility.arg.requirements#:Cpp17CopyConstructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") requirements[.](#alg.foreach-6.sentence-1) [7](#alg.foreach-7) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4661) *Effects*: Applies f to the result of dereferencing every iterator in the range [first, last)[.](#alg.foreach-7.sentence-1) [*Note [3](#alg.foreach-note-3)*: If the type of first meets the requirements of a mutable iterator,f can apply non-constant functions through the dereferenced iterator[.](#alg.foreach-7.sentence-2) — *end note*] [8](#alg.foreach-8) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4670) *Complexity*: Applies f exactly last - first times[.](#alg.foreach-8.sentence-1) [9](#alg.foreach-9) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4674) *Remarks*: If f returns a result, the result is ignored[.](#alg.foreach-9.sentence-1) Implementations do not have the freedom granted under [[algorithms.parallel.exec]](algorithms.parallel.exec "26.3.3 Effect of execution policies on algorithm execution") to make arbitrary copies of elements from the input sequence[.](#alg.foreach-9.sentence-2) [10](#alg.foreach-10) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4681) [*Note [4](#alg.foreach-note-4)*: Does not return a copy of its Function parameter, since parallelization often does not permit efficient state accumulation[.](#alg.foreach-10.sentence-1) — *end note*] [🔗](#lib:for_each__) `template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]") S, class Proj = identity, [indirectly_unary_invocable](indirectcallable.indirectinvocable#concept:indirectly_unary_invocable "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")> Fun> constexpr ranges::for_each_result ranges::for_each(I first, S last, Fun f, Proj proj = {}); template<[input_range](range.refinements#concept:input_range "25.4.6 Other range refinements [range.refinements]") R, class Proj = identity, [indirectly_unary_invocable](indirectcallable.indirectinvocable#concept:indirectly_unary_invocable "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]"), Proj>> Fun> constexpr ranges::for_each_result, Fun> ranges::for_each(R&& r, Fun f, Proj proj = {}); ` [11](#alg.foreach-11) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4701) *Effects*: Calls invoke(f, invoke(proj, *i)) for every iterator i in the range [first, last), starting from first and proceeding to last - 1[.](#alg.foreach-11.sentence-1) [*Note [5](#alg.foreach-note-5)*: If the result of invoke(proj, *i) is a mutable reference,f can apply non-constant functions[.](#alg.foreach-11.sentence-2) — *end note*] [12](#alg.foreach-12) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4711) *Returns*: {last, std​::​move(f)}[.](#alg.foreach-12.sentence-1) [13](#alg.foreach-13) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4715) *Complexity*: Applies f and proj exactly last - first times[.](#alg.foreach-13.sentence-1) [14](#alg.foreach-14) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4719) *Remarks*: If f returns a result, the result is ignored[.](#alg.foreach-14.sentence-1) [15](#alg.foreach-15) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4723) [*Note [6](#alg.foreach-note-6)*: The overloads in namespace ranges requireFun to model [copy_constructible](concept.copyconstructible#concept:copy_constructible "18.4.14 Concept copy_­constructible [concept.copyconstructible]")[.](#alg.foreach-15.sentence-1) — *end note*] [🔗](#alg.foreach-itemdecl:4) `template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_­access_­iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]") S, class Proj = identity, [indirectly_unary_invocable](indirectcallable.indirectinvocable#concept:indirectly_unary_invocable "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")> Fun> I ranges::for_each(Ep&& exec, I first, S last, Fun f, Proj proj = {}); template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, class Proj = identity, [indirectly_unary_invocable](indirectcallable.indirectinvocable#concept:indirectly_unary_invocable "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]"), Proj>> Fun> borrowed_iterator_t ranges::for_each(Ep&& exec, R&& r, Fun f, Proj proj = {}); ` [16](#alg.foreach-16) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4742) *Effects*: Calls invoke(f, invoke(proj, *i)) for every iterator i in the range [first, last)[.](#alg.foreach-16.sentence-1) [*Note [7](#alg.foreach-note-7)*: If the result of invoke(proj, *i) is a mutable reference,f can apply non-constant functions[.](#alg.foreach-16.sentence-2) — *end note*] [17](#alg.foreach-17) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4752) *Returns*: last[.](#alg.foreach-17.sentence-1) [18](#alg.foreach-18) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4756) *Complexity*: Applies f and proj exactly last - first times[.](#alg.foreach-18.sentence-1) [19](#alg.foreach-19) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4760) *Remarks*: - [(19.1)](#alg.foreach-19.1) If f returns a result, the result is ignored[.](#alg.foreach-19.1.sentence-1) - [(19.2)](#alg.foreach-19.2) Implementations do not have the freedom granted under [[algorithms.parallel.exec]](algorithms.parallel.exec "26.3.3 Effect of execution policies on algorithm execution") to make arbitrary copies of elements from the input sequence[.](#alg.foreach-19.2.sentence-1) - [(19.3)](#alg.foreach-19.3) f may modify objects via its arguments ([[algorithms.parallel.user]](algorithms.parallel.user "26.3.2 Requirements on user-provided function objects"))[.](#alg.foreach-19.3.sentence-1) [*Note [8](#alg.foreach-note-8)*: Does not return a copy of its Fun parameter, since parallelization often does not permit efficient state accumulation[.](#alg.foreach-19.sentence-2) — *end note*] [🔗](#lib:for_each_n) `template constexpr InputIterator for_each_n(InputIterator first, Size n, Function f); ` [20](#alg.foreach-20) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4785) *Mandates*: The type Size is convertible to an integral type ([[conv.integral]](conv.integral "7.3.9 Integral conversions"), [[class.conv]](class.conv "11.4.8 Conversions"))[.](#alg.foreach-20.sentence-1) [21](#alg.foreach-21) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4790) *Preconditions*: n >= 0 is true[.](#alg.foreach-21.sentence-1) Function meets the [*Cpp17MoveConstructible*](utility.arg.requirements#:Cpp17MoveConstructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") requirements[.](#alg.foreach-21.sentence-2) [*Note [9](#alg.foreach-note-9)*: Function need not meet the requirements of [*Cpp17CopyConstructible*](utility.arg.requirements#:Cpp17CopyConstructible "16.4.4.2 Template argument requirements [utility.arg.requirements]")[.](#alg.foreach-21.sentence-3) — *end note*] [22](#alg.foreach-22) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4799) *Effects*: Applies f to the result of dereferencing every iterator in the range [first, first + n) in order[.](#alg.foreach-22.sentence-1) [*Note [10](#alg.foreach-note-10)*: If the type of first meets the requirements of a mutable iterator,f can apply non-constant functions through the dereferenced iterator[.](#alg.foreach-22.sentence-2) — *end note*] [23](#alg.foreach-23) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4808) *Returns*: first + n[.](#alg.foreach-23.sentence-1) [24](#alg.foreach-24) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4812) *Remarks*: If f returns a result, the result is ignored[.](#alg.foreach-24.sentence-1) [🔗](#lib:for_each_n_) `template ForwardIterator for_each_n(ExecutionPolicy&& exec, ForwardIterator first, Size n, Function f); ` [25](#alg.foreach-25) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4825) *Mandates*: The type Size is convertible to an integral type ([[conv.integral]](conv.integral "7.3.9 Integral conversions"), [[class.conv]](class.conv "11.4.8 Conversions"))[.](#alg.foreach-25.sentence-1) [26](#alg.foreach-26) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4830) *Preconditions*: n >= 0 is true[.](#alg.foreach-26.sentence-1) Function meets the [*Cpp17CopyConstructible*](utility.arg.requirements#:Cpp17CopyConstructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") requirements[.](#alg.foreach-26.sentence-2) [27](#alg.foreach-27) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4835) *Effects*: Applies f to the result of dereferencing every iterator in the range [first, first + n)[.](#alg.foreach-27.sentence-1) [*Note [11](#alg.foreach-note-11)*: If the type of first meets the requirements of a mutable iterator,f can apply non-constant functions through the dereferenced iterator[.](#alg.foreach-27.sentence-2) — *end note*] [28](#alg.foreach-28) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4844) *Returns*: first + n[.](#alg.foreach-28.sentence-1) [29](#alg.foreach-29) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4848) *Remarks*: If f returns a result, the result is ignored[.](#alg.foreach-29.sentence-1) Implementations do not have the freedom granted under [[algorithms.parallel.exec]](algorithms.parallel.exec "26.3.3 Effect of execution policies on algorithm execution") to make arbitrary copies of elements from the input sequence[.](#alg.foreach-29.sentence-2) [🔗](#lib:for_each_n__) `template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]") I, class Proj = identity, [indirectly_unary_invocable](indirectcallable.indirectinvocable#concept:indirectly_unary_invocable "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")> Fun> constexpr ranges::for_each_n_result ranges::for_each_n(I first, iter_difference_t n, Fun f, Proj proj = {}); ` [30](#alg.foreach-30) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4865) *Preconditions*: n >= 0 is true[.](#alg.foreach-30.sentence-1) [31](#alg.foreach-31) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4869) *Effects*: Calls invoke(f, invoke(proj, *i)) for every iterator i in the range [first, first + n) in order[.](#alg.foreach-31.sentence-1) [*Note [12](#alg.foreach-note-12)*: If the result of invoke(proj, *i) is a mutable reference,f can apply non-constant functions[.](#alg.foreach-31.sentence-2) — *end note*] [32](#alg.foreach-32) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4879) *Returns*: {first + n, std​::​move(f)}[.](#alg.foreach-32.sentence-1) [33](#alg.foreach-33) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4883) *Remarks*: If f returns a result, the result is ignored[.](#alg.foreach-33.sentence-1) [34](#alg.foreach-34) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4887) [*Note [13](#alg.foreach-note-13)*: The overload in namespace ranges requires Fun to model [copy_constructible](concept.copyconstructible#concept:copy_constructible "18.4.14 Concept copy_­constructible [concept.copyconstructible]")[.](#alg.foreach-34.sentence-1) — *end note*] [🔗](#alg.foreach-itemdecl:8) `template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_­access_­iterator [iterator.concept.random.access]") I, class Proj = identity, [indirectly_unary_invocable](indirectcallable.indirectinvocable#concept:indirectly_unary_invocable "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")> Fun> I ranges::for_each_n(Ep&& exec, I first, iter_difference_t n, Fun f, Proj proj = {}); ` [35](#alg.foreach-35) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4901) *Preconditions*: n >= 0 is true[.](#alg.foreach-35.sentence-1) [36](#alg.foreach-36) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4905) *Effects*: Calls invoke(f, invoke(proj, *i)) for every iterator i in the range [first, first + n)[.](#alg.foreach-36.sentence-1) [*Note [14](#alg.foreach-note-14)*: If the result of invoke(proj, *i) is a mutable reference,f can apply non-constant functions[.](#alg.foreach-36.sentence-2) — *end note*] [37](#alg.foreach-37) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4915) *Returns*: first + n[.](#alg.foreach-37.sentence-1) [38](#alg.foreach-38) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L4919) *Remarks*: - [(38.1)](#alg.foreach-38.1) If f returns a result, the result is ignored[.](#alg.foreach-38.1.sentence-1) - [(38.2)](#alg.foreach-38.2) Implementations do not have the freedom granted under [[algorithms.parallel.exec]](algorithms.parallel.exec "26.3.3 Effect of execution policies on algorithm execution") to make arbitrary copies of elements from the input sequence[.](#alg.foreach-38.2.sentence-1) - [(38.3)](#alg.foreach-38.3) f may modify objects via its arguments ([[algorithms.parallel.user]](algorithms.parallel.user "26.3.2 Requirements on user-provided function objects"))[.](#alg.foreach-38.3.sentence-1) [*Note [15](#alg.foreach-note-15)*: Does not return a copy of its Fun parameter, since parallelization often does not permit efficient state accumulation[.](#alg.foreach-38.sentence-2) — *end note*] ### [26.6.6](#alg.find) Find [[alg.find]](alg.find) [🔗](#lib:find) `template::value_type> constexpr InputIterator find(InputIterator first, InputIterator last, const T& value); template::value_type> ForwardIterator find(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, const T& value); template constexpr InputIterator find_if(InputIterator first, InputIterator last, Predicate pred); template ForwardIterator find_if(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, Predicate pred); template constexpr InputIterator find_if_not(InputIterator first, InputIterator last, Predicate pred); template ForwardIterator find_if_not(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, Predicate pred); template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]") S, class Proj = identity, class T = projected_value_t> requires [indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]"), const T*> constexpr I ranges::find(I first, S last, const T& value, Proj proj = {}); template<[input_range](range.refinements#concept:input_range "25.4.6 Other range refinements [range.refinements]") R, class Proj = identity, class T = projected_value_t, Proj>> requires [indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]"), Proj>, const T*> constexpr borrowed_iterator_t ranges::find(R&& r, const T& value, Proj proj = {}); template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_­access_­iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]") S, class Proj = identity, class T = projected_value_t> requires [indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]"), const T*> I ranges::find(Ep&& exec, I first, S last, const T& value, Proj proj = {}); template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, class Proj = identity, class T = projected_value_t, Proj>> requires [indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]"), Proj>, const T*> borrowed_iterator_t ranges::find(Ep&& exec, R&& r, const T& value, Proj proj = {}); template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]") S, class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")> Pred> constexpr I ranges::find_if(I first, S last, Pred pred, Proj proj = {}); template<[input_range](range.refinements#concept:input_range "25.4.6 Other range refinements [range.refinements]") R, class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]"), Proj>> Pred> constexpr borrowed_iterator_t ranges::find_if(R&& r, Pred pred, Proj proj = {}); template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_­access_­iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]") S, class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")> Pred> I ranges::find_if(Ep&& exec, I first, S last, Pred pred, Proj proj = {}); template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]"), Proj>> Pred> borrowed_iterator_t ranges::find_if(Ep&& exec, R&& r, Pred pred, Proj proj = {}); template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]") S, class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")> Pred> constexpr I ranges::find_if_not(I first, S last, Pred pred, Proj proj = {}); template<[input_range](range.refinements#concept:input_range "25.4.6 Other range refinements [range.refinements]") R, class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]"), Proj>> Pred> constexpr borrowed_iterator_t ranges::find_if_not(R&& r, Pred pred, Proj proj = {}); template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_­access_­iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]") S, class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")> Pred> I ranges::find_if_not(Ep&& exec, I first, S last, Pred pred, Proj proj = {}); template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]"), Proj>> Pred> borrowed_iterator_t ranges::find_if_not(Ep&& exec, R&& r, Pred pred, Proj proj = {}); ` [1](#alg.find-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5017) Let E be: - [(1.1)](#alg.find-1.1) *i == value for find; - [(1.2)](#alg.find-1.2) pred(*i) != false for find_if; - [(1.3)](#alg.find-1.3) pred(*i) == false for find_if_not; - [(1.4)](#alg.find-1.4) bool(invoke(proj, *i) == value) for ranges​::​find; - [(1.5)](#alg.find-1.5) bool(invoke(pred, invoke(proj, *i))) for ranges​::​find_if; - [(1.6)](#alg.find-1.6) bool(!invoke(pred, invoke(proj, *i))) for ranges​::​find_if_not[.](#alg.find-1.sentence-1) [2](#alg.find-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5028) *Returns*: The first iterator i in the range [first, last) for which E is true[.](#alg.find-2.sentence-1) Returns last if no such iterator is found[.](#alg.find-2.sentence-2) [3](#alg.find-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5034) *Complexity*: At most last - first applications of the corresponding predicate and any projection[.](#alg.find-3.sentence-1) ### [26.6.7](#alg.find.last) Find last [[alg.find.last]](alg.find.last) [🔗](#lib:find_last) `template<[forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11 Concept forward_­iterator [iterator.concept.forward]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]") S, class Proj = identity, class T = projected_value_t> requires [indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]"), const T*> constexpr subrange ranges::find_last(I first, S last, const T& value, Proj proj = {}); template<[forward_range](range.refinements#concept:forward_range "25.4.6 Other range refinements [range.refinements]") R, class Proj = identity, class T = projected_value_t, Proj>> requires [indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]"), Proj>, const T*> constexpr borrowed_subrange_t ranges::find_last(R&& r, const T& value, Proj proj = {}); template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_­access_­iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]") S, class Proj = identity, class T = projected_value_t> requires [indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]"), const T*> subrange ranges::find_last(Ep&& exec, I first, S last, const T& value, Proj proj = {}); template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, class Proj = identity, class T = projected_value_t, Proj>> requires [indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]"), Proj>, const T*> borrowed_subrange_t ranges::find_last(Ep&& exec, R&& r, const T& value, Proj proj = {}); template<[forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11 Concept forward_­iterator [iterator.concept.forward]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]") S, class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")> Pred> constexpr subrange ranges::find_last_if(I first, S last, Pred pred, Proj proj = {}); template<[forward_range](range.refinements#concept:forward_range "25.4.6 Other range refinements [range.refinements]") R, class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]"), Proj>> Pred> constexpr borrowed_subrange_t ranges::find_last_if(R&& r, Pred pred, Proj proj = {}); template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_­access_­iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]") S, class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")> Pred> subrange ranges::find_last_if(Ep&& exec, I first, S last, Pred pred, Proj proj = {}); template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]"), Proj>> Pred> borrowed_subrange_t ranges::find_last_if(Ep&& exec, R&& r, Pred pred, Proj proj = {}); template<[forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11 Concept forward_­iterator [iterator.concept.forward]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]") S, class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")> Pred> constexpr subrange ranges::find_last_if_not(I first, S last, Pred pred, Proj proj = {}); template<[forward_range](range.refinements#concept:forward_range "25.4.6 Other range refinements [range.refinements]") R, class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]"), Proj>> Pred> constexpr borrowed_subrange_t ranges::find_last_if_not(R&& r, Pred pred, Proj proj = {}); template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_­access_­iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]") S, class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")> Pred> subrange ranges::find_last_if_not(Ep&& exec, I first, S last, Pred pred, Proj proj = {}); template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]"), Proj>> Pred> borrowed_subrange_t ranges::find_last_if_not(Ep&& exec, R&& r, Pred pred, Proj proj = {}); ` [1](#alg.find.last-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5095) Let E be: - [(1.1)](#alg.find.last-1.1) bool(invoke(proj, *i) == value) for ranges​::​find_last; - [(1.2)](#alg.find.last-1.2) bool(invoke(pred, invoke(proj, *i))) for ranges​::​find_last_if; - [(1.3)](#alg.find.last-1.3) bool(!invoke(pred, invoke(proj, *i))) for ranges​::​find_last_if_not[.](#alg.find.last-1.sentence-1) [2](#alg.find.last-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5106) *Returns*: Let i be the last iterator in the range [first, last) for which E is true[.](#alg.find.last-2.sentence-1) Returns {i, last}, or{last, last} if no such iterator is found[.](#alg.find.last-2.sentence-2) [3](#alg.find.last-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5113) *Complexity*: At most last - first applications of the corresponding predicate and projection[.](#alg.find.last-3.sentence-1) ### [26.6.8](#alg.find.end) Find end [[alg.find.end]](alg.find.end) [🔗](#lib:find_end) `template constexpr ForwardIterator1 find_end(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2); template ForwardIterator1 find_end(ExecutionPolicy&& exec, ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2); template constexpr ForwardIterator1 find_end(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred); template ForwardIterator1 find_end(ExecutionPolicy&& exec, ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred); template<[forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11 Concept forward_­iterator [iterator.concept.forward]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]") S1, [forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11 Concept forward_­iterator [iterator.concept.forward]") I2, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]") S2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5 Concept indirectly_­comparable [alg.req.ind.cmp]") constexpr subrange ranges::find_end(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); template<[forward_range](range.refinements#concept:forward_range "25.4.6 Other range refinements [range.refinements]") R1, [forward_range](range.refinements#concept:forward_range "25.4.6 Other range refinements [range.refinements]") R2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5 Concept indirectly_­comparable [alg.req.ind.cmp]"), iterator_t, Pred, Proj1, Proj2> constexpr borrowed_subrange_t ranges::find_end(R1&& r1, R2&& r2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_­access_­iterator [iterator.concept.random.access]") I1, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]") S1, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_­access_­iterator [iterator.concept.random.access]") I2, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]") S2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5 Concept indirectly_­comparable [alg.req.ind.cmp]") subrange ranges::find_end(Ep&& exec, I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R1, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5 Concept indirectly_­comparable [alg.req.ind.cmp]"), iterator_t, Pred, Proj1, Proj2> borrowed_subrange_t ranges::find_end(Ep&& exec, R1&& r1, R2&& r2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); ` [1](#alg.find.end-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5176) Let: - [(1.1)](#alg.find.end-1.1) pred be equal_to{} for the overloads with no parameter pred; - [(1.2)](#alg.find.end-1.2) E be: * [(1.2.1)](#alg.find.end-1.2.1) pred(*(i + n), *(first2 + n)) for the overloads in namespace std; * [(1.2.2)](#alg.find.end-1.2.2) invoke(pred, invoke(proj1, *(i + n)), invoke(proj2, *(first2 + n))) for the overloads in namespace ranges; - [(1.3)](#alg.find.end-1.3) i be last1 if [first2, last2) is empty, or if (last2 - first2) > (last1 - first1) is true, or if there is no iterator in the range [first1, last1 - (last2 - first2)) such that for every non-negative integer n < (last2 - first2), E is true[.](#alg.find.end-1.sentence-1) Otherwise i is the last such iterator in [first1, last1 - (last2 - first2))[.](#alg.find.end-1.3.sentence-2) [2](#alg.find.end-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5203) *Returns*: - [(2.1)](#alg.find.end-2.1) i for the overloads in namespace std[.](#alg.find.end-2.1.sentence-1) - [(2.2)](#alg.find.end-2.2) {i, i + (i == last1 ? 0 : last2 - first2)} for the overloads in namespace ranges[.](#alg.find.end-2.2.sentence-1) [3](#alg.find.end-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5211) *Complexity*: At most(last2 - first2) * (last1 - first1 - (last2 - first2) + 1) applications of the corresponding predicate and any projections[.](#alg.find.end-3.sentence-1) ### [26.6.9](#alg.find.first.of) Find first [[alg.find.first.of]](alg.find.first.of) [🔗](#lib:find_first_of) `template constexpr InputIterator find_first_of(InputIterator first1, InputIterator last1, ForwardIterator first2, ForwardIterator last2); template ForwardIterator1 find_first_of(ExecutionPolicy&& exec, ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2); template constexpr InputIterator find_first_of(InputIterator first1, InputIterator last1, ForwardIterator first2, ForwardIterator last2, BinaryPredicate pred); template ForwardIterator1 find_first_of(ExecutionPolicy&& exec, ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred); template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]") S1, [forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11 Concept forward_­iterator [iterator.concept.forward]") I2, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]") S2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5 Concept indirectly_­comparable [alg.req.ind.cmp]") constexpr I1 ranges::find_first_of(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); template<[input_range](range.refinements#concept:input_range "25.4.6 Other range refinements [range.refinements]") R1, [forward_range](range.refinements#concept:forward_range "25.4.6 Other range refinements [range.refinements]") R2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5 Concept indirectly_­comparable [alg.req.ind.cmp]"), iterator_t, Pred, Proj1, Proj2> constexpr borrowed_iterator_t ranges::find_first_of(R1&& r1, R2&& r2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_­access_­iterator [iterator.concept.random.access]") I1, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]") S1, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_­access_­iterator [iterator.concept.random.access]") I2, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]") S2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5 Concept indirectly_­comparable [alg.req.ind.cmp]") I1 ranges::find_first_of(Ep&& exec, I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R1, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5 Concept indirectly_­comparable [alg.req.ind.cmp]"), iterator_t, Pred, Proj1, Proj2> borrowed_iterator_t ranges::find_first_of(Ep&& exec, R1&& r1, R2&& r2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); ` [1](#alg.find.first.of-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5275) Let E be: - [(1.1)](#alg.find.first.of-1.1) *i == *j for the overloads with no parameter pred; - [(1.2)](#alg.find.first.of-1.2) pred(*i, *j) != false for the overloads with a parameter pred and no parameter proj1; - [(1.3)](#alg.find.first.of-1.3) bool(invoke(pred, invoke(proj1, *i), invoke(proj2, *j))) for the overloads with parameters pred and proj1[.](#alg.find.first.of-1.sentence-1) [2](#alg.find.first.of-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5283) *Effects*: Finds an element that matches one of a set of values[.](#alg.find.first.of-2.sentence-1) [3](#alg.find.first.of-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5287) *Returns*: The first iterator i in the range [first1, last1) such that for some iterator j in the range [first2, last2)E holds[.](#alg.find.first.of-3.sentence-1) Returns last1 if [first2, last2) is empty or if no such iterator is found[.](#alg.find.first.of-3.sentence-2) [4](#alg.find.first.of-4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5296) *Complexity*: At most (last1 - first1) * (last2 - first2) applications of the corresponding predicate and any projections[.](#alg.find.first.of-4.sentence-1) ### [26.6.10](#alg.adjacent.find) Adjacent find [[alg.adjacent.find]](alg.adjacent.find) [🔗](#lib:adjacent_find) `template constexpr ForwardIterator adjacent_find(ForwardIterator first, ForwardIterator last); template ForwardIterator adjacent_find(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last); template constexpr ForwardIterator adjacent_find(ForwardIterator first, ForwardIterator last, BinaryPredicate pred); template ForwardIterator adjacent_find(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, BinaryPredicate pred); template<[forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11 Concept forward_­iterator [iterator.concept.forward]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]") S, class Proj = identity, [indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]"), projected> Pred = ranges::equal_to> constexpr I ranges::adjacent_find(I first, S last, Pred pred = {}, Proj proj = {}); template<[forward_range](range.refinements#concept:forward_range "25.4.6 Other range refinements [range.refinements]") R, class Proj = identity, [indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]"), Proj>, projected, Proj>> Pred = ranges::equal_to> constexpr borrowed_iterator_t ranges::adjacent_find(R&& r, Pred pred = {}, Proj proj = {}); template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_­access_­iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]") S, class Proj = identity, [indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]"), projected> Pred = ranges::equal_to> I ranges::adjacent_find(Ep&& exec, I first, S last, Pred pred = {}, Proj proj = {}); template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, class Proj = identity, [indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]"), Proj>, projected, Proj>> Pred = ranges::equal_to> borrowed_iterator_t ranges::adjacent_find(Ep&& exec, R&& r, Pred pred = {}, Proj proj = {}); ` [1](#alg.adjacent.find-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5346) Let E be: - [(1.1)](#alg.adjacent.find-1.1) *i == *(i + 1) for the overloads with no parameter pred; - [(1.2)](#alg.adjacent.find-1.2) pred(*i, *(i + 1)) != false for the overloads with a parameter pred and no parameter proj; - [(1.3)](#alg.adjacent.find-1.3) bool(invoke(pred, invoke(proj, *i), invoke(proj, *(i + 1)))) for the overloads with both parameters pred and proj[.](#alg.adjacent.find-1.sentence-1) [2](#alg.adjacent.find-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5355) *Returns*: The first iterator i such that both i and i + 1 are in the range [first, last) for which E holds[.](#alg.adjacent.find-2.sentence-1) Returns last if no such iterator is found[.](#alg.adjacent.find-2.sentence-2) [3](#alg.adjacent.find-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5362) *Complexity*: For the non-parallel algorithm overloads, exactly min((i - first) + 1, (last - first) - 1) applications of the corresponding predicate, where i is adjacent_find's return value[.](#alg.adjacent.find-3.sentence-1) For the parallel algorithm overloads,O(last - first) applications of the corresponding predicate[.](#alg.adjacent.find-3.sentence-2) No more than twice as many applications of any projection[.](#alg.adjacent.find-3.sentence-3) ### [26.6.11](#alg.count) Count [[alg.count]](alg.count) [🔗](#lib:count) `template::value_type> constexpr typename iterator_traits::difference_type count(InputIterator first, InputIterator last, const T& value); template::value_type> typename iterator_traits::difference_type count(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, const T& value); template constexpr typename iterator_traits::difference_type count_if(InputIterator first, InputIterator last, Predicate pred); template typename iterator_traits::difference_type count_if(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, Predicate pred); template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]") S, class Proj = identity, class T = projected_value_t> requires [indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]"), const T*> constexpr iter_difference_t ranges::count(I first, S last, const T& value, Proj proj = {}); template<[input_range](range.refinements#concept:input_range "25.4.6 Other range refinements [range.refinements]") R, class Proj = identity, class T = projected_value_t, Proj>> requires [indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]"), Proj>, const T*> constexpr range_difference_t ranges::count(R&& r, const T& value, Proj proj = {}); template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_­access_­iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]") S, class Proj = identity, class T = projected_value_t> requires [indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]"), const T*> iter_difference_t ranges::count(Ep&& exec, I first, S last, const T& value, Proj proj = {}); template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, class Proj = identity, class T = projected_value_t, Proj>> requires [indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]"), Proj>, const T*> range_difference_t ranges::count(Ep&& exec, R&& r, const T& value, Proj proj = {}); template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]") S, class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")> Pred> constexpr iter_difference_t ranges::count_if(I first, S last, Pred pred, Proj proj = {}); template<[input_range](range.refinements#concept:input_range "25.4.6 Other range refinements [range.refinements]") R, class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]"), Proj>> Pred> constexpr range_difference_t ranges::count_if(R&& r, Pred pred, Proj proj = {}); template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_­access_­iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]") S, class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")> Pred> iter_difference_t ranges::count_if(Ep&& exec, I first, S last, Pred pred, Proj proj = {}); template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, class Proj = identity, [indirect_unary_predicate](indirectcallable.indirectinvocable#concept:indirect_unary_predicate "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]"), Proj>> Pred> range_difference_t ranges::count_if(Ep&& exec, R&& r, Pred pred, Proj proj = {}); ` [1](#alg.count-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5436) Let E be: - [(1.1)](#alg.count-1.1) *i == value for the overloads with no parameter pred or proj; - [(1.2)](#alg.count-1.2) pred(*i) != false for the overloads with a parameter pred but no parameter proj; - [(1.3)](#alg.count-1.3) invoke(proj, *i) == value for the overloads with a parameter proj but no parameter pred; - [(1.4)](#alg.count-1.4) bool(invoke(pred, invoke(proj, *i))) for the overloads with both parameters proj and pred[.](#alg.count-1.sentence-1) [2](#alg.count-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5453) *Effects*: Returns the number of iterators i in the range [first, last) for which E holds[.](#alg.count-2.sentence-1) [3](#alg.count-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5458) *Complexity*: Exactly last - first applications of the corresponding predicate and any projection[.](#alg.count-3.sentence-1) ### [26.6.12](#alg.mismatch) Mismatch [[alg.mismatch]](alg.mismatch) [🔗](#lib:mismatch) `template constexpr pair mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2); template pair mismatch(ExecutionPolicy&& exec, ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2); template constexpr pair mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, BinaryPredicate pred); template pair mismatch(ExecutionPolicy&& exec, ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, BinaryPredicate pred); template constexpr pair mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2); template pair mismatch(ExecutionPolicy&& exec, ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2); template constexpr pair mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, BinaryPredicate pred); template pair mismatch(ExecutionPolicy&& exec, ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred); template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]") S1, [input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]") I2, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]") S2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5 Concept indirectly_­comparable [alg.req.ind.cmp]") constexpr ranges::mismatch_result ranges::mismatch(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); template<[input_range](range.refinements#concept:input_range "25.4.6 Other range refinements [range.refinements]") R1, [input_range](range.refinements#concept:input_range "25.4.6 Other range refinements [range.refinements]") R2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5 Concept indirectly_­comparable [alg.req.ind.cmp]"), iterator_t, Pred, Proj1, Proj2> constexpr ranges::mismatch_result, borrowed_iterator_t> ranges::mismatch(R1&& r1, R2&& r2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_­access_­iterator [iterator.concept.random.access]") I1, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]") S1, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_­access_­iterator [iterator.concept.random.access]") I2, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]") S2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5 Concept indirectly_­comparable [alg.req.ind.cmp]") ranges::mismatch_result ranges::mismatch(Ep&& exec, I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R1, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5 Concept indirectly_­comparable [alg.req.ind.cmp]"), iterator_t, Pred, Proj1, Proj2> ranges::mismatch_result, borrowed_iterator_t> ranges::mismatch(Ep&& exec, R1&& r1, R2&& r2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); ` [1](#alg.mismatch-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5543) Let last2 be first2 + (last1 - first1) for the overloads in namespace std with no parameter last2[.](#alg.mismatch-1.sentence-1) [2](#alg.mismatch-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5547) Let E be: - [(2.1)](#alg.mismatch-2.1) !(*(first1 + n) == *(first2 + n)) for the overloads with no parameter pred; - [(2.2)](#alg.mismatch-2.2) pred(*(first1 + n), *(first2 + n)) == false for the overloads with a parameter pred and no parameter proj1; - [(2.3)](#alg.mismatch-2.3) !invoke(pred, invoke(proj1, *(first1 + n)), invoke(proj2, *(first2 + n))) for the overloads with both parameters pred and proj1[.](#alg.mismatch-2.sentence-1) [3](#alg.mismatch-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5563) Let N be min(last1 - first1, last2 - first2)[.](#alg.mismatch-3.sentence-1) [4](#alg.mismatch-4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5566) *Returns*: { first1 + n, first2 + n }, where n is the smallest integer in [0, N) such that E holds, or N if no such integer exists[.](#alg.mismatch-4.sentence-1) [5](#alg.mismatch-5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5572) *Complexity*: At most N applications of the corresponding predicate and any projections[.](#alg.mismatch-5.sentence-1) ### [26.6.13](#alg.equal) Equal [[alg.equal]](alg.equal) [🔗](#lib:equal) `template constexpr bool equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2); template bool equal(ExecutionPolicy&& exec, ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2); template constexpr bool equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, BinaryPredicate pred); template bool equal(ExecutionPolicy&& exec, ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, BinaryPredicate pred); template constexpr bool equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2); template bool equal(ExecutionPolicy&& exec, ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2); template constexpr bool equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, BinaryPredicate pred); template bool equal(ExecutionPolicy&& exec, ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred); template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]") S1, [input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]") I2, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]") S2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5 Concept indirectly_­comparable [alg.req.ind.cmp]") constexpr bool ranges::equal(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); template<[input_range](range.refinements#concept:input_range "25.4.6 Other range refinements [range.refinements]") R1, [input_range](range.refinements#concept:input_range "25.4.6 Other range refinements [range.refinements]") R2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5 Concept indirectly_­comparable [alg.req.ind.cmp]"), iterator_t, Pred, Proj1, Proj2> constexpr bool ranges::equal(R1&& r1, R2&& r2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_­access_­iterator [iterator.concept.random.access]") I1, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]") S1, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_­access_­iterator [iterator.concept.random.access]") I2, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]") S2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5 Concept indirectly_­comparable [alg.req.ind.cmp]") bool ranges::equal(Ep&& exec, I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R1, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5 Concept indirectly_­comparable [alg.req.ind.cmp]"), iterator_t, Pred, Proj1, Proj2> bool ranges::equal(Ep&& exec, R1&& r1, R2&& r2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); ` [1](#alg.equal-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5645) Let: - [(1.1)](#alg.equal-1.1) last2 be first2 + (last1 - first1) for the overloads in namespace std with no parameter last2; - [(1.2)](#alg.equal-1.2) pred be equal_to{} for the overloads with no parameter pred; - [(1.3)](#alg.equal-1.3) E be: * [(1.3.1)](#alg.equal-1.3.1) pred(*i, *(first2 + (i - first1))) for the overloads with no parameter proj1; * [(1.3.2)](#alg.equal-1.3.2) invoke(pred, invoke(proj1, *i), invoke(proj2, *(first2 + (i - first1)))) for the overloads with parameter proj1[.](#alg.equal-1.sentence-1) [2](#alg.equal-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5667) *Returns*: If last1 - first1 != last2 - first2, return false[.](#alg.equal-2.sentence-1) Otherwise return true if E holds for every iterator i in the range [first1, last1)[.](#alg.equal-2.sentence-2) Otherwise, returns false[.](#alg.equal-2.sentence-3) [3](#alg.equal-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5674) *Complexity*: If - [(3.1)](#alg.equal-3.1) the types of first1, last1, first2, and last2 meet the [*Cpp17RandomAccessIterator*](random.access.iterators#:Cpp17RandomAccessIterator "24.3.5.7 Random access iterators [random.access.iterators]") requirements ([[random.access.iterators]](random.access.iterators "24.3.5.7 Random access iterators")) and last1 - first1 != last2 - first2 for the overloads in namespace std; - [(3.2)](#alg.equal-3.2) the types of first1, last1, first2, and last2 pairwise model [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]") ([[iterator.concept.sizedsentinel]](iterator.concept.sizedsentinel "24.3.4.8 Concept sized_­sentinel_­for")) and last1 - first1 != last2 - first2 for the first and third overloads in namespace ranges, or - [(3.3)](#alg.equal-3.3) R1 and R2 each model [sized_range](range.sized#concept:sized_range "25.4.4 Sized ranges [range.sized]") and ranges​::​distance(r1) != ranges​::​distance(r2) for the second and fourth overloads in namespace ranges, then no applications of the corresponding predicate and each projection; otherwise, at most min(last1 - first1, last2 - first2) applications of the corresponding predicate and any projections[.](#alg.equal-3.sentence-1) ### [26.6.14](#alg.is.permutation) Is permutation [[alg.is.permutation]](alg.is.permutation) [🔗](#lib:is_permutation) `template constexpr bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2); template constexpr bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, BinaryPredicate pred); template constexpr bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2); template constexpr bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred); ` [1](#alg.is.permutation-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5722) Let last2 be first2 + (last1 - first1) for the overloads with no parameter named last2, and let pred be equal_to{} for the overloads with no parameter pred[.](#alg.is.permutation-1.sentence-1) [2](#alg.is.permutation-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5728) *Mandates*: ForwardIterator1 and ForwardIterator2 have the same value type[.](#alg.is.permutation-2.sentence-1) [3](#alg.is.permutation-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5732) *Preconditions*: The comparison function is an equivalence relation[.](#alg.is.permutation-3.sentence-1) [4](#alg.is.permutation-4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5736) *Returns*: If last1 - first1 != last2 - first2, return false[.](#alg.is.permutation-4.sentence-1) Otherwise return true if there exists a permutation of the elements in the range [first2, last2), beginning with ForwardIterator2 begin, such that equal(first1, last1, begin, pred) returns true; otherwise, returns false[.](#alg.is.permutation-4.sentence-2) [5](#alg.is.permutation-5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5746) *Complexity*: No applications of the corresponding predicate if ForwardIterator1 and ForwardIterator2 meet the requirements of random access iterators andlast1 - first1 != last2 - first2[.](#alg.is.permutation-5.sentence-1) Otherwise, exactly last1 - first1 applications of the corresponding predicate if equal(first1, last1, first2, last2, pred) would return true; otherwise, at worst O(N2), where N has the value last1 - first1[.](#alg.is.permutation-5.sentence-2) [🔗](#lib:is_permutation_) `template<[forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11 Concept forward_­iterator [iterator.concept.forward]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]") S1, [forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11 Concept forward_­iterator [iterator.concept.forward]") I2, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]") S2, class Proj1 = identity, class Proj2 = identity, [indirect_equivalence_relation](indirectcallable.indirectinvocable#concept:indirect_equivalence_relation "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]"), projected> Pred = ranges::equal_to> constexpr bool ranges::is_permutation(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); template<[forward_range](range.refinements#concept:forward_range "25.4.6 Other range refinements [range.refinements]") R1, [forward_range](range.refinements#concept:forward_range "25.4.6 Other range refinements [range.refinements]") R2, class Proj1 = identity, class Proj2 = identity, [indirect_equivalence_relation](indirectcallable.indirectinvocable#concept:indirect_equivalence_relation "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]"), Proj1>, projected, Proj2>> Pred = ranges::equal_to> constexpr bool ranges::is_permutation(R1&& r1, R2&& r2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); ` [6](#alg.is.permutation-6) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5776) *Returns*: If last1 - first1 != last2 - first2, return false[.](#alg.is.permutation-6.sentence-1) Otherwise return true if there exists a permutation of the elements in the range [first2, last2), bounded by [pfirst, plast), such thatranges​::​equal(first1, last1, pfirst, plast, pred, proj1, proj2) returns true; otherwise, returns false[.](#alg.is.permutation-6.sentence-2) [7](#alg.is.permutation-7) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5786) *Complexity*: No applications of the corresponding predicate and projections if - [(7.1)](#alg.is.permutation-7.1) for the first overload, * [(7.1.1)](#alg.is.permutation-7.1.1) S1 and I1 model [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]"), * [(7.1.2)](#alg.is.permutation-7.1.2) S2 and I2 model [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]"), and * [(7.1.3)](#alg.is.permutation-7.1.3) last1 - first1 != last2 - first2; - [(7.2)](#alg.is.permutation-7.2) for the second overload,R1 and R2 each model [sized_range](range.sized#concept:sized_range "25.4.4 Sized ranges [range.sized]"), andranges​::​distance(r1) != ranges​::​distance(r2)[.](#alg.is.permutation-7.sentence-1) Otherwise, exactly last1 - first1 applications of the corresponding predicate and projections if ranges​::​equal(​first1, last1, first2, last2, pred, proj1, proj2) would return true; otherwise, at worst O(N2), where N has the value last1 - first1[.](#alg.is.permutation-7.sentence-2) ### [26.6.15](#alg.search) Search [[alg.search]](alg.search) [🔗](#lib:search) `template constexpr ForwardIterator1 search(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2); template ForwardIterator1 search(ExecutionPolicy&& exec, ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2); template constexpr ForwardIterator1 search(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred); template ForwardIterator1 search(ExecutionPolicy&& exec, ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred); ` [1](#alg.search-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5839) *Returns*: The first iterator i in the range [first1, last1 - (last2 - first2)] such that for every non-negative integer n less than last2 - first2 the following corresponding conditions hold:*(i + n) == *(first2 + n), pred(*(i + n), *(first2 + n)) != false[.](#alg.search-1.sentence-1) Returns first1 if [first2, last2) is empty, otherwise returns last1 if no such iterator is found[.](#alg.search-1.sentence-2) [2](#alg.search-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5849) *Complexity*: At most (last1 - first1) * (last2 - first2) applications of the corresponding predicate[.](#alg.search-2.sentence-1) [🔗](#lib:search_) `template<[forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11 Concept forward_­iterator [iterator.concept.forward]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]") S1, [forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11 Concept forward_­iterator [iterator.concept.forward]") I2, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]") S2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5 Concept indirectly_­comparable [alg.req.ind.cmp]") constexpr subrange ranges::search(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); template<[forward_range](range.refinements#concept:forward_range "25.4.6 Other range refinements [range.refinements]") R1, [forward_range](range.refinements#concept:forward_range "25.4.6 Other range refinements [range.refinements]") R2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5 Concept indirectly_­comparable [alg.req.ind.cmp]"), iterator_t, Pred, Proj1, Proj2> constexpr borrowed_subrange_t ranges::search(R1&& r1, R2&& r2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_­access_­iterator [iterator.concept.random.access]") I1, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]") S1, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_­access_­iterator [iterator.concept.random.access]") I2, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]") S2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5 Concept indirectly_­comparable [alg.req.ind.cmp]") subrange ranges::search(Ep&& exec, I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R1, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5 Concept indirectly_­comparable [alg.req.ind.cmp]"), iterator_t, Pred, Proj1, Proj2> borrowed_subrange_t ranges::search(Ep&& exec, R1&& r1, R2&& r2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); ` [3](#alg.search-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5887) *Returns*: - [(3.1)](#alg.search-3.1) {i, i + (last2 - first2)}, where i is the first iterator in the range [first1, last1 - (last2 - first2)] such that for every non-negative integer n less than last2 - first2 the conditionbool(invoke(pred, invoke(proj1, *(i + n)), invoke(proj2, *(first2 + n)))) is true. - [(3.2)](#alg.search-3.2) Returns {last1, last1} if no such iterator exists. [4](#alg.search-4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5905) *Complexity*: At most (last1 - first1) * (last2 - first2) applications of the corresponding predicate and projections[.](#alg.search-4.sentence-1) [🔗](#lib:search_n) `template::value_type> constexpr ForwardIterator search_n(ForwardIterator first, ForwardIterator last, Size count, const T& value); template::value_type> ForwardIterator search_n(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, Size count, const T& value); template::value_type, class BinaryPredicate> constexpr ForwardIterator search_n(ForwardIterator first, ForwardIterator last, Size count, const T& value, BinaryPredicate pred); template::value_type, class BinaryPredicate> ForwardIterator search_n(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, Size count, const T& value, BinaryPredicate pred); ` [5](#alg.search-5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5942) *Mandates*: The type Size is convertible to an integral type ([[conv.integral]](conv.integral "7.3.9 Integral conversions"), [[class.conv]](class.conv "11.4.8 Conversions"))[.](#alg.search-5.sentence-1) [6](#alg.search-6) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5947) Let E be pred(*(i + n), value) != false for the overloads with a parameter pred, and *(i + n) == value otherwise[.](#alg.search-6.sentence-1) [7](#alg.search-7) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5952) *Returns*: The first iterator i in the range [first, last - count] such that for every non-negative integer n less than count the condition E is true[.](#alg.search-7.sentence-1) Returns last if no such iterator is found[.](#alg.search-7.sentence-2) [8](#alg.search-8) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5959) *Complexity*: At most last - first applications of the corresponding predicate[.](#alg.search-8.sentence-1) [🔗](#lib:search_n_) `template<[forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11 Concept forward_­iterator [iterator.concept.forward]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]") S, class Pred = ranges::equal_to, class Proj = identity, class T = projected_value_t> requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5 Concept indirectly_­comparable [alg.req.ind.cmp]") constexpr subrange ranges::search_n(I first, S last, iter_difference_t count, const T& value, Pred pred = {}, Proj proj = {}); template<[forward_range](range.refinements#concept:forward_range "25.4.6 Other range refinements [range.refinements]") R, class Pred = ranges::equal_to, class Proj = identity, class T = projected_value_t, Proj>> requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5 Concept indirectly_­comparable [alg.req.ind.cmp]"), const T*, Pred, Proj> constexpr borrowed_subrange_t ranges::search_n(R&& r, range_difference_t count, const T& value, Pred pred = {}, Proj proj = {}); template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_­access_­iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]") S, class Pred = ranges::equal_to, class Proj = identity, class T = projected_value_t> requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5 Concept indirectly_­comparable [alg.req.ind.cmp]") subrange ranges::search_n(Ep&& exec, I first, S last, iter_difference_t count, const T& value, Pred pred = {}, Proj proj = {}); template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R, class Pred = ranges::equal_to, class Proj = identity, class T = projected_value_t, Proj>> requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5 Concept indirectly_­comparable [alg.req.ind.cmp]"), const T*, Pred, Proj> borrowed_subrange_t ranges::search_n(Ep&& exec, R&& r, range_difference_t count, const T& value, Pred pred = {}, Proj proj = {}); ` [9](#alg.search-9) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L5996) *Returns*: {i, i + count} where i is the first iterator in the range [first, last - count] such that for every non-negative integer n less than count, the following condition holds:invoke(pred, invoke(proj, *(i + n)), value)[.](#alg.search-9.sentence-1) Returns {last, last} if no such iterator is found[.](#alg.search-9.sentence-2) [10](#alg.search-10) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6005) *Complexity*: At most last - first applications of the corresponding predicate and projection[.](#alg.search-10.sentence-1) [🔗](#lib:search__) `template constexpr ForwardIterator search(ForwardIterator first, ForwardIterator last, const Searcher& searcher); ` [11](#alg.search-11) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6019) *Effects*: Equivalent to: return searcher(first, last).first; [12](#alg.search-12) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6023) *Remarks*: Searcher need not meet the [*Cpp17CopyConstructible*](utility.arg.requirements#:Cpp17CopyConstructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") requirements[.](#alg.search-12.sentence-1) ### [26.6.16](#alg.starts.with) Starts with [[alg.starts.with]](alg.starts.with) [🔗](#lib:starts_with) `template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]") S1, [input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]") I2, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]") S2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5 Concept indirectly_­comparable [alg.req.ind.cmp]") constexpr bool ranges::starts_with(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); template<[input_range](range.refinements#concept:input_range "25.4.6 Other range refinements [range.refinements]") R1, [input_range](range.refinements#concept:input_range "25.4.6 Other range refinements [range.refinements]") R2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5 Concept indirectly_­comparable [alg.req.ind.cmp]"), iterator_t, Pred, Proj1, Proj2> constexpr bool ranges::starts_with(R1&& r1, R2&& r2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); ` [1](#alg.starts.with-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6045) *Returns*: ranges::mismatch(std::move(first1), last1, std::move(first2), last2, pred, proj1, proj2).in2 == last2 [🔗](#alg.starts.with-itemdecl:2) `template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_­access_­iterator [iterator.concept.random.access]") I1, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]") S1, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_­access_­iterator [iterator.concept.random.access]") I2, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]") S2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5 Concept indirectly_­comparable [alg.req.ind.cmp]") bool ranges::starts_with(Ep&& exec, I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R1, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5 Concept indirectly_­comparable [alg.req.ind.cmp]"), iterator_t, Pred, Proj1, Proj2> bool ranges::starts_with(Ep&& exec, R1&& r1, R2&& r2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); ` [2](#alg.starts.with-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6069) *Returns*: ranges::mismatch(std::forward(exec), std::move(first1), last1, std::move(first2), last2, pred, proj1, proj2).in2 == last2 ### [26.6.17](#alg.ends.with) Ends with [[alg.ends.with]](alg.ends.with) [🔗](#lib:ends_with) `template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]") S1, [input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]") I2, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]") S2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires ([forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11 Concept forward_­iterator [iterator.concept.forward]") || [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]")) && ([forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11 Concept forward_­iterator [iterator.concept.forward]") || [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]")) && [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5 Concept indirectly_­comparable [alg.req.ind.cmp]") constexpr bool ranges::ends_with(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); ` [1](#alg.ends.with-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6091) Let N1 be last1 - first1 andN2 be last2 - first2[.](#alg.ends.with-1.sentence-1) [2](#alg.ends.with-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6095) *Returns*: false if N1 < N2, otherwise:ranges::equal(std::move(first1) + (N1 - N2), last1, std::move(first2), last2, pred, proj1, proj2) [🔗](#alg.ends.with-itemdecl:2) `template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_­access_­iterator [iterator.concept.random.access]") I1, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]") S1, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_­access_­iterator [iterator.concept.random.access]") I2, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]") S2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5 Concept indirectly_­comparable [alg.req.ind.cmp]") bool ranges::ends_with(Ep&& exec, I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); ` [3](#alg.ends.with-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6114) Let N1 be last1 - first1 andN2 be last2 - first2[.](#alg.ends.with-3.sentence-1) [4](#alg.ends.with-4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6118) *Returns*: false if N1 < N2, otherwise:ranges::equal(std::forward(exec), std::move(first1) + (N1 - N2), last1, std::move(first2), last2, pred, proj1, proj2) [🔗](#alg.ends.with-itemdecl:3) `template<[input_range](range.refinements#concept:input_range "25.4.6 Other range refinements [range.refinements]") R1, [input_range](range.refinements#concept:input_range "25.4.6 Other range refinements [range.refinements]") R2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires ([forward_range](range.refinements#concept:forward_range "25.4.6 Other range refinements [range.refinements]") || [sized_range](range.sized#concept:sized_range "25.4.4 Sized ranges [range.sized]")) && ([forward_range](range.refinements#concept:forward_range "25.4.6 Other range refinements [range.refinements]") || [sized_range](range.sized#concept:sized_range "25.4.4 Sized ranges [range.sized]")) && [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5 Concept indirectly_­comparable [alg.req.ind.cmp]"), iterator_t, Pred, Proj1, Proj2> constexpr bool ranges::ends_with(R1&& r1, R2&& r2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); ` [5](#alg.ends.with-5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6138) Let N1 be ranges​::​distance(r1) andN2 be ranges​::​distance(r2)[.](#alg.ends.with-5.sentence-1) [6](#alg.ends.with-6) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6142) *Returns*: false if N1 < N2, otherwise:ranges::equal(views::drop(ranges::ref_view(r1), N1 - static_cast(N2)), r2, pred, proj1, proj2) [🔗](#alg.ends.with-itemdecl:4) `template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1 Preamble [algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R1, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6 Other range refinements [range.refinements]") R2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5 Concept indirectly_­comparable [alg.req.ind.cmp]"), iterator_t, Pred, Proj1, Proj2> bool ranges::ends_with(Ep&& exec, R1&& r1, R2&& r2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); ` [7](#alg.ends.with-7) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6161) Let N1 be ranges​::​distance(r1) andN2 be ranges​::​distance(r2)[.](#alg.ends.with-7.sentence-1) [8](#alg.ends.with-8) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6165) *Returns*: false if N1 < N2, otherwise:ranges::equal(std::forward(exec), views::drop(ranges::ref_view(r1), N1 - static_cast(N2)), r2, pred, proj1, proj2) ### [26.6.18](#alg.fold) Fold [[alg.fold]](alg.fold) [🔗](#lib:fold_left) `template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]") S, class T = iter_value_t, [indirectly-binary-left-foldable](algorithm.syn#concept:indirectly-binary-left-foldable "26.4 Header synopsis [algorithm.syn]") F> constexpr auto ranges::fold_left(I first, S last, T init, F f); template<[input_range](range.refinements#concept:input_range "25.4.6 Other range refinements [range.refinements]") R, class T = range_value_t, [indirectly-binary-left-foldable](algorithm.syn#concept:indirectly-binary-left-foldable "26.4 Header synopsis [algorithm.syn]")> F> constexpr auto ranges::fold_left(R&& r, T init, F f); ` [1](#alg.fold-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6188) *Returns*: ranges::fold_left_with_iter(std::move(first), last, std::move(init), f).value [🔗](#lib:fold_left_first) `template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]") S, [indirectly-binary-left-foldable](algorithm.syn#concept:indirectly-binary-left-foldable "26.4 Header synopsis [algorithm.syn]"), I> F> requires [constructible_from](concept.constructible#concept:constructible_from "18.4.11 Concept constructible_­from [concept.constructible]"), iter_reference_t> constexpr auto ranges::fold_left_first(I first, S last, F f); template<[input_range](range.refinements#concept:input_range "25.4.6 Other range refinements [range.refinements]") R, [indirectly-binary-left-foldable](algorithm.syn#concept:indirectly-binary-left-foldable "26.4 Header synopsis [algorithm.syn]"), iterator_t> F> requires [constructible_from](concept.constructible#concept:constructible_from "18.4.11 Concept constructible_­from [concept.constructible]"), range_reference_t> constexpr auto ranges::fold_left_first(R&& r, F f); ` [2](#alg.fold-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6207) *Returns*: ranges::fold_left_first_with_iter(std::move(first), last, f).value [🔗](#lib:fold_right) `template<[bidirectional_iterator](iterator.concept.bidir#concept:bidirectional_iterator "24.3.4.12 Concept bidirectional_­iterator [iterator.concept.bidir]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]") S, class T = iter_value_t, [indirectly-binary-right-foldable](algorithm.syn#concept:indirectly-binary-right-foldable "26.4 Header synopsis [algorithm.syn]") F> constexpr auto ranges::fold_right(I first, S last, T init, F f); template<[bidirectional_range](range.refinements#concept:bidirectional_range "25.4.6 Other range refinements [range.refinements]") R, class T = range_value_t, [indirectly-binary-right-foldable](algorithm.syn#concept:indirectly-binary-right-foldable "26.4 Header synopsis [algorithm.syn]")> F> constexpr auto ranges::fold_right(R&& r, T init, F f); ` [3](#alg.fold-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6225) *Effects*: Equivalent to:using U = decay_t, T>>;if (first == last)return U(std::move(init)); I tail = ranges::next(first, last); U accum = invoke(f, *--tail, std::move(init));while (first != tail) accum = invoke(f, *--tail, std::move(accum));return accum; [🔗](#lib:fold_right_last) `template<[bidirectional_iterator](iterator.concept.bidir#concept:bidirectional_iterator "24.3.4.12 Concept bidirectional_­iterator [iterator.concept.bidir]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]") S, [indirectly-binary-right-foldable](algorithm.syn#concept:indirectly-binary-right-foldable "26.4 Header synopsis [algorithm.syn]"), I> F> requires [constructible_from](concept.constructible#concept:constructible_from "18.4.11 Concept constructible_­from [concept.constructible]"), iter_reference_t> constexpr auto ranges::fold_right_last(I first, S last, F f); template<[bidirectional_range](range.refinements#concept:bidirectional_range "25.4.6 Other range refinements [range.refinements]") R, [indirectly-binary-right-foldable](algorithm.syn#concept:indirectly-binary-right-foldable "26.4 Header synopsis [algorithm.syn]"), iterator_t> F> requires [constructible_from](concept.constructible#concept:constructible_from "18.4.11 Concept constructible_­from [concept.constructible]"), range_reference_t> constexpr auto ranges::fold_right_last(R&& r, F f); ` [4](#alg.fold-4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6253) Let U bedecltype(ranges​::​fold_right(first, last, iter_value_t(*first), f))[.](#alg.fold-4.sentence-1) [5](#alg.fold-5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6257) *Effects*: Equivalent to:if (first == last)return optional(); I tail = ranges::prev(ranges::next(first, std::move(last)));return optional(in_place, ranges::fold_right(std::move(first), tail, iter_value_t(*tail), std::move(f))); [🔗](#lib:fold_left_with_iter) `template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]") S, class T = iter_value_t, [indirectly-binary-left-foldable](algorithm.syn#concept:indirectly-binary-left-foldable "26.4 Header synopsis [algorithm.syn]") F> constexpr see below ranges::fold_left_with_iter(I first, S last, T init, F f); template<[input_range](range.refinements#concept:input_range "25.4.6 Other range refinements [range.refinements]") R, class T = range_value_t, [indirectly-binary-left-foldable](algorithm.syn#concept:indirectly-binary-left-foldable "26.4 Header synopsis [algorithm.syn]")> F> constexpr see below ranges::fold_left_with_iter(R&& r, T init, F f); ` [6](#alg.fold-6) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6280) Let U be decay_t>>[.](#alg.fold-6.sentence-1) [7](#alg.fold-7) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6283) *Effects*: Equivalent to:if (first == last)return {std::move(first), U(std::move(init))}; U accum = invoke(f, std::move(init), *first);for (++first; first != last; ++first) accum = invoke(f, std::move(accum), *first);return {std::move(first), std::move(accum)}; [8](#alg.fold-8) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6295) *Remarks*: The return type isfold_left_with_iter_result for the first overload andfold_left_with_iter_result, U> for the second overload[.](#alg.fold-8.sentence-1) [🔗](#lib:fold_left_first_with_iter) `template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]") S, [indirectly-binary-left-foldable](algorithm.syn#concept:indirectly-binary-left-foldable "26.4 Header synopsis [algorithm.syn]"), I> F> requires [constructible_from](concept.constructible#concept:constructible_from "18.4.11 Concept constructible_­from [concept.constructible]"), iter_reference_t> constexpr see below ranges::fold_left_first_with_iter(I first, S last, F f); template<[input_range](range.refinements#concept:input_range "25.4.6 Other range refinements [range.refinements]") R, [indirectly-binary-left-foldable](algorithm.syn#concept:indirectly-binary-left-foldable "26.4 Header synopsis [algorithm.syn]"), iterator_t> F> requires [constructible_from](concept.constructible#concept:constructible_from "18.4.11 Concept constructible_­from [concept.constructible]"), range_reference_t> constexpr see below ranges::fold_left_first_with_iter(R&& r, F f); ` [9](#alg.fold-9) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6315) Let U bedecltype(ranges::fold_left(std::move(first), last, iter_value_t(*first), f)) [10](#alg.fold-10) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6321) *Effects*: Equivalent to:if (first == last)return {std::move(first), optional()}; optional init(in_place, *first);for (++first; first != last; ++first)*init = invoke(f, std::move(*init), *first);return {std::move(first), std::move(init)}; [11](#alg.fold-11) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L6333) *Remarks*: The return type isfold_left_first_with_iter_result> for the first overload andfold_left_first_with_iter_result, optional> for the second overload[.](#alg.fold-11.sentence-1)