]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | .. Algorithms/Iteration Algorithms//accumulate |10 |
2 | ||
3 | accumulate | |
4 | ========== | |
5 | ||
6 | Synopsis | |
7 | -------- | |
8 | ||
9 | .. parsed-literal:: | |
10 | ||
11 | template< | |
12 | typename Sequence | |
13 | , typename State | |
14 | , typename ForwardOp | |
15 | > | |
16 | struct accumulate | |
17 | { | |
18 | typedef |unspecified| type; | |
19 | }; | |
20 | ||
21 | ||
22 | ||
23 | Description | |
24 | ----------- | |
25 | ||
26 | Returns the result of the successive application of binary ``ForwardOp`` to the | |
27 | result of the previous ``ForwardOp`` invocation (``State`` if it's the first call) | |
28 | and every element of the sequence in the range |begin/end<Sequence>| in order. | |
29 | |Note:| ``accumulate`` is a synonym for |fold| |-- end note| | |
30 | ||
31 | ||
32 | Header | |
33 | ------ | |
34 | ||
35 | .. parsed-literal:: | |
36 | ||
37 | #include <boost/mpl/accumulate.hpp> | |
38 | ||
39 | ||
40 | Parameters | |
41 | ---------- | |
42 | ||
43 | +---------------+-------------------------------+---------------------------------------------------+ | |
44 | | Parameter | Requirement | Description | | |
45 | +===============+===============================+===================================================+ | |
46 | | ``Sequence`` | |Forward Sequence| | A sequence to iterate. | | |
47 | +---------------+-------------------------------+---------------------------------------------------+ | |
48 | | ``State`` | Any type | The initial state for the first ``ForwardOp`` | | |
49 | | | | application. | | |
50 | +---------------+-------------------------------+---------------------------------------------------+ | |
51 | | ``ForwardOp`` | Binary |Lambda Expression| | The operation to be executed on forward | | |
52 | | | | traversal. | | |
53 | +---------------+-------------------------------+---------------------------------------------------+ | |
54 | ||
55 | ||
56 | Expression semantics | |
57 | -------------------- | |
58 | ||
59 | For any |Forward Sequence| ``s``, binary |Lambda Expression| ``op``, and arbitrary type ``state``: | |
60 | ||
61 | ||
62 | .. parsed-literal:: | |
63 | ||
64 | typedef accumulate<s,state,op>::type t; | |
65 | ||
66 | :Return type: | |
67 | A type. | |
68 | ||
69 | :Semantics: | |
70 | Equivalent to | |
71 | ||
72 | .. parsed-literal:: | |
73 | ||
74 | typedef fold<s,state,op>::type t; | |
75 | ||
76 | ||
77 | ||
78 | Complexity | |
79 | ---------- | |
80 | ||
81 | Linear. Exactly ``size<s>::value`` applications of ``op``. | |
82 | ||
83 | ||
84 | Example | |
85 | ------- | |
86 | ||
87 | .. parsed-literal:: | |
88 | ||
89 | typedef vector<long,float,short,double,float,long,long double> types; | |
90 | typedef accumulate< | |
91 | types | |
92 | , int_<0> | |
93 | , if_< is_float<_2>,next<_1>,_1 > | |
94 | >::type number_of_floats; | |
95 | ||
96 | BOOST_MPL_ASSERT_RELATION( number_of_floats::value, ==, 4 ); | |
97 | ||
98 | ||
99 | See also | |
100 | -------- | |
101 | ||
102 | |Algorithms|, |fold|, |reverse_fold|, |iter_fold|, |reverse_iter_fold|, |copy|, |copy_if| | |
103 | ||
104 | ||
105 |