Files
2025-10-25 03:02:53 +03:00

45 lines
2.4 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[inner.product]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.10 Generalized numeric operations [[numeric.ops]](numeric.ops#inner.product)
### 26.10.5 Inner product [inner.product]
[🔗](#lib: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](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L12469)
*Preconditions*: T meets
the [*Cpp17CopyConstructible*](utility.arg.requirements#:Cpp17CopyConstructible "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [32](utility.arg.requirements#tab:cpp17.copyconstructible "Table 32: Cpp17CopyConstructible requirements (in addition to Cpp17MoveConstructible)"))
and [*Cpp17CopyAssignable*](utility.arg.requirements#:Cpp17CopyAssignable "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [34](utility.arg.requirements#tab:cpp17.copyassignable "Table 34: Cpp17CopyAssignable requirements (in addition to Cpp17MoveAssignable)")) requirements[.](#1.sentence-1)
In the ranges [first1, last1] and
[first2, first2 + (last1 - first1)]binary_op1 and binary_op2 neither modifies elements nor invalidates iterators or subranges[.](#1.sentence-2)[207](#footnote-207 "The use of fully closed ranges is intentional.")
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L12482)
*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[.](#2.sentence-1)
[207)](#footnote-207)[207)](#footnoteref-207)
The use of fully closed ranges is intentional[.](#footnote-207.sentence-1)