Previous fileTop of DocumentContentsIndex pageNext file
Apache C++ Standard Library Reference Guide


Library:  Algorithms


Local Index

No Entries


Algorithm that applies a function to each element in a range


#include <algorithm>

namespace std {
  template <class InputIterator, class Function>
  void Function for_each(InputIterator start, 
                         InputIterator finish,
                         Function f);


The for_each() algorithm applies the function object f to each value in the range [start, finish), where start and finish are iterators that define the sequence. Since this a non-mutating algorithm, the function f cannot make any modifications to the sequence, but it can achieve results through side effects (such as copying or printing). If f returns a result, the result is ignored.

for_each() returns the function object f.


The function object f is applied exactly finish - start times.


See Also

Algorithms, Function Objects

Standards Conformance

ISO/IEC 14882:1998 -- International Standard for Information Systems -- Programming Language C++, Section 25.1.1

Previous fileTop of DocumentContentsIndex pageNext file