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_TRANSFORM_REDUCE_H 114824e7fdSDimitry Andric #define _LIBCPP___NUMERIC_TRANSFORM_REDUCE_H 124824e7fdSDimitry Andric 134824e7fdSDimitry Andric #include <__config> 144824e7fdSDimitry Andric #include <__functional/operations.h> 154824e7fdSDimitry Andric #include <__utility/move.h> 164824e7fdSDimitry Andric 174824e7fdSDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 184824e7fdSDimitry Andric # pragma GCC system_header 194824e7fdSDimitry Andric #endif 204824e7fdSDimitry Andric 21*b3edf446SDimitry Andric _LIBCPP_PUSH_MACROS 22*b3edf446SDimitry Andric #include <__undef_macros> 23*b3edf446SDimitry Andric 244824e7fdSDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD 254824e7fdSDimitry Andric 2606c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 17 274824e7fdSDimitry Andric template <class _InputIterator, class _Tp, class _BinaryOp, class _UnaryOp> 28cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp 29cb14a3feSDimitry Andric transform_reduce(_InputIterator __first, _InputIterator __last, _Tp __init, _BinaryOp __b, _UnaryOp __u) { 304824e7fdSDimitry Andric for (; __first != __last; ++__first) 3106c3fb27SDimitry Andric __init = __b(std::move(__init), __u(*__first)); 324824e7fdSDimitry Andric return __init; 334824e7fdSDimitry Andric } 344824e7fdSDimitry Andric 354824e7fdSDimitry Andric template <class _InputIterator1, class _InputIterator2, class _Tp, class _BinaryOp1, class _BinaryOp2> 36cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp transform_reduce( 37cb14a3feSDimitry Andric _InputIterator1 __first1, 384824e7fdSDimitry Andric _InputIterator1 __last1, 39cb14a3feSDimitry Andric _InputIterator2 __first2, 40cb14a3feSDimitry Andric _Tp __init, 41cb14a3feSDimitry Andric _BinaryOp1 __b1, 42cb14a3feSDimitry Andric _BinaryOp2 __b2) { 434824e7fdSDimitry Andric for (; __first1 != __last1; ++__first1, (void)++__first2) 4406c3fb27SDimitry Andric __init = __b1(std::move(__init), __b2(*__first1, *__first2)); 454824e7fdSDimitry Andric return __init; 464824e7fdSDimitry Andric } 474824e7fdSDimitry Andric 484824e7fdSDimitry Andric template <class _InputIterator1, class _InputIterator2, class _Tp> 49cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp 50cb14a3feSDimitry Andric transform_reduce(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _Tp __init) { 51cb14a3feSDimitry Andric return std::transform_reduce(__first1, __last1, __first2, std::move(__init), std::plus<>(), std::multiplies<>()); 524824e7fdSDimitry Andric } 534824e7fdSDimitry Andric #endif 544824e7fdSDimitry Andric 554824e7fdSDimitry Andric _LIBCPP_END_NAMESPACE_STD 564824e7fdSDimitry Andric 57*b3edf446SDimitry Andric _LIBCPP_POP_MACROS 58*b3edf446SDimitry Andric 594824e7fdSDimitry Andric #endif // _LIBCPP___NUMERIC_TRANSFORM_REDUCE_H 60