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

for_each()

Library:  Algorithms


Function

Local Index

No Entries

Summary

Algorithm that applies a function to each element in a range

Synopsis

#include <algorithm>

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

Description

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.

Complexity

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

Example

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