for_each
Performs an operation for each element
Definition
The for_each() algorithm is defined in the standard header <algorithm>, and in the nonstandard backward-compatibility header <algo.h>.
Interface
#include <algorithm>
template < class InputIterator, class Function>
Function for_each (
InputIterator first,
InputIterator last,
Function f
);Parameters:
| Parameter | Description |
| first | An input iterator addressing the position of the first element in the range to be operated on |
| last | An input iterator addressing the position one past the final element in the range operated on |
| f | User-defined function object that is applied to each element in the range |
Description
The for_each() algorithm applies a specified function object to each element in a forward order within a range.
Return Value
Returns the function object.
Complexity
The complexity is linear, performing exactly (last - first) applications of f.
CodeCogs®