## partial_sum
## Prototype
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
More precisely, a running sum is first initialized to ## DefinitionDefined in the standard header numeric, and in the nonstandard backward-compatibility header algo.h. ## Requirements on typesFor the first version: -
`InputIterator` is a model of InputIterator. -
`OutputIterator` is a model of OutputIterator. -
If
`x` and`y` are objects of`InputIterator` 's value type, then`x + y` is defined. -
The return type of
`x + y` is convertible to`InputIterator` 's value type. -
`InputIterator` 's value type is convertible to a type in`OutputIterator` 's set of value types.
For the second version: -
`InputIterator` is a model of InputIterator. -
`OutputIterator` is a model of OutputIterator. -
`BinaryFunction` is a model of BinaryFunction. -
`InputIterator` 's value type is convertible to`BinaryFunction` 's first argument type and second argument type. -
`BinaryFunction` 's result type is convertible to`InputIterator` 's value type. -
`InputIterator` 's value type is convertible to a type in`OutputIterator` 's set of value types.
## Preconditions-
`[first, last)` is a valid range. -
`[result, result + (last - first))` is a valid range.
## ComplexityLinear. Zero applications of the binary operation if ## Exampleint main() { const int N = 10; int A[N]; fill(A, A+N, 1); cout << "A: "; copy(A, A+N, ostream_iterator<int>(cout, " ")); cout << endl; cout << "Partial sums of A: "; partial_sum(A, A+N, ostream_iterator<int>(cout, " ")); cout << endl; } ## Notes[1] Note that [2] The binary operation is not required to be either associative or commutative: the order of all operations is specified. ## See also |