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: Equivalent to:

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 shall be MoveConstructible (Table 23).

  • All of

    • binary_Β­op1(init, init),

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

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

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

    shall be convertible to T.

  • Neither binary_Β­op1 nor binary_Β­op2 shall invalidate subranges, or modify elements in the ranges [first1, last1] and [first2, first2 + (last1 - first1)].

Returns:

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

for every iterator i in [first1, last1).

Complexity: O(last1 - first1) applications each of binary_Β­op1 and 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 shall be MoveConstructible (Table 23).

  • All of

    • binary_Β­op(init, init),

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

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

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

    shall be convertible to T.

  • Neither unary_Β­op nor binary_Β­op shall invalidate subranges, or modify elements in the range [first, last].

Returns:

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

for every iterator i in [first, last).

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

[ Note: transform_Β­reduce does not apply unary_Β­op to init.  — end note ]