Files
cppdraft_translate/cppdraft/alg/nonmodifying.md
2025-10-25 03:02:53 +03:00

138 KiB
Raw Blame History

[alg.nonmodifying]

26 Algorithms library [algorithms]

26.6 Non-modifying sequence operations [alg.nonmodifying]

26.6.1 All of [alg.all.of]

🔗

`template<class InputIterator, class Predicate> constexpr bool all_of(InputIterator first, InputIterator last, Predicate pred); template<class ExecutionPolicy, class ForwardIterator, class Predicate> bool all_of(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, Predicate pred);

template<input_iterator I, sentinel_for S, class Proj = identity, indirect_unary_predicate<projected<I, Proj>> Pred> constexpr bool ranges::all_of(I first, S last, Pred pred, Proj proj = {}); template<input_range R, class Proj = identity, indirect_unary_predicate<projected<iterator_t, Proj>> Pred> constexpr bool ranges::all_of(R&& r, Pred pred, Proj proj = {});

template<execution-policy Ep, random_access_iterator I, sized_sentinel_for S, class Proj = identity, indirect_unary_predicate<projected<I, Proj>> Pred> bool ranges::all_of(Ep&& exec, I first, S last, Pred pred, Proj proj = {}); template<execution-policy Ep, sized-random-access-range R, class Proj = identity, indirect_unary_predicate<projected<iterator_t, Proj>> Pred> bool ranges::all_of(Ep&& exec, R&& r, Pred pred, Proj proj = {}); `

1

#

Let E be:

pred(*i) for the overloads in namespace std;

invoke(pred, invoke(proj, *i)) for the overloads in namespace ranges.

2

#

Returns: false if E is false for some iterator i in the range [first, last), andtrue otherwise.

3

#

Complexity: At most last - first applications of the predicate and any projection.

26.6.2 Any of [alg.any.of]

🔗

`template<class InputIterator, class Predicate> constexpr bool any_of(InputIterator first, InputIterator last, Predicate pred); template<class ExecutionPolicy, class ForwardIterator, class Predicate> bool any_of(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, Predicate pred);

template<input_iterator I, sentinel_for S, class Proj = identity, indirect_unary_predicate<projected<I, Proj>> Pred> constexpr bool ranges::any_of(I first, S last, Pred pred, Proj proj = {}); template<input_range R, class Proj = identity, indirect_unary_predicate<projected<iterator_t, Proj>> Pred> constexpr bool ranges::any_of(R&& r, Pred pred, Proj proj = {});

template<execution-policy Ep, random_access_iterator I, sized_sentinel_for S, class Proj = identity, indirect_unary_predicate<projected<I, Proj>> Pred> bool ranges::any_of(Ep&& exec, I first, S last, Pred pred, Proj proj = {}); template<execution-policy Ep, sized-random-access-range R, class Proj = identity, indirect_unary_predicate<projected<iterator_t, Proj>> Pred> bool ranges::any_of(Ep&& exec, R&& r, Pred pred, Proj proj = {}); `

1

#

Let E be:

pred(*i) for the overloads in namespace std;

invoke(pred, invoke(proj, *i)) for the overloads in namespace ranges.

2

#

Returns: true if E is true for some iterator i in the range [first, last), and false otherwise.

3

#

Complexity: At most last - first applications of the predicate and any projection.

26.6.3 None of [alg.none.of]

🔗

`template<class InputIterator, class Predicate> constexpr bool none_of(InputIterator first, InputIterator last, Predicate pred); template<class ExecutionPolicy, class ForwardIterator, class Predicate> bool none_of(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, Predicate pred);

template<input_iterator I, sentinel_for S, class Proj = identity, indirect_unary_predicate<projected<I, Proj>> Pred> constexpr bool ranges::none_of(I first, S last, Pred pred, Proj proj = {}); template<input_range R, class Proj = identity, indirect_unary_predicate<projected<iterator_t, Proj>> Pred> constexpr bool ranges::none_of(R&& r, Pred pred, Proj proj = {});

template<execution-policy Ep, random_access_iterator I, sized_sentinel_for S, class Proj = identity, indirect_unary_predicate<projected<I, Proj>> Pred> bool ranges::none_of(Ep&& exec, I first, S last, Pred pred, Proj proj = {}); template<execution-policy Ep, sized-random-access-range R, class Proj = identity, indirect_unary_predicate<projected<iterator_t, Proj>> Pred> bool ranges::none_of(Ep&& exec, R&& r, Pred pred, Proj proj = {}); `

1

#

Let E be:

pred(*i) for the overloads in namespace std;

invoke(pred, invoke(proj, *i)) for the overloads in namespace ranges.

2

#

Returns: false if E is true for some iterator i in the range [first, last), andtrue otherwise.

3

#

Complexity: At most last - first applications of the predicate and any projection.

26.6.4 Contains [alg.contains]

🔗

template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class Proj = identity, class T = projected_value_t<I, Proj>> requires [indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<ranges::equal_to, projected<I, Proj>, 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.6Other range refinements[range.refinements]") R, class Proj = identity, class T = projected_value_t<iterator_t<R>, Proj>> requires [indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*> constexpr bool ranges::contains(R&& r, const T& value, Proj proj = {});

1

#

Returns: ranges::find(std::move(first), last, value, proj) != last.

🔗

template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S, class Proj = identity, class T = projected_value_t<I, Proj>> requires [indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<ranges::equal_to, projected<I, Proj>, 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.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity, class T = projected_value_t<iterator_t<R>, Proj>> requires [indirect_binary_predicate](indirectcallable.indirectinvocable#concept:indirect_binary_predicate "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*> bool ranges::contains(Ep&& exec, R&& r, const T& value, Proj proj = {});

2

#

Returns: ranges::find(std::forward(exec), first, last, value, proj) != last.

🔗

template<[forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11Concept forward_­iterator[iterator.concept.forward]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I1> S1, [forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11Concept forward_­iterator[iterator.concept.forward]") I2, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I2> 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.5Concept indirectly_­comparable[alg.req.ind.cmp]")<I1, I2, Pred, Proj1, Proj2> 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.6Other range refinements[range.refinements]") R1, [forward_range](range.refinements#concept:forward_range "25.4.6Other 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.5Concept indirectly_­comparable[alg.req.ind.cmp]")<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2> constexpr bool ranges::contains_subrange(R1&& r1, R2&& r2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {});

3

#

Returns: first2 == last2 || !ranges::search(first1, last1, first2, last2, pred, proj1, proj2).empty()

🔗

template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I1, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I1> S1, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I2, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I2> 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.5Concept indirectly_­comparable[alg.req.ind.cmp]")<I1, I2, Pred, Proj1, Proj2> 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.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R1, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other 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.5Concept indirectly_­comparable[alg.req.ind.cmp]")<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2> bool ranges::contains_subrange(Ep&& exec, R1&& r1, R2&& r2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {});

4

#

Returns: first2 == last2 || !ranges::search(std::forward(exec), first1, last1, first2, last2, pred, proj1, proj2).empty()

26.6.5 For each [alg.foreach]

🔗

template<class InputIterator, class Function> constexpr Function for_each(InputIterator first, InputIterator last, Function f);

1

#

Preconditions: Function meets the Cpp17MoveConstructible requirements (Table 31).

[Note 1:

Function need not meet the requirements ofCpp17CopyConstructible (Table 32).

— end note]

2

#

Effects: Applies f to the result of dereferencing every iterator in the range [first, last), starting from first and proceeding to last - 1.

[Note 2:

If the type of first meets the requirements of a mutable iterator,f can apply non-constant functions through the dereferenced iterator.

— end note]

3

#

Returns: f.

4

#

Complexity: Applies f exactly last - first times.

5

#

Remarks: If f returns a result, the result is ignored.

🔗

template<class ExecutionPolicy, class ForwardIterator, class Function> void for_each(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, Function f);

6

#

Preconditions: Function meets the Cpp17CopyConstructible requirements.

7

#

Effects: Applies f to the result of dereferencing every iterator in the range [first, last).

[Note 3:

If the type of first meets the requirements of a mutable iterator,f can apply non-constant functions through the dereferenced iterator.

— end note]

8

#

Complexity: Applies f exactly last - first times.

9

#

Remarks: If f returns a result, the result is ignored.

Implementations do not have the freedom granted under [algorithms.parallel.exec] to make arbitrary copies of elements from the input sequence.

10

#

[Note 4:

Does not return a copy of its Function parameter, since parallelization often does not permit efficient state accumulation.

— end note]

🔗

template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class Proj = identity, [indirectly_unary_invocable](indirectcallable.indirectinvocable#concept:indirectly_unary_invocable "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Fun> constexpr ranges::for_each_result<I, Fun> ranges::for_each(I first, S last, Fun f, Proj proj = {}); template<[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity, [indirectly_unary_invocable](indirectcallable.indirectinvocable#concept:indirectly_unary_invocable "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Fun> constexpr ranges::for_each_result<borrowed_iterator_t<R>, Fun> ranges::for_each(R&& r, Fun f, Proj proj = {});

11

#

Effects: Calls invoke(f, invoke(proj, *i)) for every iterator i in the range [first, last), starting from first and proceeding to last - 1.

[Note 5:

If the result of invoke(proj, *i) is a mutable reference,f can apply non-constant functions.

— end note]

12

#

Returns: {last, std::move(f)}.

13

#

Complexity: Applies f and proj exactly last - first times.

14

#

Remarks: If f returns a result, the result is ignored.

15

#

[Note 6:

The overloads in namespace ranges requireFun to model copy_constructible.

— end note]

🔗

template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I> S, class Proj = identity, [indirectly_unary_invocable](indirectcallable.indirectinvocable#concept:indirectly_unary_invocable "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> 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.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R, class Proj = identity, [indirectly_unary_invocable](indirectcallable.indirectinvocable#concept:indirectly_unary_invocable "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Fun> borrowed_iterator_t<R> ranges::for_each(Ep&& exec, R&& r, Fun f, Proj proj = {});

16

#

Effects: Calls invoke(f, invoke(proj, *i)) for every iterator i in the range [first, last).

[Note 7:

If the result of invoke(proj, *i) is a mutable reference,f can apply non-constant functions.

— end note]

17

#

Returns: last.

18

#

Complexity: Applies f and proj exactly last - first times.

19

#

Remarks:

[Note 8:

Does not return a copy of its Fun parameter, since parallelization often does not permit efficient state accumulation.

— end note]

🔗

template<class InputIterator, class Size, class Function> constexpr InputIterator for_each_n(InputIterator first, Size n, Function f);

20

#

Mandates: The type Size is convertible to an integral type ([conv.integral], [class.conv]).

21

#

Preconditions: n >= 0 is true.

Function meets the Cpp17MoveConstructible requirements.

[Note 9:

Function need not meet the requirements of Cpp17CopyConstructible.

— end note]

22

#

Effects: Applies f to the result of dereferencing every iterator in the range [first, first + n) in order.

[Note 10:

If the type of first meets the requirements of a mutable iterator,f can apply non-constant functions through the dereferenced iterator.

— end note]

23

#

Returns: first + n.

24

#

Remarks: If f returns a result, the result is ignored.

🔗

template<class ExecutionPolicy, class ForwardIterator, class Size, class Function> ForwardIterator for_each_n(ExecutionPolicy&& exec, ForwardIterator first, Size n, Function f);

25

#

Mandates: The type Size is convertible to an integral type ([conv.integral], [class.conv]).

26

#

Preconditions: n >= 0 is true.

Function meets the Cpp17CopyConstructible requirements.

27

#

Effects: Applies f to the result of dereferencing every iterator in the range [first, first + n).

[Note 11:

If the type of first meets the requirements of a mutable iterator,f can apply non-constant functions through the dereferenced iterator.

— end note]

28

#

Returns: first + n.

29

#

Remarks: If f returns a result, the result is ignored.

Implementations do not have the freedom granted under [algorithms.parallel.exec] to make arbitrary copies of elements from the input sequence.

🔗

template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I, class Proj = identity, [indirectly_unary_invocable](indirectcallable.indirectinvocable#concept:indirectly_unary_invocable "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Fun> constexpr ranges::for_each_n_result<I, Fun> ranges::for_each_n(I first, iter_difference_t<I> n, Fun f, Proj proj = {});

30

#

Preconditions: n >= 0 is true.

31

#

Effects: Calls invoke(f, invoke(proj, *i)) for every iterator i in the range [first, first + n) in order.

[Note 12:

If the result of invoke(proj, *i) is a mutable reference,f can apply non-constant functions.

— end note]

32

#

Returns: {first + n, std::move(f)}.

33

#

Remarks: If f returns a result, the result is ignored.

34

#

[Note 13:

The overload in namespace ranges requires Fun to model copy_constructible.

— end note]

🔗

template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I, class Proj = identity, [indirectly_unary_invocable](indirectcallable.indirectinvocable#concept:indirectly_unary_invocable "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I, Proj>> Fun> I ranges::for_each_n(Ep&& exec, I first, iter_difference_t<I> n, Fun f, Proj proj = {});

35

#

Preconditions: n >= 0 is true.

36

#

Effects: Calls invoke(f, invoke(proj, *i)) for every iterator i in the range [first, first + n).

[Note 14:

If the result of invoke(proj, *i) is a mutable reference,f can apply non-constant functions.

— end note]

37

#

Returns: first + n.

38

#

Remarks:

[Note 15:

Does not return a copy of its Fun parameter, since parallelization often does not permit efficient state accumulation.

— end note]

26.6.6 Find [alg.find]

🔗

`template<class InputIterator, class T = iterator_traits::value_type> constexpr InputIterator find(InputIterator first, InputIterator last, const T& value); template<class ExecutionPolicy, class ForwardIterator, class T = iterator_traits::value_type> ForwardIterator find(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, const T& value);

template<class InputIterator, class Predicate> constexpr InputIterator find_if(InputIterator first, InputIterator last, Predicate pred); template<class ExecutionPolicy, class ForwardIterator, class Predicate> ForwardIterator find_if(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, Predicate pred);

template<class InputIterator, class Predicate> constexpr InputIterator find_if_not(InputIterator first, InputIterator last, Predicate pred); template<class ExecutionPolicy, class ForwardIterator, class Predicate> ForwardIterator find_if_not(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, Predicate pred);

template<input_iterator I, sentinel_for S, class Proj = identity, class T = projected_value_t<I, Proj>> requires indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*> constexpr I ranges::find(I first, S last, const T& value, Proj proj = {}); template<input_range R, class Proj = identity, class T = projected_value_t<iterator_t, Proj>> requires indirect_binary_predicate<ranges::equal_to, projected<iterator_t, Proj>, const T*> constexpr borrowed_iterator_t ranges::find(R&& r, const T& value, Proj proj = {});

template<execution-policy Ep, random_access_iterator I, sized_sentinel_for S, class Proj = identity, class T = projected_value_t<I, Proj>> requires indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*> I ranges::find(Ep&& exec, I first, S last, const T& value, Proj proj = {}); template<execution-policy Ep, sized-random-access-range R, class Proj = identity, class T = projected_value_t<iterator_t, Proj>> requires indirect_binary_predicate<ranges::equal_to, projected<iterator_t, Proj>, const T*> borrowed_iterator_t ranges::find(Ep&& exec, R&& r, const T& value, Proj proj = {});

template<input_iterator I, sentinel_for S, class Proj = identity, indirect_unary_predicate<projected<I, Proj>> Pred> constexpr I ranges::find_if(I first, S last, Pred pred, Proj proj = {}); template<input_range R, class Proj = identity, indirect_unary_predicate<projected<iterator_t, Proj>> Pred> constexpr borrowed_iterator_t ranges::find_if(R&& r, Pred pred, Proj proj = {});

template<execution-policy Ep, random_access_iterator I, sized_sentinel_for S, class Proj = identity, indirect_unary_predicate<projected<I, Proj>> Pred> I ranges::find_if(Ep&& exec, I first, S last, Pred pred, Proj proj = {}); template<execution-policy Ep, sized-random-access-range R, class Proj = identity, indirect_unary_predicate<projected<iterator_t, Proj>> Pred> borrowed_iterator_t ranges::find_if(Ep&& exec, R&& r, Pred pred, Proj proj = {});

template<input_iterator I, sentinel_for S, class Proj = identity, indirect_unary_predicate<projected<I, Proj>> Pred> constexpr I ranges::find_if_not(I first, S last, Pred pred, Proj proj = {}); template<input_range R, class Proj = identity, indirect_unary_predicate<projected<iterator_t, Proj>> Pred> constexpr borrowed_iterator_t ranges::find_if_not(R&& r, Pred pred, Proj proj = {});

template<execution-policy Ep, random_access_iterator I, sized_sentinel_for S, class Proj = identity, indirect_unary_predicate<projected<I, Proj>> Pred> I ranges::find_if_not(Ep&& exec, I first, S last, Pred pred, Proj proj = {}); template<execution-policy Ep, sized-random-access-range R, class Proj = identity, indirect_unary_predicate<projected<iterator_t, Proj>> Pred> borrowed_iterator_t ranges::find_if_not(Ep&& exec, R&& r, Pred pred, Proj proj = {}); `

1

#

Let E be:

*i == value for find;

pred(*i) != false for find_if;

pred(*i) == false for find_if_not;

bool(invoke(proj, *i) == value) for ranges::find;

bool(invoke(pred, invoke(proj, *i))) for ranges::find_if;

bool(!invoke(pred, invoke(proj, *i))) for ranges::find_if_not.

2

#

Returns: The first iterator i in the range [first, last) for which E is true.

Returns last if no such iterator is found.

3

#

Complexity: At most last - first applications of the corresponding predicate and any projection.

26.6.7 Find last [alg.find.last]

🔗

`template<forward_iterator I, sentinel_for S, class Proj = identity, class T = projected_value_t<I, Proj>> requires indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*> constexpr subrange ranges::find_last(I first, S last, const T& value, Proj proj = {}); template<forward_range R, class Proj = identity, class T = projected_value_t<iterator_t, Proj>> requires indirect_binary_predicate<ranges::equal_to, projected<iterator_t, Proj>, const T*> constexpr borrowed_subrange_t ranges::find_last(R&& r, const T& value, Proj proj = {});

template<execution-policy Ep, random_access_iterator I, sized_sentinel_for S, class Proj = identity, class T = projected_value_t<I, Proj>> requires indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*> subrange ranges::find_last(Ep&& exec, I first, S last, const T& value, Proj proj = {}); template<execution-policy Ep, sized-random-access-range R, class Proj = identity, class T = projected_value_t<iterator_t, Proj>> requires indirect_binary_predicate<ranges::equal_to, projected<iterator_t, Proj>, const T*> borrowed_subrange_t ranges::find_last(Ep&& exec, R&& r, const T& value, Proj proj = {});

template<forward_iterator I, sentinel_for S, class Proj = identity, indirect_unary_predicate<projected<I, Proj>> Pred> constexpr subrange ranges::find_last_if(I first, S last, Pred pred, Proj proj = {}); template<forward_range R, class Proj = identity, indirect_unary_predicate<projected<iterator_t, Proj>> Pred> constexpr borrowed_subrange_t ranges::find_last_if(R&& r, Pred pred, Proj proj = {});

template<execution-policy Ep, random_access_iterator I, sized_sentinel_for S, class Proj = identity, indirect_unary_predicate<projected<I, Proj>> Pred> subrange ranges::find_last_if(Ep&& exec, I first, S last, Pred pred, Proj proj = {}); template<execution-policy Ep, sized-random-access-range R, class Proj = identity, indirect_unary_predicate<projected<iterator_t, Proj>> Pred> borrowed_subrange_t ranges::find_last_if(Ep&& exec, R&& r, Pred pred, Proj proj = {});

template<forward_iterator I, sentinel_for S, class Proj = identity, indirect_unary_predicate<projected<I, Proj>> Pred> constexpr subrange ranges::find_last_if_not(I first, S last, Pred pred, Proj proj = {}); template<forward_range R, class Proj = identity, indirect_unary_predicate<projected<iterator_t, Proj>> Pred> constexpr borrowed_subrange_t ranges::find_last_if_not(R&& r, Pred pred, Proj proj = {});

template<execution-policy Ep, random_access_iterator I, sized_sentinel_for S, class Proj = identity, indirect_unary_predicate<projected<I, Proj>> Pred> subrange ranges::find_last_if_not(Ep&& exec, I first, S last, Pred pred, Proj proj = {}); template<execution-policy Ep, sized-random-access-range R, class Proj = identity, indirect_unary_predicate<projected<iterator_t, Proj>> Pred> borrowed_subrange_t ranges::find_last_if_not(Ep&& exec, R&& r, Pred pred, Proj proj = {}); `

1

#

Let E be:

bool(invoke(proj, *i) == value) for ranges::find_last;

bool(invoke(pred, invoke(proj, *i))) for ranges::find_last_if;

bool(!invoke(pred, invoke(proj, *i))) for ranges::find_last_if_not.

2

#

Returns: Let i be the last iterator in the range [first, last) for which E is true.

Returns {i, last}, or{last, last} if no such iterator is found.

3

#

Complexity: At most last - first applications of the corresponding predicate and projection.

26.6.8 Find end [alg.find.end]

🔗

`template<class ForwardIterator1, class ForwardIterator2> constexpr ForwardIterator1 find_end(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2); template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2> ForwardIterator1 find_end(ExecutionPolicy&& exec, ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2);

template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate> constexpr ForwardIterator1 find_end(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred); template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class BinaryPredicate> ForwardIterator1 find_end(ExecutionPolicy&& exec, ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred);

template<forward_iterator I1, sentinel_for S1, forward_iterator I2, sentinel_for S2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires indirectly_comparable<I1, I2, Pred, Proj1, Proj2> constexpr subrange ranges::find_end(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); template<forward_range R1, forward_range R2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires indirectly_comparable<iterator_t, 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 Ep, random_access_iterator I1, sized_sentinel_for S1, random_access_iterator I2, sized_sentinel_for S2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires indirectly_comparable<I1, I2, Pred, Proj1, Proj2> subrange ranges::find_end(Ep&& exec, I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); template<execution-policy Ep, sized-random-access-range R1, sized-random-access-range R2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires indirectly_comparable<iterator_t, iterator_t, Pred, Proj1, Proj2> borrowed_subrange_t ranges::find_end(Ep&& exec, R1&& r1, R2&& r2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); `

1

#

Let:

pred be equal_to{} for the overloads with no parameter pred;

E be:

pred(*(i + n), *(first2 + n)) for the overloads in namespace std;

invoke(pred, invoke(proj1, *(i + n)), invoke(proj2, *(first2 + n))) for the overloads in namespace ranges;

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. Otherwise i is the last such iterator in [first1, last1 - (last2 - first2)).

2

#

Returns:

  • (2.1)

    i for the overloads in namespace std.

  • (2.2)

    {i, i + (i == last1 ? 0 : last2 - first2)} for the overloads in namespace ranges.

3

#

Complexity: At most(last2 - first2) * (last1 - first1 - (last2 - first2) + 1) applications of the corresponding predicate and any projections.

26.6.9 Find first [alg.find.first.of]

🔗

`template<class InputIterator, class ForwardIterator> constexpr InputIterator find_first_of(InputIterator first1, InputIterator last1, ForwardIterator first2, ForwardIterator last2); template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2> ForwardIterator1 find_first_of(ExecutionPolicy&& exec, ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2);

template<class InputIterator, class ForwardIterator, class BinaryPredicate> constexpr InputIterator find_first_of(InputIterator first1, InputIterator last1, ForwardIterator first2, ForwardIterator last2, BinaryPredicate pred); template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class BinaryPredicate> ForwardIterator1 find_first_of(ExecutionPolicy&& exec, ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred);

template<input_iterator I1, sentinel_for S1, forward_iterator I2, sentinel_for S2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires indirectly_comparable<I1, I2, Pred, Proj1, Proj2> constexpr I1 ranges::find_first_of(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); template<input_range R1, forward_range R2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires indirectly_comparable<iterator_t, 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 Ep, random_access_iterator I1, sized_sentinel_for S1, random_access_iterator I2, sized_sentinel_for S2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires indirectly_comparable<I1, I2, Pred, Proj1, Proj2> I1 ranges::find_first_of(Ep&& exec, I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); template<execution-policy Ep, sized-random-access-range R1, sized-random-access-range R2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires indirectly_comparable<iterator_t, 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

#

Let E be:

*i == *j for the overloads with no parameter pred;

pred(*i, *j) != false for the overloads with a parameter pred and no parameter proj1;

bool(invoke(pred, invoke(proj1, *i), invoke(proj2, *j))) for the overloads with parameters pred and proj1.

2

#

Effects: Finds an element that matches one of a set of values.

3

#

Returns: The first iterator i in the range [first1, last1) such that for some iterator j in the range [first2, last2)E holds.

Returns last1 if [first2, last2) is empty or if no such iterator is found.

4

#

Complexity: At most (last1 - first1) * (last2 - first2) applications of the corresponding predicate and any projections.

26.6.10 Adjacent find [alg.adjacent.find]

🔗

`template constexpr ForwardIterator adjacent_find(ForwardIterator first, ForwardIterator last); template<class ExecutionPolicy, class ForwardIterator> ForwardIterator adjacent_find(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last);

template<class ForwardIterator, class BinaryPredicate> constexpr ForwardIterator adjacent_find(ForwardIterator first, ForwardIterator last, BinaryPredicate pred); template<class ExecutionPolicy, class ForwardIterator, class BinaryPredicate> ForwardIterator adjacent_find(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, BinaryPredicate pred);

template<forward_iterator I, sentinel_for S, class Proj = identity, indirect_binary_predicate<projected<I, Proj>, projected<I, Proj>> Pred = ranges::equal_to> constexpr I ranges::adjacent_find(I first, S last, Pred pred = {}, Proj proj = {}); template<forward_range R, class Proj = identity, indirect_binary_predicate<projected<iterator_t, Proj>, projected<iterator_t, Proj>> Pred = ranges::equal_to> constexpr borrowed_iterator_t ranges::adjacent_find(R&& r, Pred pred = {}, Proj proj = {});

template<execution-policy Ep, random_access_iterator I, sized_sentinel_for S, class Proj = identity, indirect_binary_predicate<projected<I, Proj>, projected<I, Proj>> Pred = ranges::equal_to> I ranges::adjacent_find(Ep&& exec, I first, S last, Pred pred = {}, Proj proj = {}); template<execution-policy Ep, sized-random-access-range R, class Proj = identity, indirect_binary_predicate<projected<iterator_t, Proj>, projected<iterator_t, Proj>> Pred = ranges::equal_to> borrowed_iterator_t ranges::adjacent_find(Ep&& exec, R&& r, Pred pred = {}, Proj proj = {}); `

1

#

Let E be:

*i == *(i + 1) for the overloads with no parameter pred;

pred(*i, *(i + 1)) != false for the overloads with a parameter pred and no parameter proj;

bool(invoke(pred, invoke(proj, *i), invoke(proj, *(i + 1)))) for the overloads with both parameters pred and proj.

2

#

Returns: The first iterator i such that both i and i + 1 are in the range [first, last) for which E holds.

Returns last if no such iterator is found.

3

#

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.

For the parallel algorithm overloads,O(last - first) applications of the corresponding predicate.

No more than twice as many applications of any projection.

26.6.11 Count [alg.count]

🔗

`template<class InputIterator, class T = iterator_traits::value_type> constexpr typename iterator_traits::difference_type count(InputIterator first, InputIterator last, const T& value); template<class ExecutionPolicy, class ForwardIterator, class T = iterator_traits::value_type> typename iterator_traits::difference_type count(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, const T& value);

template<class InputIterator, class Predicate> constexpr typename iterator_traits::difference_type count_if(InputIterator first, InputIterator last, Predicate pred); template<class ExecutionPolicy, class ForwardIterator, class Predicate> typename iterator_traits::difference_type count_if(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, Predicate pred);

template<input_iterator I, sentinel_for S, class Proj = identity, class T = projected_value_t<I, Proj>> requires indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*> constexpr iter_difference_t ranges::count(I first, S last, const T& value, Proj proj = {}); template<input_range R, class Proj = identity, class T = projected_value_t<iterator_t, Proj>> requires indirect_binary_predicate<ranges::equal_to, projected<iterator_t, Proj>, const T*> constexpr range_difference_t ranges::count(R&& r, const T& value, Proj proj = {});

template<execution-policy Ep, random_access_iterator I, sized_sentinel_for S, class Proj = identity, class T = projected_value_t<I, Proj>> requires indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*> iter_difference_t ranges::count(Ep&& exec, I first, S last, const T& value, Proj proj = {}); template<execution-policy Ep, sized-random-access-range R, class Proj = identity, class T = projected_value_t<iterator_t, Proj>> requires indirect_binary_predicate<ranges::equal_to, projected<iterator_t, Proj>, const T*> range_difference_t ranges::count(Ep&& exec, R&& r, const T& value, Proj proj = {});

template<input_iterator I, sentinel_for S, class Proj = identity, indirect_unary_predicate<projected<I, Proj>> Pred> constexpr iter_difference_t ranges::count_if(I first, S last, Pred pred, Proj proj = {}); template<input_range R, class Proj = identity, indirect_unary_predicate<projected<iterator_t, Proj>> Pred> constexpr range_difference_t ranges::count_if(R&& r, Pred pred, Proj proj = {});

template<execution-policy Ep, random_access_iterator I, sized_sentinel_for S, class Proj = identity, indirect_unary_predicate<projected<I, Proj>> Pred> iter_difference_t ranges::count_if(Ep&& exec, I first, S last, Pred pred, Proj proj = {}); template<execution-policy Ep, sized-random-access-range R, class Proj = identity, indirect_unary_predicate<projected<iterator_t, Proj>> Pred> range_difference_t ranges::count_if(Ep&& exec, R&& r, Pred pred, Proj proj = {}); `

1

#

Let E be:

*i == value for the overloads with no parameter pred or proj;

pred(*i) != false for the overloads with a parameter pred but no parameter proj;

invoke(proj, *i) == value for the overloads with a parameter proj but no parameter pred;

bool(invoke(pred, invoke(proj, *i))) for the overloads with both parameters proj and pred.

2

#

Effects: Returns the number of iterators i in the range [first, last) for which E holds.

3

#

Complexity: Exactly last - first applications of the corresponding predicate and any projection.

26.6.12 Mismatch [alg.mismatch]

🔗

`template<class InputIterator1, class InputIterator2> constexpr pair<InputIterator1, InputIterator2> mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2); template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2> pair<ForwardIterator1, ForwardIterator2> mismatch(ExecutionPolicy&& exec, ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2);

template<class InputIterator1, class InputIterator2, class BinaryPredicate> constexpr pair<InputIterator1, InputIterator2> mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, BinaryPredicate pred); template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class BinaryPredicate> pair<ForwardIterator1, ForwardIterator2> mismatch(ExecutionPolicy&& exec, ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, BinaryPredicate pred);

template<class InputIterator1, class InputIterator2> constexpr pair<InputIterator1, InputIterator2> mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2); template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2> pair<ForwardIterator1, ForwardIterator2> mismatch(ExecutionPolicy&& exec, ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2);

template<class InputIterator1, class InputIterator2, class BinaryPredicate> constexpr pair<InputIterator1, InputIterator2> mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, BinaryPredicate pred); template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class BinaryPredicate> pair<ForwardIterator1, ForwardIterator2> mismatch(ExecutionPolicy&& exec, ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred);

template<input_iterator I1, sentinel_for S1, input_iterator I2, sentinel_for S2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires indirectly_comparable<I1, I2, Pred, Proj1, Proj2> constexpr ranges::mismatch_result<I1, I2> ranges::mismatch(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); template<input_range R1, input_range R2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires indirectly_comparable<iterator_t, iterator_t, Pred, Proj1, Proj2> constexpr ranges::mismatch_result<borrowed_iterator_t, borrowed_iterator_t> ranges::mismatch(R1&& r1, R2&& r2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {});

template<execution-policy Ep, random_access_iterator I1, sized_sentinel_for S1, random_access_iterator I2, sized_sentinel_for S2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires indirectly_comparable<I1, I2, Pred, Proj1, Proj2> ranges::mismatch_result<I1, I2> ranges::mismatch(Ep&& exec, I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); template<execution-policy Ep, sized-random-access-range R1, sized-random-access-range R2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires indirectly_comparable<iterator_t, iterator_t, Pred, Proj1, Proj2> ranges::mismatch_result<borrowed_iterator_t, borrowed_iterator_t> ranges::mismatch(Ep&& exec, R1&& r1, R2&& r2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); `

1

#

Let last2 be first2 + (last1 - first1) for the overloads in namespace std with no parameter last2.

2

#

Let E be:

!(*(first1 + n) == *(first2 + n)) for the overloads with no parameter pred;

pred(*(first1 + n), *(first2 + n)) == false for the overloads with a parameter pred and no parameter proj1;

!invoke(pred, invoke(proj1, *(first1 + n)), invoke(proj2, *(first2 + n))) for the overloads with both parameters pred and proj1.

3

#

Let N be min(last1 - first1, last2 - first2).

4

#

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.

5

#

Complexity: At most N applications of the corresponding predicate and any projections.

26.6.13 Equal [alg.equal]

🔗

`template<class InputIterator1, class InputIterator2> constexpr bool equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2); template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2> bool equal(ExecutionPolicy&& exec, ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2);

template<class InputIterator1, class InputIterator2, class BinaryPredicate> constexpr bool equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, BinaryPredicate pred); template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class BinaryPredicate> bool equal(ExecutionPolicy&& exec, ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, BinaryPredicate pred);

template<class InputIterator1, class InputIterator2> constexpr bool equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2); template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2> bool equal(ExecutionPolicy&& exec, ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2);

template<class InputIterator1, class InputIterator2, class BinaryPredicate> constexpr bool equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, BinaryPredicate pred); template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class BinaryPredicate> bool equal(ExecutionPolicy&& exec, ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred);

template<input_iterator I1, sentinel_for S1, input_iterator I2, sentinel_for S2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires indirectly_comparable<I1, I2, Pred, Proj1, Proj2> constexpr bool ranges::equal(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); template<input_range R1, input_range R2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires indirectly_comparable<iterator_t, iterator_t, Pred, Proj1, Proj2> constexpr bool ranges::equal(R1&& r1, R2&& r2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {});

template<execution-policy Ep, random_access_iterator I1, sized_sentinel_for S1, random_access_iterator I2, sized_sentinel_for S2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires indirectly_comparable<I1, I2, Pred, Proj1, Proj2> bool ranges::equal(Ep&& exec, I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); template<execution-policy Ep, sized-random-access-range R1, sized-random-access-range R2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires indirectly_comparable<iterator_t, iterator_t, Pred, Proj1, Proj2> bool ranges::equal(Ep&& exec, R1&& r1, R2&& r2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); `

1

#

Let:

last2 be first2 + (last1 - first1) for the overloads in namespace std with no parameter last2;

pred be equal_to{} for the overloads with no parameter pred;

E be:

pred(*i, *(first2 + (i - first1))) for the overloads with no parameter proj1;

invoke(pred, invoke(proj1, *i), invoke(proj2, *(first2 + (i - first1)))) for the overloads with parameter proj1.

2

#

Returns: If last1 - first1 != last2 - first2, return false.

Otherwise return true if E holds for every iterator i in the range [first1, last1).

Otherwise, returns false.

3

#

Complexity: If

the types of first1, last1, first2, and last2 meet the Cpp17RandomAccessIterator requirements ([random.access.iterators]) and last1 - first1 != last2 - first2 for the overloads in namespace std;

the types of first1, last1, first2, and last2 pairwise model sized_sentinel_for ([iterator.concept.sizedsentinel]) and last1 - first1 != last2 - first2 for the first and third overloads in namespace ranges, or

R1 and R2 each model sized_range 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.

26.6.14 Is permutation [alg.is.permutation]

🔗

template<class ForwardIterator1, class ForwardIterator2> constexpr bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2); template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate> constexpr bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, BinaryPredicate pred); template<class ForwardIterator1, class ForwardIterator2> constexpr bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2); template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate> constexpr bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred);

1

#

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.

2

#

Mandates: ForwardIterator1 and ForwardIterator2 have the same value type.

3

#

Preconditions: The comparison function is an equivalence relation.

4

#

Returns: If last1 - first1 != last2 - first2, return false.

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.

5

#

Complexity: No applications of the corresponding predicate if ForwardIterator1 and ForwardIterator2 meet the requirements of random access iterators andlast1 - first1 != last2 - first2.

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.

🔗

template<[forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11Concept forward_­iterator[iterator.concept.forward]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I1> S1, [forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11Concept forward_­iterator[iterator.concept.forward]") I2, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I2> S2, class Proj1 = identity, class Proj2 = identity, [indirect_equivalence_relation](indirectcallable.indirectinvocable#concept:indirect_equivalence_relation "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<I1, Proj1>, projected<I2, Proj2>> 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.6Other range refinements[range.refinements]") R1, [forward_range](range.refinements#concept:forward_range "25.4.6Other range refinements[range.refinements]") R2, class Proj1 = identity, class Proj2 = identity, [indirect_equivalence_relation](indirectcallable.indirectinvocable#concept:indirect_equivalence_relation "24.3.6.3Indirect callables[indirectcallable.indirectinvocable]")<projected<iterator_t<R1>, Proj1>, projected<iterator_t<R2>, Proj2>> Pred = ranges::equal_to> constexpr bool ranges::is_permutation(R1&& r1, R2&& r2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {});

6

#

Returns: If last1 - first1 != last2 - first2, return false.

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.

7

#

Complexity: No applications of the corresponding predicate and projections if

for the first overload,

S1 and I1 model sized_sentinel_for<S1, I1>,

S2 and I2 model sized_sentinel_for<S2, I2>, and

last1 - first1 != last2 - first2;

for the second overload,R1 and R2 each model sized_range, andranges::distance(r1) != ranges::distance(r2).

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.

26.6.15 Search [alg.search]

🔗

`template<class ForwardIterator1, class ForwardIterator2> constexpr ForwardIterator1 search(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2); template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2> ForwardIterator1 search(ExecutionPolicy&& exec, ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2);

template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate> constexpr ForwardIterator1 search(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred); template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class BinaryPredicate> ForwardIterator1 search(ExecutionPolicy&& exec, ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred); `

1

#

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.

Returns first1 if [first2, last2) is empty, otherwise returns last1 if no such iterator is found.

2

#

Complexity: At most (last1 - first1) * (last2 - first2) applications of the corresponding predicate.

🔗

`template<forward_iterator I1, sentinel_for S1, forward_iterator I2, sentinel_for S2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires indirectly_comparable<I1, I2, Pred, Proj1, Proj2> constexpr subrange ranges::search(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); template<forward_range R1, forward_range R2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires indirectly_comparable<iterator_t, iterator_t, Pred, Proj1, Proj2> constexpr borrowed_subrange_t ranges::search(R1&& r1, R2&& r2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {});

template<execution-policy Ep, random_access_iterator I1, sized_sentinel_for S1, random_access_iterator I2, sized_sentinel_for S2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires indirectly_comparable<I1, I2, Pred, Proj1, Proj2> subrange ranges::search(Ep&& exec, I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); template<execution-policy Ep, sized-random-access-range R1, sized-random-access-range R2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires indirectly_comparable<iterator_t, iterator_t, Pred, Proj1, Proj2> borrowed_subrange_t ranges::search(Ep&& exec, R1&& r1, R2&& r2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}); `

3

#

Returns:

{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.

Returns {last1, last1} if no such iterator exists.

4

#

Complexity: At most (last1 - first1) * (last2 - first2) applications of the corresponding predicate and projections.

🔗

`template<class ForwardIterator, class Size, class T = iterator_traits::value_type> constexpr ForwardIterator search_n(ForwardIterator first, ForwardIterator last, Size count, const T& value); template<class ExecutionPolicy, class ForwardIterator, class Size, class T = iterator_traits::value_type> ForwardIterator search_n(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, Size count, const T& value);

template<class ForwardIterator, class Size, class T = iterator_traits::value_type, class BinaryPredicate> constexpr ForwardIterator search_n(ForwardIterator first, ForwardIterator last, Size count, const T& value, BinaryPredicate pred); template<class ExecutionPolicy, class ForwardIterator, class Size, class T = iterator_traits::value_type, class BinaryPredicate> ForwardIterator search_n(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, Size count, const T& value, BinaryPredicate pred); `

5

#

Mandates: The type Size is convertible to an integral type ([conv.integral], [class.conv]).

6

#

Let E be pred(*(i + n), value) != false for the overloads with a parameter pred, and *(i + n) == value otherwise.

7

#

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.

Returns last if no such iterator is found.

8

#

Complexity: At most last - first applications of the corresponding predicate.

🔗

`template<forward_iterator I, sentinel_for S, class Pred = ranges::equal_to, class Proj = identity, class T = projected_value_t<I, Proj>> requires indirectly_comparable<I, const T*, Pred, Proj> constexpr subrange ranges::search_n(I first, S last, iter_difference_t count, const T& value, Pred pred = {}, Proj proj = {}); template<forward_range R, class Pred = ranges::equal_to, class Proj = identity, class T = projected_value_t<iterator_t, Proj>> requires indirectly_comparable<iterator_t, 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 Ep, random_access_iterator I, sized_sentinel_for S, class Pred = ranges::equal_to, class Proj = identity, class T = projected_value_t<I, Proj>> requires indirectly_comparable<I, const T*, Pred, Proj> subrange ranges::search_n(Ep&& exec, I first, S last, iter_difference_t count, const T& value, Pred pred = {}, Proj proj = {}); template<execution-policy Ep, sized-random-access-range R, class Pred = ranges::equal_to, class Proj = identity, class T = projected_value_t<iterator_t, Proj>> requires indirectly_comparable<iterator_t, 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

#

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).

Returns {last, last} if no such iterator is found.

10

#

Complexity: At most last - first applications of the corresponding predicate and projection.

🔗

template<class ForwardIterator, class Searcher> constexpr ForwardIterator search(ForwardIterator first, ForwardIterator last, const Searcher& searcher);

11

#

Effects: Equivalent to: return searcher(first, last).first;

12

#

Remarks: Searcher need not meet the Cpp17CopyConstructible requirements.

26.6.16 Starts with [alg.starts.with]

🔗

template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I1> S1, [input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I2, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I2> 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.5Concept indirectly_­comparable[alg.req.ind.cmp]")<I1, I2, Pred, Proj1, Proj2> 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.6Other range refinements[range.refinements]") R1, [input_range](range.refinements#concept:input_range "25.4.6Other 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.5Concept indirectly_­comparable[alg.req.ind.cmp]")<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2> constexpr bool ranges::starts_with(R1&& r1, R2&& r2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {});

1

#

Returns: ranges::mismatch(std::move(first1), last1, std::move(first2), last2, pred, proj1, proj2).in2 == last2

🔗

template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I1, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I1> S1, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I2, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I2> 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.5Concept indirectly_­comparable[alg.req.ind.cmp]")<I1, I2, Pred, Proj1, Proj2> 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.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R1, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other 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.5Concept indirectly_­comparable[alg.req.ind.cmp]")<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2> bool ranges::starts_with(Ep&& exec, R1&& r1, R2&& r2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {});

2

#

Returns: ranges::mismatch(std::forward(exec), std::move(first1), last1, std::move(first2), last2, pred, proj1, proj2).in2 == last2

26.6.17 Ends with [alg.ends.with]

🔗

template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I1, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I1> S1, [input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I2, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I2> S2, class Pred = ranges::equal_to, class Proj1 = identity, class Proj2 = identity> requires ([forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11Concept forward_­iterator[iterator.concept.forward]")<I1> || [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<S1, I1>) && ([forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11Concept forward_­iterator[iterator.concept.forward]")<I2> || [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<S2, I2>) && [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5Concept indirectly_­comparable[alg.req.ind.cmp]")<I1, I2, Pred, Proj1, Proj2> constexpr bool ranges::ends_with(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {});

1

#

Let N1 be last1 - first1 andN2 be last2 - first2.

2

#

Returns: false if N1 < N2, otherwise:ranges::equal(std::move(first1) + (N1 - N2), last1, std::move(first2), last2, pred, proj1, proj2)

🔗

template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I1, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I1> S1, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") I2, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<I2> 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.5Concept indirectly_­comparable[alg.req.ind.cmp]")<I1, I2, Pred, Proj1, Proj2> bool ranges::ends_with(Ep&& exec, I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {});

3

#

Let N1 be last1 - first1 andN2 be last2 - first2.

4

#

Returns: false if N1 < N2, otherwise:ranges::equal(std::forward(exec), std::move(first1) + (N1 - N2), last1, std::move(first2), last2, pred, proj1, proj2)

🔗

template<[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R1, [input_range](range.refinements#concept:input_range "25.4.6Other 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.6Other range refinements[range.refinements]")<R1> || [sized_range](range.sized#concept:sized_range "25.4.4Sized ranges[range.sized]")<R1>) && ([forward_range](range.refinements#concept:forward_range "25.4.6Other range refinements[range.refinements]")<R2> || [sized_range](range.sized#concept:sized_range "25.4.4Sized ranges[range.sized]")<R2>) && [indirectly_comparable](alg.req.ind.cmp#concept:indirectly_comparable "24.3.7.5Concept indirectly_­comparable[alg.req.ind.cmp]")<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2> constexpr bool ranges::ends_with(R1&& r1, R2&& r2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {});

5

#

Let N1 be ranges::distance(r1) andN2 be ranges::distance(r2).

6

#

Returns: false if N1 < N2, otherwise:ranges::equal(views::drop(ranges::ref_view(r1), N1 - static_cast<decltype(N1)>(N2)), r2, pred, proj1, proj2)

🔗

template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R1, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other 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.5Concept indirectly_­comparable[alg.req.ind.cmp]")<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2> bool ranges::ends_with(Ep&& exec, R1&& r1, R2&& r2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {});

7

#

Let N1 be ranges::distance(r1) andN2 be ranges::distance(r2).

8

#

Returns: false if N1 < N2, otherwise:ranges::equal(std::forward(exec), views::drop(ranges::ref_view(r1), N1 - static_cast<decltype(N1)>(N2)), r2, pred, proj1, proj2)

26.6.18 Fold [alg.fold]

🔗

template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class T = iter_value_t<I>, [indirectly-binary-left-foldable](algorithm.syn#concept:indirectly-binary-left-foldable "26.4Header <algorithm> synopsis[algorithm.syn]")<T, I> F> constexpr auto ranges::fold_left(I first, S last, T init, F f); template<[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R, class T = range_value_t<R>, [indirectly-binary-left-foldable](algorithm.syn#concept:indirectly-binary-left-foldable "26.4Header <algorithm> synopsis[algorithm.syn]")<T, iterator_t<R>> F> constexpr auto ranges::fold_left(R&& r, T init, F f);

1

#

Returns: ranges::fold_left_with_iter(std::move(first), last, std::move(init), f).value

🔗

template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, [indirectly-binary-left-foldable](algorithm.syn#concept:indirectly-binary-left-foldable "26.4Header <algorithm> synopsis[algorithm.syn]")<iter_value_t<I>, I> F> requires [constructible_from](concept.constructible#concept:constructible_from "18.4.11Concept constructible_­from[concept.constructible]")<iter_value_t<I>, iter_reference_t<I>> constexpr auto ranges::fold_left_first(I first, S last, F f); template<[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R, [indirectly-binary-left-foldable](algorithm.syn#concept:indirectly-binary-left-foldable "26.4Header <algorithm> synopsis[algorithm.syn]")<range_value_t<R>, iterator_t<R>> F> requires [constructible_from](concept.constructible#concept:constructible_from "18.4.11Concept constructible_­from[concept.constructible]")<range_value_t<R>, range_reference_t<R>> constexpr auto ranges::fold_left_first(R&& r, F f);

2

#

Returns: ranges::fold_left_first_with_iter(std::move(first), last, f).value

🔗

template<[bidirectional_iterator](iterator.concept.bidir#concept:bidirectional_iterator "24.3.4.12Concept bidirectional_­iterator[iterator.concept.bidir]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class T = iter_value_t<I>, [indirectly-binary-right-foldable](algorithm.syn#concept:indirectly-binary-right-foldable "26.4Header <algorithm> synopsis[algorithm.syn]")<T, I> F> constexpr auto ranges::fold_right(I first, S last, T init, F f); template<[bidirectional_range](range.refinements#concept:bidirectional_range "25.4.6Other range refinements[range.refinements]") R, class T = range_value_t<R>, [indirectly-binary-right-foldable](algorithm.syn#concept:indirectly-binary-right-foldable "26.4Header <algorithm> synopsis[algorithm.syn]")<T, iterator_t<R>> F> constexpr auto ranges::fold_right(R&& r, T init, F f);

3

#

Effects: Equivalent to:using U = decay_t<invoke_result_t<F&, iter_reference_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;

🔗

template<[bidirectional_iterator](iterator.concept.bidir#concept:bidirectional_iterator "24.3.4.12Concept bidirectional_­iterator[iterator.concept.bidir]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, [indirectly-binary-right-foldable](algorithm.syn#concept:indirectly-binary-right-foldable "26.4Header <algorithm> synopsis[algorithm.syn]")<iter_value_t<I>, I> F> requires [constructible_from](concept.constructible#concept:constructible_from "18.4.11Concept constructible_­from[concept.constructible]")<iter_value_t<I>, iter_reference_t<I>> constexpr auto ranges::fold_right_last(I first, S last, F f); template<[bidirectional_range](range.refinements#concept:bidirectional_range "25.4.6Other range refinements[range.refinements]") R, [indirectly-binary-right-foldable](algorithm.syn#concept:indirectly-binary-right-foldable "26.4Header <algorithm> synopsis[algorithm.syn]")<range_value_t<R>, iterator_t<R>> F> requires [constructible_from](concept.constructible#concept:constructible_from "18.4.11Concept constructible_­from[concept.constructible]")<range_value_t<R>, range_reference_t<R>> constexpr auto ranges::fold_right_last(R&& r, F f);

4

#

Let U bedecltype(ranges::fold_right(first, last, iter_value_t(*first), f)).

5

#

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)));

🔗

template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, class T = iter_value_t<I>, [indirectly-binary-left-foldable](algorithm.syn#concept:indirectly-binary-left-foldable "26.4Header <algorithm> synopsis[algorithm.syn]")<T, I> 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.6Other range refinements[range.refinements]") R, class T = range_value_t<R>, [indirectly-binary-left-foldable](algorithm.syn#concept:indirectly-binary-left-foldable "26.4Header <algorithm> synopsis[algorithm.syn]")<T, iterator_t<R>> F> constexpr see below ranges::fold_left_with_iter(R&& r, T init, F f);

6

#

Let U be decay_t<invoke_result_t<F&, T, iter_reference_t>>.

7

#

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

#

Remarks: The return type isfold_left_with_iter_result<I, U> for the first overload andfold_left_with_iter_result<borrowed_iterator_t, U> for the second overload.

🔗

template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9Concept input_­iterator[iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<I> S, [indirectly-binary-left-foldable](algorithm.syn#concept:indirectly-binary-left-foldable "26.4Header <algorithm> synopsis[algorithm.syn]")<iter_value_t<I>, I> F> requires [constructible_from](concept.constructible#concept:constructible_from "18.4.11Concept constructible_­from[concept.constructible]")<iter_value_t<I>, iter_reference_t<I>> 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.6Other range refinements[range.refinements]") R, [indirectly-binary-left-foldable](algorithm.syn#concept:indirectly-binary-left-foldable "26.4Header <algorithm> synopsis[algorithm.syn]")<range_value_t<R>, iterator_t<R>> F> requires [constructible_from](concept.constructible#concept:constructible_from "18.4.11Concept constructible_­from[concept.constructible]")<range_value_t<R>, range_reference_t<R>> constexpr see below ranges::fold_left_first_with_iter(R&& r, F f);

9

#

Let U bedecltype(ranges::fold_left(std::move(first), last, iter_value_t(*first), f))

10

#

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

#

Remarks: The return type isfold_left_first_with_iter_result<I, optional> for the first overload andfold_left_first_with_iter_result<borrowed_iterator_t, optional> for the second overload.