template
T accumulate(InputIterator first, InputIterator last, T init);
template
T accumulate(InputIterator first, InputIterator last, T init,
BinaryOperation binary_op);
accumulate is similar to the APL reduction operator and Common Lisp
reduce function, but it avoids the difficulty of defining the result of
reduction on an empty sequence by always requiring an initial value.
Accumulation is done by initializing the accumulator acc with the
initial value init and then modifying it with
acc = acc + *i or acc = binary_op(acc, *i)
for every iterator i in the range [first, last)
in order. binary_op is assumed not to cause side effects.
|