(C++) std::accumulate
January 18, 2018 ยท View on GitHub
std::accumulate is an STL algorithm to accumulate a range. std::accumulate is defined in numeric.h.
- std::accumulate example 1: summing a std::vector of integers
- std::accumulate example 2: summing a std::vector of a custom class using a C++11 lambda expression
- accumulate_if:
accumulatewith a predicate.
A definition of std::accumulate
template <class InputIterator, class T>
T accumulate (InputIterator first, InputIterator last, T init)
{
while (first != last) init = init + *first++;
return init;
}