std::experimental::ranges::for_each
<experimental/ranges/algorithm>
IndirectUnaryInvocable<projected <I, Proj>> Fun >
ranges::tagged_pair <tag::in (I), tag::fun (Fun)>
IndirectUnaryInvocable<projected <ranges::iterator_t <R>, Proj>> Fun >
ranges::tagged_pair <tag::in (ranges::safe_iterator_t <R>), tag::fun (Fun)>
[
first,
last)
(i.e.,ranges::invoke (f, ranges::invoke (proj, *i))), in order. For both overloads, if the iterator type is mutable, f may modify the elements of the range through the dereferenced iterator. If f returns a result, the result is ignored.
Unlike the rest of the algorithms, for_each is not allowed to make copies of the elements in the sequence even if they are trivially copyable.
Unlike std::for_each (which requires only MoveConstructible), these functions require Fun
to model CopyConstructible
.
Notwithstanding the declarations depicted above, the actual number and order of template parameters for algorithm declarations is unspecified. Thus, if explicit template arguments are used when calling an algorithm, the program is probably non-portable.
[edit] Parameters
[edit] Return value
A tagged_pair
object containing the following two members:
- The first member, with the tag
tag::in
, is the past-the-end iterator of the source range (that is, an iterator of typeI
that compares equal to the sentinel last). - The second member, with the tag
tag::fun
, is initialized fromstd::move(f)
(after all applications of the function object).
[edit] Complexity
Exactly last - first applications of f and proj.
[edit] Possible implementation
template<InputIterator I, Sentinel<I> S, class Proj = ranges::identity, IndirectUnaryInvocable<ranges::projected <I, Proj>> Fun> auto for_each(I first, S last, Fun f, Proj proj = Proj{}) -> ranges::tagged_pair <tag::in (I), tag::fun (Fun)> { for (; first != last; ++first) ranges::invoke (f, ranges::invoke (proj, *first)); return {std::move(first), std::move(f)}; }
[edit] Example
Reason: no example