5.1 KiB
[inclusive.scan]
26 Algorithms library [algorithms]
26.10 Generalized numeric operations [numeric.ops]
26.10.9 Inclusive scan [inclusive.scan]
template<class InputIterator, class OutputIterator> constexpr OutputIterator inclusive_scan(InputIterator first, InputIterator last, OutputIterator result);
Effects: Equivalent to:return inclusive_scan(first, last, result, plus<>());
template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2> ForwardIterator2 inclusive_scan(ExecutionPolicy&& exec, ForwardIterator1 first, ForwardIterator1 last, ForwardIterator2 result);
Effects: Equivalent to:return inclusive_scan(std::forward(exec), first, last, result, plus<>());
`template<class InputIterator, class OutputIterator, class BinaryOperation> constexpr OutputIterator inclusive_scan(InputIterator first, InputIterator last, OutputIterator result, BinaryOperation binary_op); template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class BinaryOperation> ForwardIterator2 inclusive_scan(ExecutionPolicy&& exec, ForwardIterator1 first, ForwardIterator1 last, ForwardIterator2 result, BinaryOperation binary_op);
template<class InputIterator, class OutputIterator, class BinaryOperation, class T> constexpr OutputIterator inclusive_scan(InputIterator first, InputIterator last, OutputIterator result, BinaryOperation binary_op, T init); template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class BinaryOperation, class T> ForwardIterator2 inclusive_scan(ExecutionPolicy&& exec, ForwardIterator1 first, ForwardIterator1 last, ForwardIterator2 result, BinaryOperation binary_op, T init); `
Let U be the value type of decltype(first).
Mandates: If init is provided, all of
binary_op(init, init),
binary_op(init, *first), and
binary_op(*first, *first)
are convertible to T; otherwise, binary_op(*first, *first) is convertible to U.
Preconditions:
-
If init is provided, T meets the Cpp17MoveConstructible (Table 31) requirements; otherwise, U meets the Cpp17MoveConstructible requirements.
-
binary_op neither invalidates iterators or subranges, nor modifies elements in the ranges [first, last] or [result, result + (last - first)].
Effects: For each integer K in [0, last - first) assigns through result + K the value of
-
GENERALIZED_NONCOMMUTATIVE_SUM(
binary_op, init, *(first + 0), *(first + 1), …, *(first + K))
if init is provided, or -
GENERALIZED_NONCOMMUTATIVE_SUM(
binary_op, *(first + 0), *(first + 1), …, *(first + K))
otherwise.
Returns: The end of the resulting range beginning at result.
Complexity: O(last - first) applications of binary_op.
Remarks: result may be equal to first.
[Note 1:
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 can be nondeterministic.
â end note]