Name

accumulate function template — Computes a value from all items in a range

Synopsis

template <typename InputIter, typename T>
T accumulate(InputIter first, InputIter last, T init);
template < typename InputIter, typename T, typename BinaryOp>
T accumulate(InputIter first, InputIter last, T init, BinaryOp binary_op);

The accumulate function template sums all the values in the range [first, last) added with init and returns the result. The result and intermediate sum have the same type as init. The second version calls binary_op instead of using the addition (+) operator.