File indexing completed on 2026-05-03 08:13:37
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef _LIBCPP___CXX03___NUMERIC_TRANSFORM_REDUCE_H
0011 #define _LIBCPP___CXX03___NUMERIC_TRANSFORM_REDUCE_H
0012
0013 #include <__cxx03/__config>
0014 #include <__cxx03/__functional/operations.h>
0015 #include <__cxx03/__utility/move.h>
0016
0017 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0018 # pragma GCC system_header
0019 #endif
0020
0021 _LIBCPP_PUSH_MACROS
0022 #include <__cxx03/__undef_macros>
0023
0024 _LIBCPP_BEGIN_NAMESPACE_STD
0025
0026 #if _LIBCPP_STD_VER >= 17
0027 template <class _InputIterator, class _Tp, class _BinaryOp, class _UnaryOp>
0028 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp
0029 transform_reduce(_InputIterator __first, _InputIterator __last, _Tp __init, _BinaryOp __b, _UnaryOp __u) {
0030 for (; __first != __last; ++__first)
0031 __init = __b(std::move(__init), __u(*__first));
0032 return __init;
0033 }
0034
0035 template <class _InputIterator1, class _InputIterator2, class _Tp, class _BinaryOp1, class _BinaryOp2>
0036 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp transform_reduce(
0037 _InputIterator1 __first1,
0038 _InputIterator1 __last1,
0039 _InputIterator2 __first2,
0040 _Tp __init,
0041 _BinaryOp1 __b1,
0042 _BinaryOp2 __b2) {
0043 for (; __first1 != __last1; ++__first1, (void)++__first2)
0044 __init = __b1(std::move(__init), __b2(*__first1, *__first2));
0045 return __init;
0046 }
0047
0048 template <class _InputIterator1, class _InputIterator2, class _Tp>
0049 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp
0050 transform_reduce(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _Tp __init) {
0051 return std::transform_reduce(__first1, __last1, __first2, std::move(__init), std::plus<>(), std::multiplies<>());
0052 }
0053 #endif
0054
0055 _LIBCPP_END_NAMESPACE_STD
0056
0057 _LIBCPP_POP_MACROS
0058
0059 #endif