template<class InputIt1, class InputIt2, class T>
T inner_product(InputIt1 first1, InputIt1 last1, InputIt2 first2, T init); // constexpr since C++20
template<class InputIt1, class InputIt2, class T, class BinaryOp1, class BinaryOp2>
T inner_product(InputIt1 first1, InputIt1 last1, InputIt2 first2, T init, BinaryOp1 op1, BinaryOp2 op2); // constexpr since C++20
: 두 개 범위의 내적(inner product)을 계산하고 그 값을 반환합니다.
<example>
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;
int main() {
vector<int> vec1 = { 10, 15, 5, 2, 4 };
vector<int> vec2 = { 5, 7, 9, 11, 13 };
cout << inner_product(vec1.begin(), vec1.end(), vec2.begin(), 0);
return 0;
}
결과값
계산 과정
0 + 10 * 5 + 15 * 7 + 5 * 9 + 2 * 11 + 4 * 13 = 274