## inner_product
## Prototype
template <class InputIterator1, class InputIterator2, class T> T inner_product(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, T init); template <class InputIterator1, class InputIterator2, class T, class BinaryFunction1, class BinaryFunction2> T inner_product(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, T init, BinaryFunction1 binary_op1, BinaryFunction2 binary_op2); ## Description
The first version of The second version of ## DefinitionDefined in the standard header numeric, and in the nonstandard backward-compatibility header algo.h. ## Requirements on typesFor the first version: -
`InputIterator1` is a model of InputIterator. -
`InputIterator2` is a model of InputIterator. -
`T` is a model of Assignable. -
If
`x` is an object of type`T` ,`y` is an object of`InputIterator1` 's value type, and`z` is an object of`InputIterator2` 's value type, then`x + y * z` is defined. -
The type of
`x + y * z` is convertible to`T` .
For the second version: -
`InputIterator1` is a model of InputIterator. -
`InputIterator2` is a model of InputIterator. -
`T` is a model of Assignable. -
`BinaryFunction1` is a model of BinaryFunction. -
`BinaryFunction2` is a model of BinaryFunction. -
`InputIterator1` 's value type is convertible to`BinaryFunction2` 's first argument type. -
`InputIterator2` 's value type is convertible to`BinaryFunction2` 's second argument type. -
`T` is convertible to`BinaryFunction1` 's first argument type. -
`BinaryFunction2` 's return type is convertible to`BinaryFunction1` 's second argument type. -
`BinaryFunction1` 's return type is convertible to`T` .
## Preconditions-
`[first1, last1)` is a valid range. -
`[first2, first2 + (last1 - first1))` is a valid range.
## ComplexityLinear. Exactly ## Exampleint main() { int A1[] = {1, 2, 3}; int A2[] = {4, 1, -2}; const int N1 = sizeof(A1) / sizeof(int); cout << "The inner product of A1 and A2 is " << inner_product(A1, A1 + N1, A2, 0) << endl; } ## Notes[1] There are several reasons why it is important that [2] Neither binary operation is required to be either associative or commutative: the order of all operations is specified. ## See also |