November 1999
Intermediate to advanced
336 pages
6h 29m
English
By default, the accumulate() function applies operator+ to all the elements residing in a container and returns the cumulative result of adding all the elements. In the case of an integer collection, if the initial value provided to accumulate() is 0, the result would be the sum of the collection. The accumulate() algorithm is by no means limited to object addition. It is capable of applying any operation to the container elements (given that the operation is supported by the elements) and returning the cumulative result [MS96]:
template <class InputIterator, class T>
T accumulate(InputIterator first,
InputIterator beyondLast,
T initialValue)
{
while (first != beyondLast) {
initialValue = initialValue + *first++;
}
}
In C programming, ...
Read now
Unlock full access