51 lines · c
1// -*- C++ -*-2//===----------------------------------------------------------------------===//3//4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.5// See https://llvm.org/LICENSE.txt for license information.6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception7//8//===----------------------------------------------------------------------===//9 10#ifndef _LIBCPP___CXX03___NUMERIC_INNER_PRODUCT_H11#define _LIBCPP___CXX03___NUMERIC_INNER_PRODUCT_H12 13#include <__cxx03/__config>14#include <__cxx03/__utility/move.h>15 16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)17# pragma GCC system_header18#endif19 20_LIBCPP_PUSH_MACROS21#include <__cxx03/__undef_macros>22 23_LIBCPP_BEGIN_NAMESPACE_STD24 25template <class _InputIterator1, class _InputIterator2, class _Tp>26_LIBCPP_HIDE_FROM_ABI _Tp27inner_product(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _Tp __init) {28 for (; __first1 != __last1; ++__first1, (void)++__first2)29 __init = __init + *__first1 * *__first2;30 return __init;31}32 33template <class _InputIterator1, class _InputIterator2, class _Tp, class _BinaryOperation1, class _BinaryOperation2>34_LIBCPP_HIDE_FROM_ABI _Tp inner_product(35 _InputIterator1 __first1,36 _InputIterator1 __last1,37 _InputIterator2 __first2,38 _Tp __init,39 _BinaryOperation1 __binary_op1,40 _BinaryOperation2 __binary_op2) {41 for (; __first1 != __last1; ++__first1, (void)++__first2)42 __init = __binary_op1(__init, __binary_op2(*__first1, *__first2));43 return __init;44}45 46_LIBCPP_END_NAMESPACE_STD47 48_LIBCPP_POP_MACROS49 50#endif // _LIBCPP___CXX03___NUMERIC_INNER_PRODUCT_H51