⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 accumulate.rst

📁 C++的一个好库。。。现在很流行
💻 RST
字号:
.. Algorithms/Iteration Algorithms//accumulate |10

accumulate
==========

Synopsis
--------

.. parsed-literal::
    
    template<
          typename Sequence
        , typename State
        , typename ForwardOp
        >
    struct accumulate
    {
        typedef |unspecified| type;
    };



Description
-----------

Returns the result of the successive application of binary ``ForwardOp`` to the 
result of the previous ``ForwardOp`` invocation (``State`` if it's the first call) 
and every element of the sequence in the range |begin/end<Sequence>| in order. 
|Note:| ``accumulate`` is a synonym for |fold| |-- end note|


Header
------

.. parsed-literal::
    
    #include <boost/mpl/accumulate.hpp>


Parameters
----------

+---------------+-------------------------------+---------------------------------------------------+
| Parameter     | Requirement                   | Description                                       |
+===============+===============================+===================================================+
| ``Sequence``  | |Forward Sequence|            | A sequence to iterate.                            |
+---------------+-------------------------------+---------------------------------------------------+
| ``State``     | Any type                      | The initial state for the first ``ForwardOp``     |
|               |                               | application.                                      |
+---------------+-------------------------------+---------------------------------------------------+
| ``ForwardOp`` | Binary |Lambda Expression|    | The operation to be executed on forward           |
|               |                               | traversal.                                        |
+---------------+-------------------------------+---------------------------------------------------+


Expression semantics
--------------------

For any |Forward Sequence| ``s``, binary |Lambda Expression| ``op``, and arbitrary type ``state``:


.. parsed-literal::

    typedef accumulate<s,state,op>::type t; 

:Return type:
    A type.

:Semantics:
    Equivalent to
        
    .. parsed-literal::
    
        typedef fold<s,state,op>::type t; 



Complexity
----------

Linear. Exactly ``size<s>::value`` applications of ``op``. 


Example
-------

.. parsed-literal::
    
    typedef vector<long,float,short,double,float,long,long double> types;
    typedef accumulate<
          types
        , int_<0>
        , if_< is_float<_2>,next<_1>,_1 >
        >::type number_of_floats;
    
    BOOST_MPL_ASSERT_RELATION( number_of_floats::value, ==, 4 );


See also
--------

|Algorithms|, |fold|, |reverse_fold|, |iter_fold|, |reverse_iter_fold|, |copy|, |copy_if|

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -