...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
Applies a unary function object to each element of a sequence.
template<
typename Sequence,
typename F
>
typename result_of::for_each
<Sequence, F>::type for_each(
Sequence& seq, F f);
Table 1.43. Parameters
Parameter |
Requirement |
Description |
---|---|---|
|
A model of Forward
Sequence, |
Operation's argument |
|
A unary Regular Callable Object |
Operation's argument |
for_each
(seq, f);
Return type: void
Semantics: Calls f(e)
for each element e
in seq
.
Linear, exactly
applications of result_of::size
<Sequence>::valuef
.
#include <boost/fusion/algorithm/iteration/for_each.hpp> #include <boost/fusion/include/for_each.hpp>
struct increment { template<typename T> void operator()(T& t) const { ++t; } }; ...vector
<int,int> vec(1,2);for_each
(vec, increment()); assert(vec ==make_vector
(2,3));