[alg.foreach] (original) (raw)
26 Algorithms library [algorithms]
26.6 Non-modifying sequence operations [alg.nonmodifying]
26.6.5 For each [alg.foreach]
template<class InputIterator, class Function> constexpr Function for_each(InputIterator first, InputIterator last, Function f);
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_]
Complexity: Applies f exactly last - first times.
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);
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_]
Complexity: Applies f exactly last - first times.
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.
[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%5Fiterator "24.3.4.9 Concept input_iterator [iterator.concept.input]") I, [sentinel_for](iterator.concept.sentinel#concept:sentinel%5Ffor "24.3.4.7 Concept sentinel_for [iterator.concept.sentinel]")<I> S, class Proj = identity,[indirectly_unary_invocable](indirectcallable.indirectinvocable#concept:indirectly%5Funary%5Finvocable "24.3.6.3 Indirect 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%5Frange "25.4.6 Other range refinements [range.refinements]") R, class Proj = identity,[indirectly_unary_invocable](indirectcallable.indirectinvocable#concept:indirectly%5Funary%5Finvocable "24.3.6.3 Indirect 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 = {});
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_]
Returns: {last, std::move(f)}.
Complexity: Applies f and proj exactly last - first times.
Remarks: If f returns a result, the result is ignored.
[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.1 Preamble [algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random%5Faccess%5Fiterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]") I, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized%5Fsentinel%5Ffor "24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]")<I> S,class Proj = identity,[indirectly_unary_invocable](indirectcallable.indirectinvocable#concept:indirectly%5Funary%5Finvocable "24.3.6.3 Indirect 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.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%5Funary%5Finvocable "24.3.6.3 Indirect callables [indirectcallable.indirectinvocable]")<projected<iterator_t<R>, Proj>> Fun> borrowed_iterator_t<R> ranges::for_each(Ep&& exec, R&& r, Fun f, Proj proj = {});
Effects: Calls invoke(f, invoke(proj, *i))for every iterator iin 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_]
Complexity: Applies f and proj exactly last - first times.
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.
[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);
Preconditions: n >= 0 is true.
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_]
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);
Preconditions: n >= 0 is true.
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_]
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%5Fiterator "24.3.4.9 Concept input_iterator [iterator.concept.input]") I, class Proj = identity,[indirectly_unary_invocable](indirectcallable.indirectinvocable#concept:indirectly%5Funary%5Finvocable "24.3.6.3 Indirect 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 = {});
Preconditions: n >= 0 is true.
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_]
Returns: {first + n, std::move(f)}.
Remarks: If f returns a result, the result is ignored.
[Note 13:
The overload in namespace rangesrequires Fun to model copy_constructible.
— _end note_]
Preconditions: n >= 0 is true.
Effects: Calls invoke(f, invoke(proj, *i))for every iterator iin 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_]
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.
[Note 15:
Does not return a copy of its Fun parameter, since parallelization often does not permit efficient state accumulation.
— _end note_]