• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1.. .. Algorithms/Iteration Algorithms
2
3.. UNFINISHED: Expression semantics and everything that follows
4
5
6iter_fold_if
7============
8
9Synopsis
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
28Description
29-----------
30
31Returns the result of the successive application of binary ``ForwardOp`` to the result
32of the previous ``ForwardOp`` invocation (``State`` if it's the first call) and each
33iterator in the sequence range determined by ``ForwardPred`` predicate. If ``BackwardOp``
34is provided, it's similarly applied on backward traversal to the result of the
35previous ``BackwardOp`` invocation (the last result returned by ``ForwardOp` if it's
36the first call) and each iterator in the sequence range determined by
37``BackwardPred`` predicate.
38
39
40Header
41------
42
43.. parsed-literal::
44
45    #include <boost/mpl/iter_fold_if.hpp>
46
47
48Parameters
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
71Expression semantics
72--------------------
73
74For any |Forward Sequence| ``s``, binary |Lambda Expression| ``op``, and an
75arbitrary 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
106Complexity
107----------
108
109Linear. Exactly ``size<Sequence>::value`` applications of ``ForwardOp``.
110
111
112Example
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
128See also
129--------
130
131Algorithms, ``iter_fold_backward``, ``fold``, ``fold_backward``, ``copy``, ``copy_backward``
132
133
134.. copyright:: Copyright �  2001-2009 Aleksey Gurtovoy and David Abrahams
135   Distributed under the Boost Software License, Version 1.0. (See accompanying
136   file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
137