]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | .. .. Algorithms/Iteration Algorithms |
2 | ||
3 | .. UNFINISHED: Expression semantics and everything that follows | |
4 | ||
5 | ||
6 | iter_fold_if | |
7 | ============ | |
8 | ||
9 | Synopsis | |
10 | -------- | |
11 | ||
12 | .. parsed-literal:: | |
13 | ||
14 | template< | |
15 | typename Sequence | |
16 | , typename State | |
17 | , typename ForwardOp | |
18 | , typename ForwardPred | |
19 | , typename BackwardOp = |unspecified| | |
20 | , typename BackwardPred = |unspecified| | |
21 | > | |
22 | struct iter_fold_if | |
23 | { | |
24 | typedef |unspecified| type; | |
25 | }; | |
26 | ||
27 | ||
28 | Description | |
29 | ----------- | |
30 | ||
31 | Returns the result of the successive application of binary ``ForwardOp`` to the result | |
32 | of the previous ``ForwardOp`` invocation (``State`` if it's the first call) and each | |
33 | iterator in the sequence range determined by ``ForwardPred`` predicate. If ``BackwardOp`` | |
34 | is provided, it's similarly applied on backward traversal to the result of the | |
35 | previous ``BackwardOp`` invocation (the last result returned by ``ForwardOp` if it's | |
36 | the first call) and each iterator in the sequence range determined by | |
37 | ``BackwardPred`` predicate. | |
38 | ||
39 | ||
40 | Header | |
41 | ------ | |
42 | ||
43 | .. parsed-literal:: | |
44 | ||
45 | #include <boost/mpl/iter_fold_if.hpp> | |
46 | ||
47 | ||
48 | Parameters | |
49 | ---------- | |
50 | ||
51 | +-------------------+-------------------------------+-----------------------------------------------+ | |
52 | | Parameter | Requirement | Description | | |
53 | +===============+===================================+===============================================+ | |
54 | | ``Sequence`` | |Forward Sequence| | A sequence to iterate. | | |
55 | +-------------------+-------------------------------+-----------------------------------------------+ | |
56 | | ``State`` | Any type | The initial state for the first ``BackwardOp``| | |
57 | | | | / ``ForwardOp`` application. | | |
58 | +-------------------+-------------------------------+-----------------------------------------------+ | |
59 | | ``ForwardOp`` | Binary |Lambda Expression| | The operation to be executed on forward | | |
60 | | | | traversal. | | |
61 | +-------------------+-------------------------------+-----------------------------------------------+ | |
62 | | ``ForwardPred`` | Binary |Lambda Expression| | The forward traversal predicate. | | |
63 | +-------------------+-------------------------------+-----------------------------------------------+ | |
64 | | ``BackwardOp`` | Binary |Lambda Expression| | The operation to be executed on backward | | |
65 | | | | traversal. | | |
66 | +-------------------+-------------------------------+-----------------------------------------------+ | |
67 | | ``BackwardPred`` | Binary |Lambda Expression| | The backward traversal predicate. | | |
68 | +-------------------+-------------------------------+-----------------------------------------------+ | |
69 | ||
70 | ||
71 | Expression semantics | |
72 | -------------------- | |
73 | ||
74 | For any |Forward Sequence| ``s``, binary |Lambda Expression| ``op``, and an | |
75 | arbitrary type ``state``: | |
76 | ||
77 | ||
78 | .. parsed-literal:: | |
79 | ||
80 | typedef iter_fold<Sequence,T,Op>::type t; | |
81 | ||
82 | :Return type: | |
83 | A type | |
84 | ||
85 | :Semantics: | |
86 | Equivalent to | |
87 | ||
88 | .. parsed-literal:: | |
89 | ||
90 | typedef lambda<Op>::type op; | |
91 | typedef begin<Sequence>::type i1; | |
92 | typedef apply<op,T,i1>::type t1; | |
93 | typedef i1::next i2; | |
94 | typedef apply<op,t1,i2>::type t2; | |
95 | ... | |
96 | typedef apply<op,T,in>::type tn; | |
97 | typedef in::next last; | |
98 | typedef tn t | |
99 | ||
100 | where ``n == size<Sequence>::value`` and ``last`` is identical to ``end<Sequence>::type``; | |
101 | ||
102 | Equivalent to ``typedef T t;`` if the sequence is empty. | |
103 | ||
104 | ||
105 | ||
106 | Complexity | |
107 | ---------- | |
108 | ||
109 | Linear. Exactly ``size<Sequence>::value`` applications of ``ForwardOp``. | |
110 | ||
111 | ||
112 | Example | |
113 | ------- | |
114 | ||
115 | .. parsed-literal:: | |
116 | ||
117 | typedef list_c<int,5,-1,0,7,2,0,-5,4> numbers; | |
118 | typedef iter_fold< | |
119 | numbers | |
120 | , begin<numbers>::type | |
121 | , if_< less< deref<_1>, deref<_2> >,_2,_1 > | |
122 | >::type max_element_iter; | |
123 | ||
124 | BOOST_STATIC_ASSERT(max_element_iter::type::value == 7); | |
125 | ||
126 | ||
127 | ||
128 | See also | |
129 | -------- | |
130 | ||
131 | Algorithms, ``iter_fold_backward``, ``fold``, ``fold_backward``, ``copy``, ``copy_backward`` | |
132 | ||
133 | ||
134 |