Standard C++ Library Class Reference

Click on the banner to return to the Class Reference home page.
©Copyright 1996 Rogue Wave Software
partial_sum
Generalized Numeric Operation
Summary
Calculates successive partial sums of a range of values.
Contents
Synopsis
Description
Complexity
Example
Warning
Synopsis
#include <numeric>
template <class InputIterator, class OutputIterator>
OutputIterator partial_sum (InputIterator first,
InputIterator last,
OutputIterator result);
template <class InputIterator,
class OutputIterator,
class BinaryOperation>
OutputIterator partial_sum (InputIterator first,
InputIterator last,
OutputIterator result,
BinaryOperation binary_op);
Description
The partial_sum algorithm creates a new sequence in which every element is formed by adding all the values of
the previous elements, or, in the second form of the algorithm, applying the operation binary_op successively on
every previous element. That is, partial_sum assigns to every iterator i in the range [result, result + (last - first)) a
value equal to:
((...(*first + *(first + 1)) + ... ) + *(first + (i - result)))
or, in the second version of the algorithm: