Previous fileTop of DocumentContentsIndex pageNext file
Apache C++ Standard Library Reference Guide

partial_sum()

Library:  Numerics


Function

Local Index

No Entries

Summary

Generalized numeric operation that calculates successive partial sums of a range of values

Synopsis

#include <numeric>

namespace std {
  template <class InputIterator, class OutputIterator>
  OutputIterator partial_sum(InputIterator start,
                             InputIterator finish,
                             OutputIterator result);

  template <class InputIterator,
            class OutputIterator,
            class BinaryOperation>
  OutputIterator partial_sum(InputIterator start,
                             InputIterator finish,
                             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, by applying the operation binary_op successively on every previous element. That is, partial_sum() assigns to every iterator i in the range [result, result + (finish - start)) a value equal to:

or, in the second version of the algorithm:

For instance, applying partial_sum() to (1,2,3,4,) yields (1,3,6,10).

The partial_sum() algorithm returns result + (finish - start).

If result is equal to start, the elements of the new sequence successively replace the elements in the original sequence, effectively turning partial_sum() into an inplace transformation.

Complexity

Exactly (finish - start) - 1 applications of the default + operator or binary_op are performed.

Example

See Also

Algorithms, <algorithm>

Standards Conformance

ISO/IEC 14882:1998 -- International Standard for Information Systems -- Programming Language C++, Section 26.4.3



Previous fileTop of DocumentContentsIndex pageNext file