iter_fold_if
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.
Finds an iterator to the last negative element in the sequence.
typedef list_c<int,5,-1,0,7,2,0,-5,4> numbers;
typedef iter_fold_backward<
numbers
, end<numbers>::type
, if_< less< deref<_2>, int_c<0> >,_2,_1 >
>::type last_negative_iter;
BOOST_STATIC_ASSERT(last_negative_iter::type::value == -5);
Algorithms, iter_fold, fold_backward, fold, copy, copy_backward