14824e7fdSDimitry Andric // -*- C++ -*-
24824e7fdSDimitry Andric //===----------------------------------------------------------------------===//
34824e7fdSDimitry Andric //
44824e7fdSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
54824e7fdSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
64824e7fdSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
74824e7fdSDimitry Andric //
84824e7fdSDimitry Andric //===----------------------------------------------------------------------===//
94824e7fdSDimitry Andric
104824e7fdSDimitry Andric #ifndef _LIBCPP___NUMERIC_INNER_PRODUCT_H
114824e7fdSDimitry Andric #define _LIBCPP___NUMERIC_INNER_PRODUCT_H
124824e7fdSDimitry Andric
134824e7fdSDimitry Andric #include <__config>
144824e7fdSDimitry Andric #include <__utility/move.h>
154824e7fdSDimitry Andric
164824e7fdSDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
174824e7fdSDimitry Andric # pragma GCC system_header
184824e7fdSDimitry Andric #endif
194824e7fdSDimitry Andric
2006c3fb27SDimitry Andric _LIBCPP_PUSH_MACROS
2106c3fb27SDimitry Andric #include <__undef_macros>
2206c3fb27SDimitry Andric
234824e7fdSDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD
244824e7fdSDimitry Andric
254824e7fdSDimitry Andric template <class _InputIterator1, class _InputIterator2, class _Tp>
26*cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp
inner_product(_InputIterator1 __first1,_InputIterator1 __last1,_InputIterator2 __first2,_Tp __init)27*cb14a3feSDimitry Andric inner_product(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _Tp __init) {
284824e7fdSDimitry Andric for (; __first1 != __last1; ++__first1, (void)++__first2)
2906c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 20
305f757f3fSDimitry Andric __init = std::move(__init) + *__first1 * *__first2;
314824e7fdSDimitry Andric #else
324824e7fdSDimitry Andric __init = __init + *__first1 * *__first2;
334824e7fdSDimitry Andric #endif
344824e7fdSDimitry Andric return __init;
354824e7fdSDimitry Andric }
364824e7fdSDimitry Andric
374824e7fdSDimitry Andric template <class _InputIterator1, class _InputIterator2, class _Tp, class _BinaryOperation1, class _BinaryOperation2>
inner_product(_InputIterator1 __first1,_InputIterator1 __last1,_InputIterator2 __first2,_Tp __init,_BinaryOperation1 __binary_op1,_BinaryOperation2 __binary_op2)38*cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp inner_product(
39*cb14a3feSDimitry Andric _InputIterator1 __first1,
40*cb14a3feSDimitry Andric _InputIterator1 __last1,
41*cb14a3feSDimitry Andric _InputIterator2 __first2,
42*cb14a3feSDimitry Andric _Tp __init,
43*cb14a3feSDimitry Andric _BinaryOperation1 __binary_op1,
44*cb14a3feSDimitry Andric _BinaryOperation2 __binary_op2) {
454824e7fdSDimitry Andric for (; __first1 != __last1; ++__first1, (void)++__first2)
4606c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 20
475f757f3fSDimitry Andric __init = __binary_op1(std::move(__init), __binary_op2(*__first1, *__first2));
484824e7fdSDimitry Andric #else
494824e7fdSDimitry Andric __init = __binary_op1(__init, __binary_op2(*__first1, *__first2));
504824e7fdSDimitry Andric #endif
514824e7fdSDimitry Andric return __init;
524824e7fdSDimitry Andric }
534824e7fdSDimitry Andric
544824e7fdSDimitry Andric _LIBCPP_END_NAMESPACE_STD
554824e7fdSDimitry Andric
5606c3fb27SDimitry Andric _LIBCPP_POP_MACROS
5706c3fb27SDimitry Andric
584824e7fdSDimitry Andric #endif // _LIBCPP___NUMERIC_INNER_PRODUCT_H
59