Declaration
template <class InputIterator, class Function> void for_each(InputIterator first, InputIterator last, Function f);
Description The for_each function applies the function object f to the dereferencing of each iterator in the range [ first, last) .
Type requirements
Group Non-mutating sequence operations.
Time complexity Linear.
If n is the size of the range [ first, last) , then exactly n applications of f are made.
Space complexity Constant.
Mutative? Yes.
Details The function object f is assumed not to apply any non-constant function through the dereferenced iterator.
Glossary terms constant space, dereference type, dereferencing an iterator, Function, function object, function object type, InputIterator, iterator, linear time, mutative, non-constant function, range, sequence.
Example Select here to view the source code for the example.
Implementation Select here to view source code (Copyright (C) 1994, Hewlett-Packard Company) for this algorithm.
Implementation notes If f returns a result, that result is ignored.