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

2.4 KiB
Raw Blame History

[inner.product]

26 Algorithms library [algorithms]

26.10 Generalized numeric operations [numeric.ops]

26.10.5 Inner product [inner.product]

🔗

template<class InputIterator1, class InputIterator2, class T> constexpr T inner_product(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, T init); template<class InputIterator1, class InputIterator2, class T, class BinaryOperation1, class BinaryOperation2> constexpr T inner_product(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, T init, BinaryOperation1 binary_op1, BinaryOperation2 binary_op2);

1

#

Preconditions: T meets the Cpp17CopyConstructible (Table 32) and Cpp17CopyAssignable (Table 34) requirements.

In the ranges [first1, last1] and [first2, first2 + (last1 - first1)]binary_op1 and binary_op2 neither modifies elements nor invalidates iterators or subranges.207

2

#

Effects: Computes its result by initializing the accumulator acc with the initial value init and then modifying it withacc = std::move(acc) + (*i1) * (*i2) oracc = binary_op1(std::move(acc), binary_op2(*i1, *i2)) for every iterator i1 in the range [first1, last1) and iterator i2 in the range [first2, first2 + (last1 - first1)) in order.

207)207)

The use of fully closed ranges is intentional.