29 Numerics library [numerics]

29.8 Generalized numeric operations [numeric.ops]

29.8.5 Transform reduce [transform.reduce]

template <class InputIterator1, class InputIterator2, class T> T transform_reduce(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, T init); template <class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class T> T transform_reduce(ExecutionPolicy&& exec, ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, T init);

Effects: Эквивалентен:

return transform_reduce(first1, last1, first2, init, plus<>(), multiplies<>());

template <class InputIterator1, class InputIterator2, class T, class BinaryOperation1, class BinaryOperation2> T transform_reduce(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, T init, BinaryOperation1 binary_op1, BinaryOperation2 binary_op2); template <class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class T, class BinaryOperation1, class BinaryOperation2> T transform_reduce(ExecutionPolicy&& exec, ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, T init, BinaryOperation1 binary_op1, BinaryOperation2 binary_op2);

Requires:

  • T будет MoveConstructible (таблица 23).

  • Все

    • binary_­op1(init, init),

    • binary_­op1(init, binary_­op2(*first1, *first2)),

    • binary_­op1(binary_­op2(*first1, *first2), init), а также

    • binary_­op1(binary_­op2(*first1, *first2), binary_­op2(*first1, *first2))

    конвертируется в T.

  • Ни и binary_­op1 не binary_­op2 должны аннулировать поддиапазоны или изменять элементы в диапазонах [first1, last1] и [first2, first2 + (last1 - first1)].

Returns:

GENERALIZED_SUM(binary_op1, init, binary_op2(*i, *(first2 + (i - first1))), ...)

для каждого итератора i в [first1, last1).

Complexity: O(last1 - first1) приложения каждый из binary_­op1 и binary_­op2.

template<class InputIterator, class T, class BinaryOperation, class UnaryOperation> T transform_reduce(InputIterator first, InputIterator last, T init, BinaryOperation binary_op, UnaryOperation unary_op); template<class ExecutionPolicy, class ForwardIterator, class T, class BinaryOperation, class UnaryOperation> T transform_reduce(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, T init, BinaryOperation binary_op, UnaryOperation unary_op);

Requires:

  • T будет MoveConstructible (таблица 23).

  • Все

    • binary_­op(init, init),

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

    • binary_­op(unary_­op(*first), init), а также

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

    конвертируется в T.

  • Ни и unary_­op не binary_­op должно аннулировать поддиапазоны или изменять элементы в диапазоне [first, last].

Returns:

GENERALIZED_SUM(binary_op, init, unary_op(*i), ...)

для каждого итератора i в [first, last).

Complexity: O(last - first) приложения каждый из unary_­op и binary_­op.

[ Note: transform_­reduce не относится unary_­op к init. ] end note