• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1.. Algorithms/Iteration Algorithms//accumulate |10
2
3accumulate
4==========
5
6Synopsis
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
23Description
24-----------
25
26Returns the result of the successive application of binary ``ForwardOp`` to the
27result of the previous ``ForwardOp`` invocation (``State`` if it's the first call)
28and 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
32Header
33------
34
35.. parsed-literal::
36
37    #include <boost/mpl/accumulate.hpp>
38
39
40Parameters
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
56Expression semantics
57--------------------
58
59For 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
78Complexity
79----------
80
81Linear. Exactly ``size<s>::value`` applications of ``op``.
82
83
84Example
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
99See also
100--------
101
102|Algorithms|, |fold|, |reverse_fold|, |iter_fold|, |reverse_iter_fold|, |copy|, |copy_if|
103
104
105.. copyright:: Copyright �  2001-2009 Aleksey Gurtovoy and David Abrahams
106   Distributed under the Boost Software License, Version 1.0. (See accompanying
107   file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
108