int add (int x, int y) { return x + y; }
int s = 0;
return accumulate (l.begin(), l.end(), s, add);
Implementierung (in <numeric>)
template<typename _InputIterator, typename _Tp,
typename _BinaryOperation>
_Tp accumulate(_InputIterator __first,
_InputIterator __last,
_Tp __init, _BinaryOperation __binary_op)
{
for ( ; __first != __last; ++__first)
__init = __binary_op(__init, *__first);
return __init;
}