accumulate()
By default, adds the container elements to an initial value specified by the third argument. A binary operation can be passed in to override the default addition.
#include <numeric> iresult = accumulate( ia, ia+8, 0); iresult = accumulate( ilist.begin(), ilist.end(), 0, plus<int>() );
Get Essential C++ now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.