Back to Arangodb

reverse_fold

3rdParty/boost/1.78.0/libs/mpl/doc/refmanual/reverse-fold.html

3.12.9.14.1 KB
Original Source

| Prev Next | Back Along | Up Home | Full TOC | Front Page / Algorithms / Iteration Algorithms / reverse_fold |

reverse_fold

Synopsis

template<
      typename Sequence
    , typename State
    , typename BackwardOp
    , typename ForwardOp =[\_1](./placeholders.html)>
struct[reverse\_fold](./reverse-fold.html){
    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 every element in the range [begin<Sequence>::type, end<Sequence>::type) in reverse order. If ForwardOp is provided, then it is applied on forward traversal to form the result that is passed to the first BackwardOp call.

#include <[boost/mpl/reverse\_fold.hpp](../../../../boost/mpl/reverse_fold.hpp)>

Parameters

Parameters

ParameterRequirementDescription
SequenceForward SequenceA sequence to iterate.
StateAny typeThe initial state for the first BackwardOp / ForwardOp application.
BackwardOpBinary Lambda ExpressionThe operation to be executed on backward traversal.
ForwardOpBinary Lambda ExpressionThe operation to be executed on forward traversal.

Expression semantics

For any Forward Sequence s, binary Lambda Expression backward_op and forward_op, and arbitrary type state:

typedef[reverse\_fold](./reverse-fold.html)< s,state,backward_op >::type t;

| Return type: |

A type

| | Semantics: |

Equivalent to

typedef[lambda](./lambda.html)<backward_op>::type op;
typedef[reverse\_iter\_fold](./reverse-iter-fold.html)<
      s
    , state
    , apply_wrap2< op,[\_1](./placeholders.html),[deref](./deref.html)<[\_2](./placeholders.html)> >
    >::type t;

|

typedef[reverse\_fold](./reverse-fold.html)< s,state,backward_op,forward_op >::type t;

| Return type: |

A type.

| | Semantics: |

Equivalent to

typedef[reverse\_fold](./reverse-fold.html)<
      Sequence
    ,[fold](./fold.html)<s,state,forward_op>::type
    , backward_op
    >::type t;

|

Complexity

Linear. Exactly size<s>::value applications of backward_op and forward_op.

Example

Remove non-negative elements from a sequence [2].

typedef[list\_c](./list-c.html)<int,5,-1,0,-7,-2,0,-5,4> numbers;
typedef[list\_c](./list-c.html)<int,-1,-7,-2,-5> negatives;
typedef[reverse\_fold](./reverse-fold.html)<
      numbers
    ,[list\_c](./list-c.html)<int>
    ,[if\_](./if.html)<[less](./less.html)<[\_2](./placeholders.html),[int\_](./int.html)<0> >,[push\_front](./push-front.html)<[\_1](./placeholders.html),[\_2](./placeholders.html),>,[\_1](./placeholders.html)>
    >::type result;[BOOST\_MPL\_ASSERT](./assert.html)(([equal](./equal.html)< negatives,result > ));

| [2] | See remove_if for a more compact way to do this. |

See also

Algorithms, fold, reverse_iter_fold, iter_fold

| Prev Next | Back Along | Up Home | Full TOC |

Copyright © 2001-2009 Aleksey Gurtovoy and David Abrahams Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |