...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 const& f);
Table 1.35. Parameters
Parameter |
Requirement |
Description |
---|---|---|
seq |
A model of Forward Sequence, f(e) must be a valid expression for each element e in seq |
Operation's argument |
f |
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 result_of::size<Sequence>::value applications of f.
#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));