accumulate

template<class InIt, class T>
    T accumulate(InIt first, InIt last, T val);
template<class InIt, class T, class Pred>
    T accumulate(InIt first, InIt last, T val, Pred pr);

The first template function repeatedly replaces val with val + *I, for each value of the InIt iterator I in the interval [first, last). It then returns val.

The second template function repeatedly replaces val with pr(val, *I), for each value of the InIt iterator I in the interval [first, last). It then returns val.

See the related sample program.