| 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-exception |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP_EXECUTION |
| 11 | #define _LIBCPP_EXECUTION |
| 12 | |
| 13 | /* |
| 14 | namespace std::execution { |
| 15 | struct sequenced_policy; |
| 16 | struct parallel_policy; |
| 17 | struct parallel_unsequenced_policy; |
| 18 | struct unsequenced_policy; // since C++20 |
| 19 | |
| 20 | inline constexpr sequenced_policy seq = implementation-defined; |
| 21 | inline constexpr parallel_policy par = implementation-defined; |
| 22 | inline constexpr parallel_unsequenced_policy par_unseq = implementation-defined; |
| 23 | inline constexpr unsequenced_policy unseq = implementation-defined; // since C++20 |
| 24 | } |
| 25 | |
| 26 | namespace std { |
| 27 | template <class T> |
| 28 | struct is_execution_policy; |
| 29 | |
| 30 | template <class T> |
| 31 | inline constexpr bool is_execution_policy_v; |
| 32 | } |
| 33 | */ |
| 34 | |
| 35 | #if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS) |
| 36 | # include <__cxx03/__config> |
| 37 | #else |
| 38 | # include <__config> |
| 39 | # include <__type_traits/is_execution_policy.h> |
| 40 | # include <__type_traits/is_same.h> |
| 41 | # include <__type_traits/remove_cvref.h> |
| 42 | # include <version> |
| 43 | |
| 44 | # if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 45 | # pragma GCC system_header |
| 46 | # endif |
| 47 | |
| 48 | # if _LIBCPP_HAS_EXPERIMENTAL_PSTL && _LIBCPP_STD_VER >= 17 |
| 49 | |
| 50 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 51 | |
| 52 | namespace execution { |
| 53 | struct sequenced_policy { |
| 54 | _LIBCPP_HIDE_FROM_ABI constexpr explicit sequenced_policy(__disable_user_instantiations_tag) {} |
| 55 | sequenced_policy(const sequenced_policy&) = delete; |
| 56 | sequenced_policy& operator=(const sequenced_policy&) = delete; |
| 57 | }; |
| 58 | |
| 59 | inline constexpr sequenced_policy seq{__disable_user_instantiations_tag{}}; |
| 60 | |
| 61 | struct parallel_policy { |
| 62 | _LIBCPP_HIDE_FROM_ABI constexpr explicit parallel_policy(__disable_user_instantiations_tag) {} |
| 63 | parallel_policy(const parallel_policy&) = delete; |
| 64 | parallel_policy& operator=(const parallel_policy&) = delete; |
| 65 | }; |
| 66 | |
| 67 | inline constexpr parallel_policy par{__disable_user_instantiations_tag{}}; |
| 68 | |
| 69 | struct parallel_unsequenced_policy { |
| 70 | _LIBCPP_HIDE_FROM_ABI constexpr explicit parallel_unsequenced_policy(__disable_user_instantiations_tag) {} |
| 71 | parallel_unsequenced_policy(const parallel_unsequenced_policy&) = delete; |
| 72 | parallel_unsequenced_policy& operator=(const parallel_unsequenced_policy&) = delete; |
| 73 | }; |
| 74 | |
| 75 | inline constexpr parallel_unsequenced_policy par_unseq{__disable_user_instantiations_tag{}}; |
| 76 | |
| 77 | struct __unsequenced_policy { |
| 78 | _LIBCPP_HIDE_FROM_ABI constexpr explicit __unsequenced_policy(__disable_user_instantiations_tag) {} |
| 79 | __unsequenced_policy(const __unsequenced_policy&) = delete; |
| 80 | __unsequenced_policy& operator=(const __unsequenced_policy&) = delete; |
| 81 | }; |
| 82 | |
| 83 | constexpr __unsequenced_policy __unseq{__disable_user_instantiations_tag{}}; |
| 84 | |
| 85 | # if _LIBCPP_STD_VER >= 20 |
| 86 | |
| 87 | struct unsequenced_policy { |
| 88 | _LIBCPP_HIDE_FROM_ABI constexpr explicit unsequenced_policy(__disable_user_instantiations_tag) {} |
| 89 | unsequenced_policy(const unsequenced_policy&) = delete; |
| 90 | unsequenced_policy& operator=(const unsequenced_policy&) = delete; |
| 91 | }; |
| 92 | |
| 93 | inline constexpr unsequenced_policy unseq{__disable_user_instantiations_tag{}}; |
| 94 | |
| 95 | # endif // _LIBCPP_STD_VER >= 20 |
| 96 | |
| 97 | } // namespace execution |
| 98 | |
| 99 | _LIBCPP_DIAGNOSTIC_PUSH |
| 100 | # if __has_warning("-Winvalid-specialization") |
| 101 | _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Winvalid-specialization") |
| 102 | # endif |
| 103 | template <> |
| 104 | inline constexpr bool is_execution_policy_v<execution::sequenced_policy> = true; |
| 105 | |
| 106 | template <> |
| 107 | inline constexpr bool is_execution_policy_v<execution::parallel_policy> = true; |
| 108 | |
| 109 | template <> |
| 110 | inline constexpr bool is_execution_policy_v<execution::parallel_unsequenced_policy> = true; |
| 111 | |
| 112 | template <> |
| 113 | inline constexpr bool is_execution_policy_v<execution::__unsequenced_policy> = true; |
| 114 | _LIBCPP_DIAGNOSTIC_POP |
| 115 | |
| 116 | template <> |
| 117 | inline constexpr bool __is_parallel_execution_policy_impl<execution::parallel_policy> = true; |
| 118 | |
| 119 | template <> |
| 120 | inline constexpr bool __is_parallel_execution_policy_impl<execution::parallel_unsequenced_policy> = true; |
| 121 | |
| 122 | template <> |
| 123 | inline constexpr bool __is_unsequenced_execution_policy_impl<execution::__unsequenced_policy> = true; |
| 124 | |
| 125 | template <> |
| 126 | inline constexpr bool __is_unsequenced_execution_policy_impl<execution::parallel_unsequenced_policy> = true; |
| 127 | |
| 128 | # if _LIBCPP_STD_VER >= 20 |
| 129 | _LIBCPP_DIAGNOSTIC_PUSH |
| 130 | # if __has_warning("-Winvalid-specialization") |
| 131 | _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Winvalid-specialization") |
| 132 | # endif |
| 133 | template <> |
| 134 | inline constexpr bool is_execution_policy_v<execution::unsequenced_policy> = true; |
| 135 | _LIBCPP_DIAGNOSTIC_POP |
| 136 | |
| 137 | template <> |
| 138 | inline constexpr bool __is_unsequenced_execution_policy_impl<execution::unsequenced_policy> = true; |
| 139 | |
| 140 | # endif |
| 141 | |
| 142 | template <class _Tp> |
| 143 | struct _LIBCPP_NO_SPECIALIZATIONS is_execution_policy : bool_constant<is_execution_policy_v<_Tp>> {}; |
| 144 | |
| 145 | template <class _ExecutionPolicy> |
| 146 | _LIBCPP_HIDE_FROM_ABI auto __remove_parallel_policy(const _ExecutionPolicy&) { |
| 147 | if constexpr (is_same_v<_ExecutionPolicy, execution::parallel_policy>) { |
| 148 | return execution::sequenced_policy(execution::__disable_user_instantiations_tag{}); |
| 149 | } else if constexpr (is_same_v<_ExecutionPolicy, execution::parallel_unsequenced_policy>) { |
| 150 | return execution::__unsequenced_policy{execution::__disable_user_instantiations_tag{}}; |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | _LIBCPP_END_NAMESPACE_STD |
| 155 | |
| 156 | # endif // _LIBCPP_HAS_EXPERIMENTAL_PSTL && _LIBCPP_STD_VER >= 17 |
| 157 | |
| 158 | # if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 |
| 159 | # include <cstddef> |
| 160 | # endif |
| 161 | #endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS) |
| 162 | |
| 163 | #endif // _LIBCPP_EXECUTION |