1.. Algorithms/Iteration Algorithms//reverse_iter_fold 2 3reverse_iter_fold 4================= 5 6Synopsis 7-------- 8 9.. parsed-literal:: 10 11 template< 12 typename Sequence 13 , typename State 14 , typename BackwardOp 15 , typename ForwardOp = _1 16 > 17 struct reverse_iter_fold 18 { 19 typedef |unspecified| type; 20 }; 21 22 23 24Description 25----------- 26 27Returns the result of the successive application of binary ``BackwardOp`` to the 28result of the previous ``BackwardOp`` invocation (``State`` if it's the first call) 29and each iterator in the range [``begin<Sequence>::type``, ``end<Sequence>::type``) 30in reverse order. If ``ForwardOp`` is provided, then it's applied on forward 31traversal to form the result which is passed to the first ``BackwardOp`` call. 32 33 34Header 35------ 36 37.. parsed-literal:: 38 39 #include <boost/mpl/reverse_iter_fold.hpp> 40 41 42 43Parameters 44---------- 45 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 | 55| | | traversal. | 56+---------------+-------------------------------+-----------------------------------------------+ 57| ``ForwardOp`` | Binary |Lambda Expression| | The operation to be executed on forward | 58| | | traversal. | 59+---------------+-------------------------------+-----------------------------------------------+ 60 61 62Expression semantics 63-------------------- 64 65For any |Forward Sequence| ``s``, binary |Lambda Expression| ``backward_op`` and ``forward_op``, 66and arbitrary type ``state``: 67 68 69.. parsed-literal:: 70 71 typedef reverse_iter_fold< s,state,backward_op >::type t; 72 73:Return type: 74 A type. 75 76:Semantics: 77 Equivalent to 78 79 .. parsed-literal:: 80 81 typedef begin<s>::type i\ :sub:`1`; 82 typedef next<i\ :sub:`1`>::type i\ :sub:`2`; 83 |...| 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`; 87 |...| 88 typedef apply<backward_op,state\ :sub:`2`,i\ :sub:`1`>::type state\ :sub:`1`; 89 typedef state\ :sub:`1` t; 90 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``. 93 94 95.. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 96 97 98.. parsed-literal:: 99 100 typedef reverse_iter_fold< s,state,backward_op,forward_op >::type t; 101 102:Return type: 103 A type. 104 105:Semantics: 106 Equivalent to 107 108 .. parsed-literal:: 109 110 typedef reverse_iter_fold< 111 Sequence 112 , iter_fold<s,state,forward_op>::type 113 , backward_op 114 >::type t; 115 116 117Complexity 118---------- 119 120Linear. Exactly ``size<s>::value`` applications of ``backward_op`` and ``forward_op``. 121 122 123Example 124------- 125 126Build a list of iterators to the negative elements in a sequence. 127 128.. parsed-literal:: 129 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< 133 numbers 134 , list<> 135 , if_< less< deref<_2>,int_<0> >, push_front<_1,_2>, _1 > 136 >::type iters; 137 138 BOOST_MPL_ASSERT(( equal< 139 negatives 140 , transform_view< iters,deref<_1> > 141 > )); 142 143 144See also 145-------- 146 147|Algorithms|, |iter_fold|, |reverse_fold|, |fold| 148 149 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) 153