1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef _LIBCPP___NUMERIC_PSTL_TRANSFORM_REDUCE_H 10 #define _LIBCPP___NUMERIC_PSTL_TRANSFORM_REDUCE_H 11 12 #include <__algorithm/pstl_backend.h> 13 #include <__algorithm/pstl_frontend_dispatch.h> 14 #include <__config> 15 #include <__functional/operations.h> 16 #include <__numeric/transform_reduce.h> 17 #include <__type_traits/is_execution_policy.h> 18 #include <__utility/move.h> 19 #include <__utility/terminate_on_exception.h> 20 21 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 22 # pragma GCC system_header 23 #endif 24 25 #if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17 26 27 _LIBCPP_BEGIN_NAMESPACE_STD 28 29 template <class _ExecutionPolicy, 30 class _ForwardIterator1, 31 class _ForwardIterator2, 32 class _Tp, 33 class _BinaryOperation1, 34 class _BinaryOperation2, 35 class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>, 36 enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0> 37 _LIBCPP_HIDE_FROM_ABI _Tp transform_reduce( 38 _ExecutionPolicy&&, 39 _ForwardIterator1 __first1, 40 _ForwardIterator1 __last1, 41 _ForwardIterator2 __first2, 42 _Tp __init, 43 _BinaryOperation1 __reduce, 44 _BinaryOperation2 __transform) { 45 using _Backend = typename __select_backend<_RawPolicy>::type; 46 return std::__pstl_transform_reduce<_RawPolicy>( 47 _Backend{}, 48 std::move(__first1), 49 std::move(__last1), 50 std::move(__first2), 51 std::move(__init), 52 std::move(__reduce), 53 std::move(__transform)); 54 } 55 56 // This overload doesn't get a customization point because it's trivial to detect (through e.g. 57 // __is_trivial_plus_operation) when specializing the more general variant, which should always be preferred 58 template <class _ExecutionPolicy, 59 class _ForwardIterator1, 60 class _ForwardIterator2, 61 class _Tp, 62 enable_if_t<is_execution_policy_v<__remove_cvref_t<_ExecutionPolicy>>, int> = 0> 63 _LIBCPP_HIDE_FROM_ABI _Tp transform_reduce( 64 _ExecutionPolicy&& __policy, 65 _ForwardIterator1 __first1, 66 _ForwardIterator1 __last1, 67 _ForwardIterator2 __first2, 68 _Tp __init) { 69 return std::transform_reduce(__policy, __first1, __last1, __first2, __init, plus{}, multiplies{}); 70 } 71 72 template <class _ExecutionPolicy, 73 class _ForwardIterator, 74 class _Tp, 75 class _BinaryOperation, 76 class _UnaryOperation, 77 class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>, 78 enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0> 79 _LIBCPP_HIDE_FROM_ABI _Tp transform_reduce( 80 _ExecutionPolicy&&, 81 _ForwardIterator __first, 82 _ForwardIterator __last, 83 _Tp __init, 84 _BinaryOperation __reduce, 85 _UnaryOperation __transform) { 86 using _Backend = typename __select_backend<_RawPolicy>::type; 87 return std::__pstl_transform_reduce<_RawPolicy>( 88 _Backend{}, 89 std::move(__first), 90 std::move(__last), 91 std::move(__init), 92 std::move(__reduce), 93 std::move(__transform)); 94 } 95 96 _LIBCPP_END_NAMESPACE_STD 97 98 #endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17 99 100 #endif // _LIBCPP___NUMERIC_PSTL_TRANSFORM_REDUCE_H 101