1 .. Algorithms/Runtime Algorithms//for_each |10
19 , typename TransformOp
28 ``for_each`` is a family of overloaded function templates:
30 * ``for_each<Sequence>( f )`` applies the runtime function object
31 ``f`` to every element in the |begin/end<Sequence>| range.
33 * ``for_each<Sequence,TransformOp>( f )`` applies the runtime function
34 object ``f`` to the result of the transformation ``TransformOp`` of
35 every element in the |begin/end<Sequence>| range.
43 #include <boost/mpl/for_each.hpp>
49 +-------------------+-----------------------------------+-----------------------------------+
50 | Parameter | Requirement | Description |
51 +===================+===================================+===================================+
52 | ``Sequence`` | |Forward Sequence| | A sequence to iterate. |
53 +-------------------+-----------------------------------+-----------------------------------+
54 | ``TransformOp`` | |Lambda Expression| | A transformation. |
55 +-------------------+-----------------------------------+-----------------------------------+
56 | ``f`` | An |unary function object| | A runtime operation to apply. |
57 +-------------------+-----------------------------------+-----------------------------------+
63 For any |Forward Sequence| ``s``, |Lambda Expression| ``op`` , and an
64 |unary function object| ``f``:
78 typedef begin<Sequence>::type i\ :sub:`1`;
79 |value_initialized|\ < deref<i\ :sub:`1`>::type > x\ :sub:`1`;
80 f(boost::get(x\ :sub:`1`));
82 typedef next<i\ :sub:`1`>::type i\ :sub:`2`;
83 |value_initialized|\ < deref<i\ :sub:`2`>::type > x\ :sub:`2`;
84 f(boost::get(x\ :sub:`2`));
86 |value_initialized|\ < deref<i\ :sub:`n`>::type > x\ :sub:`n`;
87 f(boost::get(x\ :sub:`n`));
88 typedef next<i\ :sub:`n`>::type last;
90 where ``n == size<s>::value`` and ``last`` is identical to
91 ``end<s>::type``; no effect if ``empty<s>::value == true``.
106 for_each< transform_view<s,op> >( f );
112 Linear. Exactly ``size<s>::value`` applications of ``op`` and ``f``.
122 template< typename U > void operator()(U x)
124 std::cout << x << '\\n';
130 for_each< range_c<int,0,10> >( value_printer() );
137 |Runtime Algorithms|, |Views|, |transform_view|
139 .. |unary function object| replace:: `unary function object <http://www.sgi.com/tech/stl/UnaryFunction.html>`__
140 .. |value_initialized| replace:: `value_initialized <http://www.boost.org/libs/utility/value_init.htm>`__
143 .. copyright:: Copyright © 2001-2009 Aleksey Gurtovoy and David Abrahams
144 Distributed under the Boost Software License, Version 1.0. (See accompanying
145 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)