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 an old version of boost. Click here for the latest version's documentation home page.



      typename Sequence
    , typename State
    , typename ForwardOp
struct iter_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 each iterator in the range [begin<Sequence>::type,end<Sequence>::type) in the linear order.


#include "boost/mpl/iter_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 iter_fold<Sequence,T,Op>::type t;A typeEquivalent to typedef lambda<Op>::type op; typedef begin<Sequence>::type i1; typedef apply<op,T,i1>::type t1; typedef i1::next i2; typedef apply<op,t1,i2>::type t2; ...; typedef apply<op,T,in>::type tn; typedef in::next last; typedef tn t, where n == size<Sequence>::type::value and last is identical to end<Sequence>::type; Equivalent to typedef T t; if the sequence is empty.


Linear. Exactly size<Sequence>::type::value applications of ForwardOp.


typedef list_c<int,5,-1,0,7,2,0,-5,4> numbers;
typedef iter_fold<
    , begin<numbers>::type
    , if_< less< deref<_1>, deref<_2> >,_2,_1 >
    >::type max_element_iter;

BOOST_STATIC_ASSERT(max_element_iter::type::value == 7);

See also

Algorithms, iter_fold_backward, fold, fold_backward, copy, copy_backward

Table of Contents
Last edited July 19, 2002 1:16 am