Boost C++ Libraries of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of boost. Click here for the latest Boost documentation.



      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  
SequenceA model of SequenceA sequence to iterate.
StateA typeThe initial state for the first ForwardOp application.
ForwardOpA model of [Lambda Function]The operation to be executed on forward traversal.

Expression semantics

 Expression  Expression type  Precondition  Semantics  Postcondition 
typedef fold<Sequence,T,Op>::type t;A typeEquivalent 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<
    , integral_c<long, 0>
    , if_< is_float<_2>,next<_1>,_1 >
    >::type number_of_floats;

BOOST_STATIC_ASSERT(number_of_floats::value == 4);

See also

Algorithms, fold_backward, iter_fold, iter_fold_backward, copy, copy_if

Table of Contents
Last edited December 12, 2002 4:42 pm