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 | #include <__config> |
36 | #include <__type_traits/is_execution_policy.h> |
37 | #include <__type_traits/is_same.h> |
38 | #include <__type_traits/remove_cvref.h> |
39 | #include <version> |
40 | |
41 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
42 | # pragma GCC system_header |
43 | #endif |
44 | |
45 | #if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17 |
46 | |
47 | _LIBCPP_BEGIN_NAMESPACE_STD |
48 | |
49 | namespace execution { |
50 | struct sequenced_policy { |
51 | _LIBCPP_HIDE_FROM_ABI constexpr explicit sequenced_policy(__disable_user_instantiations_tag) {} |
52 | sequenced_policy(const sequenced_policy&) = delete; |
53 | sequenced_policy& operator=(const sequenced_policy&) = delete; |
54 | }; |
55 | |
56 | inline constexpr sequenced_policy seq{__disable_user_instantiations_tag{}}; |
57 | |
58 | struct parallel_policy { |
59 | _LIBCPP_HIDE_FROM_ABI constexpr explicit parallel_policy(__disable_user_instantiations_tag) {} |
60 | parallel_policy(const parallel_policy&) = delete; |
61 | parallel_policy& operator=(const parallel_policy&) = delete; |
62 | }; |
63 | |
64 | inline constexpr parallel_policy par{__disable_user_instantiations_tag{}}; |
65 | |
66 | struct parallel_unsequenced_policy { |
67 | _LIBCPP_HIDE_FROM_ABI constexpr explicit parallel_unsequenced_policy(__disable_user_instantiations_tag) {} |
68 | parallel_unsequenced_policy(const parallel_unsequenced_policy&) = delete; |
69 | parallel_unsequenced_policy& operator=(const parallel_unsequenced_policy&) = delete; |
70 | }; |
71 | |
72 | inline constexpr parallel_unsequenced_policy par_unseq{__disable_user_instantiations_tag{}}; |
73 | |
74 | struct __unsequenced_policy { |
75 | _LIBCPP_HIDE_FROM_ABI constexpr explicit __unsequenced_policy(__disable_user_instantiations_tag) {} |
76 | __unsequenced_policy(const __unsequenced_policy&) = delete; |
77 | __unsequenced_policy& operator=(const __unsequenced_policy&) = delete; |
78 | }; |
79 | |
80 | constexpr __unsequenced_policy __unseq{__disable_user_instantiations_tag{}}; |
81 | |
82 | # if _LIBCPP_STD_VER >= 20 |
83 | |
84 | struct unsequenced_policy { |
85 | _LIBCPP_HIDE_FROM_ABI constexpr explicit unsequenced_policy(__disable_user_instantiations_tag) {} |
86 | unsequenced_policy(const unsequenced_policy&) = delete; |
87 | unsequenced_policy& operator=(const unsequenced_policy&) = delete; |
88 | }; |
89 | |
90 | inline constexpr unsequenced_policy unseq{__disable_user_instantiations_tag{}}; |
91 | |
92 | # endif // _LIBCPP_STD_VER >= 20 |
93 | |
94 | } // namespace execution |
95 | |
96 | template <> |
97 | inline constexpr bool is_execution_policy_v<execution::sequenced_policy> = true; |
98 | |
99 | template <> |
100 | inline constexpr bool is_execution_policy_v<execution::parallel_policy> = true; |
101 | |
102 | template <> |
103 | inline constexpr bool is_execution_policy_v<execution::parallel_unsequenced_policy> = true; |
104 | |
105 | template <> |
106 | inline constexpr bool is_execution_policy_v<execution::__unsequenced_policy> = true; |
107 | |
108 | template <> |
109 | inline constexpr bool __is_parallel_execution_policy_impl<execution::parallel_policy> = true; |
110 | |
111 | template <> |
112 | inline constexpr bool __is_parallel_execution_policy_impl<execution::parallel_unsequenced_policy> = true; |
113 | |
114 | template <> |
115 | inline constexpr bool __is_unsequenced_execution_policy_impl<execution::__unsequenced_policy> = true; |
116 | |
117 | template <> |
118 | inline constexpr bool __is_unsequenced_execution_policy_impl<execution::parallel_unsequenced_policy> = true; |
119 | |
120 | # if _LIBCPP_STD_VER >= 20 |
121 | template <> |
122 | inline constexpr bool is_execution_policy_v<execution::unsequenced_policy> = true; |
123 | |
124 | template <> |
125 | inline constexpr bool __is_unsequenced_execution_policy_impl<execution::unsequenced_policy> = true; |
126 | |
127 | # endif |
128 | |
129 | template <class _Tp> |
130 | struct is_execution_policy : bool_constant<is_execution_policy_v<_Tp>> {}; |
131 | |
132 | template <class _ExecutionPolicy> |
133 | _LIBCPP_HIDE_FROM_ABI auto __remove_parallel_policy(const _ExecutionPolicy&) { |
134 | if constexpr (is_same_v<_ExecutionPolicy, execution::parallel_policy>) { |
135 | return execution::sequenced_policy(execution::__disable_user_instantiations_tag{}); |
136 | } else if constexpr (is_same_v<_ExecutionPolicy, execution::parallel_unsequenced_policy>) { |
137 | return execution::__unsequenced_policy{execution::__disable_user_instantiations_tag{}}; |
138 | } |
139 | } |
140 | |
141 | _LIBCPP_END_NAMESPACE_STD |
142 | |
143 | #endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17 |
144 | |
145 | #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 |
146 | # include <cstddef> |
147 | #endif |
148 | |
149 | #endif // _LIBCPP_EXECUTION |
150 | |