| Home | Libraries | People | FAQ | More

##### accumulate

###### Prototype

    template<
        class SinglePassRange,
        class Value
        >
    Value accumulate(const SinglePassRange& source_rng,
                     Value init);

    template<
        class SinglePassRange,
        class Value,
        class BinaryOperation
        >
    Value accumulate(const SinglePassRange& source_rng,
                     Value init,
                     BinaryOperation op);

###### Description

`accumulate` is a generalisation of summation. It computes a binary operation (`operator+` in the non-predicate version) of `init` and all of the elements in `rng`.

The return value is the resultant value of the above algorithm.

###### Definition

Defined in the header file `boost/range/numeric.hpp`

###### Requirements

###### For the first version

1. `SinglePassRange` is a model of the Single Pass Range Concept.
2. `Value` is a model of the `AssignableConcept`.
3. An `operator+` is defined for a left-hand operand of type `Value` and a right-hand operand of the `SinglePassRange` value type.
4. The return type of the above operator is convertible to `Value`.

###### For the second version

1. `SinglePassRange` is a model of the Single Pass Range Concept.
2. `Value` is a model of the `AssignableConcept`.
3. `BinaryOperation` is a model of the `BinaryFunctionConcept`.
4. `Value` is convertible to `BinaryOperation`'s first argument type.
5. `SinglePassRange`'s value type is convertible to `BinaryOperation`'s second argument type.
6. The return type of `BinaryOperation` is convertible to `Value`.

###### Complexity

Linear. Exactly `distance(source_rng)`.