Files
cppdraft_translate/cppdraft/inclusive/scan.md
2025-10-25 03:02:53 +03:00

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);

1

#

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);

2

#

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); `

3

#

Let U be the value type of decltype(first).

4

#

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.

5

#

Preconditions:

  • (5.1)

    If init is provided, T meets the Cpp17MoveConstructible (Table 31) requirements; otherwise, U meets the Cpp17MoveConstructible requirements.

  • (5.2)

    binary_op neither invalidates iterators or subranges, nor modifies elements in the ranges [first, last] or [result, result + (last - first)].

6

#

Effects: For each integer K in [0, last - first) assigns through result + K the value of

  • (6.1)

    GENERALIZED_NONCOMMUTATIVE_SUM(
    binary_op, init, *(first + 0), *(first + 1), …, *(first + K))
    if init is provided, or

  • (6.2)

    GENERALIZED_NONCOMMUTATIVE_SUM(
    binary_op, *(first + 0), *(first + 1), …, *(first + K))
    otherwise.

7

#

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

8

#

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

9

#

Remarks: result may be equal to first.

10

#

[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]