29 Numerics library [numerics]

29.8 Generalized numeric operations [numeric.ops]

29.8.9 Transform exclusive scan [transform.exclusive.scan]

template<class InputIterator, class OutputIterator, class T, class BinaryOperation, class UnaryOperation> OutputIterator transform_exclusive_scan(InputIterator first, InputIterator last, OutputIterator result, T init, BinaryOperation binary_op, UnaryOperation unary_op); template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class T, class BinaryOperation, class UnaryOperation> ForwardIterator2 transform_exclusive_scan(ExecutionPolicy&& exec, ForwardIterator1 first, ForwardIterator1 last, ForwardIterator2 result, T init, BinaryOperation binary_op, UnaryOperation unary_op);

Requires:

  • T shall be MoveConstructible (Table 23).

  • All of

    • binary_­op(init, init),

    • binary_­op(init, unary_­op(*first)), and

    • binary_­op(unary_­op(*first), unary_­op(*first))

    shall be convertible to T.

  • Neither unary_­op nor binary_­op shall invalidate iterators or subranges, or modify 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,
    unary_op(*(first + 0)), unary_op(*(first + 1)), ..., unary_op(*(first + K - 1)))

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

Complexity: O(last - first) applications each of unary_­op and binary_­op.

Remarks: result may be equal to first.

[Note: The difference between transform_­exclusive_­scan and transform_­inclusive_­scan is that transform_­exclusive_­scan excludes the ith input element from the ith sum. If binary_­op is not mathematically associative, the behavior of transform_­exclusive_­scan may be nondeterministic. transform_­exclusive_­scan does not apply unary_­op to init. end note]