Boost C++ Libraries

...one 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.

[Home]iter_fold_backward

Synopsis

template<
      typename Sequence
    , typename State
    , typename BackwardOp
    , typename ForwardOp = _1
    >
struct iter_fold_backward
{
    typedef unspecified type;
};

Description

Returns the result of the successive application of binary BackwardOp to the result of the previous BackwardOp invocation (State if it's the first call) and each iterator in the range [begin<Sequence>::type,end<Sequence>::type) in the reverse order. If ForwardOp is provided, then it's applied on forward traversal to form the result which is passed to the first BackwardOp call.

Definition

#include "boost/mpl/iter_fold_backward.hpp"

Parameters

 Parameter  Requirement  Description  Default value  
SequenceA model of SequenceA sequence to iterate.
StateA typeThe initial state for the first BackwardOp/ForwardOp application.
BackwardOpA model of [Lambda Function]The operation to be executed on backward traversal.
ForwardOpA model of [Lambda Function]The operation to be executed on forward traversal.arg<1>

Expression semantics

 Expression  Expression type  Precondition  Semantics  Postcondition 
typedef iter_fold_backward< Sequence,T,BackwardOp >::type t;A typeEquivalent to typedef lambda<BackwardOp>::type bk_op; typedef begin<Sequence>::type i1; typedef i1::next i2; ...; typedef in::next last; typedef apply<bk_op,T,in>::type tn; typedef apply<bk_op,tn,in-1>::type tn-1; ...; typedef apply<bk_op,t2,i1>::type t1; typedef t1 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.
typedef iter_fold_backward< Sequence,T,BackwardOp,ForwardOp >::type t;A typeEquivalent to typedef iter_fold_backward<Sequence, iter_fold<Sequence,State,ForwardOp>::type, BackwardOp>::type t;.

Complexity

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

Example

Builds a list of iterators to the negative elements in a sequence.

typedef vector_c<int,5,-1,0,-7,-2,0,-5,4> numbers;
typedef list_c<int,-1,-7,-2,-5> negatives;
typedef iter_fold_backward<
      numbers
    , list<>
    , if_< less< deref<_2>,int_<0> >, push_front<_1,_2>, _1 >
    >::type iters;

BOOST_STATIC_ASSERT(equal< negatives, transform_view< iters,deref<_1> > >::type::value);

See also

Algorithms, iter_fold, fold_backward, fold, copy, copy_backward


Table of Contents
Last edited March 12, 2003 6:31 am