Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Standard C++ Library Module Reference Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

partial_sum()

Module:  Standard C++ Library   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

Copyright (c) 1994-2006 Rogue Wave Software, a Quovadx Division.
Licensed under the Apache License, Version 2.0.
Contact Rogue Wave about documentation or support issues. You can also seek help from other developers through the Apache stdcxx community (see below).

For more information on the Rogue Wave Standard C++ Library under open source, see Section 1.2 of the user's guide.