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

accumulate()

Library: Numerics


Function

Local Index

No Entries

Summary

A generalized numeric operation that accumulates all elements within a range into a single value

Synopsis

#include <numeric>
namespace std {
 template <class InputIterator, class T>
 T accumulate(InputIterator start,
 InputIterator finish,
 T init);
 template <class InputIterator,
 class T,
 class BinaryOperation>
 T accumulate(InputIterator start,
 InputIterator finish,
 T init,
 BinaryOperation binary_op);
}

Description

accumulate() applies a binary operation to init and each value in the range [start,finish). The result of each operation is returned in init. This process aggregates the result of performing the operation on every element of the sequence into a single value.

The accumulator acc is initialized with the value init and modified with acc = acc + *i or acc = binary_op(acc, *i) for each interator i, in order, in the range [start, finish).

Complexity

accumulate() performs exactly finish-start applications of the binary operation, operator+ by default.

Example

Standards Conformance

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



Previous fileTop of DocumentContentsIndex pageNext file

AltStyle によって変換されたページ (->オリジナル) /