iter_fold_backward
template<
typename Sequence
, typename State
, typename BackwardOp
, typename ForwardOp = _1
>
struct iter_fold_backward
{
typedef unspecified type;
};
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.
#include "boost/mpl/iter_fold_backward.hpp"
| Parameter | Requirement | Description | Default value |
|---|---|---|---|
Sequence | A model of Sequence | A sequence to iterate. | |
State | A type | The initial state for the first BackwardOp/ForwardOp application. | |
BackwardOp | A model of [Lambda Function] | The operation to be executed on backward traversal. | |
ForwardOp | A model of [Lambda Function] | The operation to be executed on forward traversal. | arg<1> |
| Expression | Expression type | Precondition | Semantics | Postcondition |
|---|---|---|---|---|
typedef iter_fold_backward< Sequence,T,BackwardOp >::type t; | A type | Equivalent 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 type | Equivalent to typedef iter_fold_backward<Sequence, iter_fold<Sequence,State,ForwardOp>::type, BackwardOp>::type t;. |
Linear. Exactly size<Sequence>::type::value applications of BackwardOp and ForwardOp.
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_c<0> >, push_front<_1,_2>, _1 >
>::type iters;
BOOST_STATIC_ASSERT(equal< negatives, transform_view< iters,deref<_> >, equal_to<_,_> >::type::value);
Algorithms, iter_fold, fold_backward, fold, copy, copy_backward