26 Numerics library [numerics]

26.8 Generalized numeric operations [numeric.ops]

26.8.8 Inclusive scan [inclusive.scan]

template<class InputIterator, class OutputIterator> OutputIterator inclusive_scan(InputIterator first, InputIterator last, OutputIterator result);

Effects: Equivalent to:

return inclusive_scan(first, last, result, plus<>());

template<class ExecutionPolicy, class InputIterator, class OutputIterator> OutputIterator inclusive_scan(ExecutionPolicy&& exec, InputIterator first, InputIterator last, OutputIterator result);

Effects: Equivalent to:

return inclusive_scan(std::forward<ExecutionPolicy>(exec), first, last, result, plus<>());

template<class InputIterator, class OutputIterator, class BinaryOperation> OutputIterator inclusive_scan(InputIterator first, InputIterator last, OutputIterator result, BinaryOperation binary_op); template<class ExecutionPolicy, class InputIterator, class OutputIterator, class BinaryOperation> OutputIterator inclusive_scan(ExecutionPolicy&& exec, InputIterator first, InputIterator last, OutputIterator result, BinaryOperation binary_op); template<class InputIterator, class OutputIterator, class BinaryOperation, class T> OutputIterator inclusive_scan(InputIterator first, InputIterator last, OutputIterator result, BinaryOperation binary_op, T init); template<class ExecutionPolicy, class InputIterator, class OutputIterator, class BinaryOperation, class T> OutputIterator inclusive_scan(ExecutionPolicy&& exec, InputIterator first, InputIterator last, OutputIterator result, BinaryOperation binary_op, T init);

Requires: binary_op shall not invalidate iterators or subranges, nor modify elements in the ranges [first, last) or [result, result + (last - first)).

Effects: Assigns through each iterator i in [result, result + (last - first)) the value of

  • GENERALIZED_NONCOMMUTATIVE_SUM(binary_op, init, *j, ...) for every j in [first, first + (i - result + 1)) if init is provided, or

  • GENERALIZED_NONCOMMUTATIVE_SUM(binary_op, *j, ...) for every j in [first, first + (i - result + 1)) otherwise.

Returns: The end of the resulting range beginning at result.

Complexity: Ο(last - first) applications of binary_op.

Remarks: result may be equal to first.

Notes: The difference between exclusive_scan and inclusive_scan is that inclusive_scan includes the ith input element in the ith sum. If binary_op is not mathematically associative, the behavior of inclusive_scan may be nondeterministic.