1 .. Algorithms/Iteration Algorithms//reverse_iter_fold
15 , typename ForwardOp = _1
17 struct reverse_iter_fold
19 typedef |unspecified| type;
27 Returns the result of the successive application of binary ``BackwardOp`` to the
28 result of the previous ``BackwardOp`` invocation (``State`` if it's the first call)
29 and each iterator in the range [``begin<Sequence>::type``, ``end<Sequence>::type``)
30 in reverse order. If ``ForwardOp`` is provided, then it's applied on forward
31 traversal to form the result which is passed to the first ``BackwardOp`` call.
39 #include <boost/mpl/reverse_iter_fold.hpp>
46 +---------------+-------------------------------+-----------------------------------------------+
47 | Parameter | Requirement | Description |
48 +===============+===============================+===============================================+
49 | ``Sequence`` | |Forward Sequence| | A sequence to iterate. |
50 +---------------+-------------------------------+-----------------------------------------------+
51 | ``State`` | Any type | The initial state for the first ``BackwardOp``|
52 | | | / ``ForwardOp`` application. |
53 +---------------+-------------------------------+-----------------------------------------------+
54 | ``BackwardOp``| Binary |Lambda Expression| | The operation to be executed on backward |
56 +---------------+-------------------------------+-----------------------------------------------+
57 | ``ForwardOp`` | Binary |Lambda Expression| | The operation to be executed on forward |
59 +---------------+-------------------------------+-----------------------------------------------+
65 For any |Forward Sequence| ``s``, binary |Lambda Expression| ``backward_op`` and ``forward_op``,
66 and arbitrary type ``state``:
71 typedef reverse_iter_fold< s,state,backward_op >::type t;
81 typedef begin<s>::type i\ :sub:`1`;
82 typedef next<i\ :sub:`1`>::type i\ :sub:`2`;
84 typedef next<i\ :sub:`n`>::type last;
85 typedef apply<backward_op,state,i\ :sub:`n`>::type state\ :sub:`n`;
86 typedef apply<backward_op,state\ :sub:`n`,i\ :sub:`n-1`>::type state\ :sub:`n-1`;
88 typedef apply<backward_op,state\ :sub:`2`,i\ :sub:`1`>::type state\ :sub:`1`;
89 typedef state\ :sub:`1` t;
91 where ``n == size<s>::value`` and ``last`` is identical to ``end<s>::type``; equivalent
92 to ``typedef state t;`` if ``empty<s>::value == true``.
95 .. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
100 typedef reverse_iter_fold< s,state,backward_op,forward_op >::type t;
110 typedef reverse_iter_fold<
112 , iter_fold<s,state,forward_op>::type
120 Linear. Exactly ``size<s>::value`` applications of ``backward_op`` and ``forward_op``.
126 Build a list of iterators to the negative elements in a sequence.
130 typedef vector_c<int,5,-1,0,-7,-2,0,-5,4> numbers;
131 typedef list_c<int,-1,-7,-2,-5> negatives;
132 typedef reverse_iter_fold<
135 , if_< less< deref<_2>,int_<0> >, push_front<_1,_2>, _1 >
138 BOOST_MPL_ASSERT(( equal<
140 , transform_view< iters,deref<_1> >
147 |Algorithms|, |iter_fold|, |reverse_fold|, |fold|
150 .. copyright:: Copyright © 2001-2009 Aleksey Gurtovoy and David Abrahams
151 Distributed under the Boost Software License, Version 1.0. (See accompanying
152 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)