fold
template<
typename Sequence
, typename State
, typename ForwardOp
>
struct fold
{
typedef unspecified type;
};
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 the linear order.
#include "boost/mpl/fold.hpp"
| Parameter | Requirement | Description |
|---|---|---|
Sequence | A model of Sequence | A sequence to iterate. |
State | A type | The initial state for the first ForwardOp application. |
ForwardOp | A model of [Lambda Function] | The operation to be executed on forward traversal. |
| Expression | Expression type | Precondition | Semantics | Postcondition |
|---|---|---|---|---|
typedef fold<Sequence,T,Op>::type t; | A type | Equivalent to typedef lambda<Op>::type op; typedef iter_fold< Sequence,T,apply<op,_1,deref<_2> > >::type t;. |
Linear. Exactly size<Sequence>::type::value applications of ForwardOp.
typedef vector<long,float,short,double,float,long,long double> types;
typedef typename fold<
types
, integral_c<long, 0>
, if_< is_float<_2>,next<_1>,_1 >
>::type number_of_floats;
BOOST_STATIC_ASSERT(number_of_floats::value == 3);
Algorithms, fold_backward, iter_fold, iter_fold_backward, copy, copy_if