Back to Arangodb

for_each

3rdParty/boost/1.78.0/libs/mpl/doc/refmanual/for-each.html

3.12.9.13.8 KB
Original Source

| Prev Next | Back Along | Up Home | Full TOC | Front Page / Algorithms / Runtime Algorithms / for_each |

for_each

Synopsis

template<
      typename Sequence
    , typename F
    >
void[for\_each](./for-each.html)( F f );

template<
      typename Sequence
    , typename TransformOp
    , typename F
    >
void[for\_each](./for-each.html)( F f );

Description

for_each is a family of overloaded function templates:

  • for_each<Sequence>( f ) applies the runtime function object f to every element in the [begin<Sequence>::type, end<Sequence>::type) range.
  • for_each<Sequence,TransformOp>( f ) applies the runtime function object f to the result of the transformation TransformOp of every element in the [begin<Sequence>::type, end<Sequence>::type) range.
#include <[boost/mpl/for\_each.hpp](../../../../boost/mpl/for_each.hpp)>

Parameters

ParameterRequirementDescription
SequenceForward SequenceA sequence to iterate.
TransformOpLambda ExpressionA transformation.
fAn unary function objectA runtime operation to apply.

Expression semantics

For any Forward Sequence s, Lambda Expression op , and an unary function object f:

[for\_each](./for-each.html)<s>( f );

| Return type: |

void

| | Postcondition: |

Equivalent to

typedef[begin](./begin.html)<Sequence>::type i1;[value\_initialized](http://www.boost.org/libs/utility/value_init.htm)<[deref](./deref.html)<i1>::type > x1;
f(boost::get(x1));

typedef[next](./next.html)<i1>::type i2;[value\_initialized](http://www.boost.org/libs/utility/value_init.htm)<[deref](./deref.html)<i2>::type > x2;
f(boost::get(x2));_..._[value\_initialized](http://www.boost.org/libs/utility/value_init.htm)<[deref](./deref.html)<in>::type > xn;
f(boost::get(xn));
typedef[next](./next.html)<in>::type last;

where n == size<s>::value and last is identical to end<s>::type; no effect if empty<s>::value == true.

|

[for\_each](./for-each.html)<s,op>( f );

| Return type: |

void

| | Postcondition: |

Equivalent to

[for\_each](./for-each.html)<[transform\_view](./transform-view.html)<s,op> >( f );

|

Complexity

Linear. Exactly size<s>::value applications of op and f.

Example

struct value_printer
{
    template< typename U > void operator()(U x)
    {
        std::cout << x << '\n';
    }
};

int main()
{[for\_each](./for-each.html)<[range\_c](./range-c.html)<int,0,10> >( value_printer() );
}

See also

Runtime Algorithms, Views, transform_view

| Prev Next | Back Along | Up Home | Full TOC |

Copyright © 2001-2009 Aleksey Gurtovoy and David Abrahams Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |