Back to Arangodb

fold

3rdParty/boost/1.78.0/libs/mpl/doc/refmanual/fold.html

3.12.9.13.1 KB
Original Source

| Prev Next | Back Along | Up Home | Full TOC | Front Page / Algorithms / Iteration Algorithms / fold |

fold

Synopsis

template<
      typename Sequence
    , typename State
    , typename ForwardOp
    >
struct[fold](./fold.html){
    typedef_unspecified_type;
};

Description

Returns the result of the successive application of binary ForwardOp to the result of the previous ForwardOp invocation (State if it's the first call) and every element of the sequence in the range [begin<Sequence>::type, end<Sequence>::type) in order.

#include <[boost/mpl/fold.hpp](../../../../boost/mpl/fold.hpp)>

Parameters

ParameterRequirementDescription
SequenceForward SequenceA sequence to iterate.
StateAny typeThe initial state for the first ForwardOp application.
ForwardOpBinary Lambda ExpressionThe operation to be executed on forward traversal.

Expression semantics

For any Forward Sequence s, binary Lambda Expression op, and arbitrary type state:

typedef[fold](./fold.html)<s,state,op>::type t;

| Return type: |

A type.

| | Semantics: |

Equivalent to

typedef[iter\_fold](./iter-fold.html)<
      s
    , state
    , apply_wrap2<[lambda](./lambda.html)<op>::type,[\_1](./placeholders.html),[deref](./deref.html)<[\_2](./placeholders.html)> >
    >::type t;

|

Complexity

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

Example

typedef[vector](./vector.html)<long,float,short,double,float,long,long double> types;
typedef[fold](./fold.html)<
      types
    ,[int\_](./int.html)<0>
    ,[if\_](./if.html)< is_float<[\_2](./placeholders.html)>,[next](./next.html)<[\_1](./placeholders.html)>,[\_1](./placeholders.html)>
    >::type number_of_floats;[BOOST\_MPL\_ASSERT\_RELATION](./assert-relation.html)( number_of_floats::value, ==, 4 );

See also

Algorithms, accumulate, reverse_fold, iter_fold, reverse_iter_fold, copy, copy_if

| 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) |