1// -*- C++ -*-
2//===-- execution_defs.h --------------------------------------------------===//
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 _PSTL_EXECUTION_POLICY_DEFS_H
11#define _PSTL_EXECUTION_POLICY_DEFS_H
12
13#include <type_traits>
14
15namespace __pstl
16{
17namespace execution
18{
19inline namespace v1
20{
21
22// 2.4, Sequential execution policy
23class sequenced_policy
24{
25 public:
26 // For internal use only
27 static constexpr std::false_type
28 __allow_unsequenced()
29 {
30 return std::false_type{};
31 }
32 static constexpr std::false_type
33 __allow_vector()
34 {
35 return std::false_type{};
36 }
37 static constexpr std::false_type
38 __allow_parallel()
39 {
40 return std::false_type{};
41 }
42};
43
44// 2.5, Parallel execution policy
45class parallel_policy
46{
47 public:
48 // For internal use only
49 static constexpr std::false_type
50 __allow_unsequenced()
51 {
52 return std::false_type{};
53 }
54 static constexpr std::false_type
55 __allow_vector()
56 {
57 return std::false_type{};
58 }
59 static constexpr std::true_type
60 __allow_parallel()
61 {
62 return std::true_type{};
63 }
64};
65
66// 2.6, Parallel+Vector execution policy
67class parallel_unsequenced_policy
68{
69 public:
70 // For internal use only
71 static constexpr std::true_type
72 __allow_unsequenced()
73 {
74 return std::true_type{};
75 }
76 static constexpr std::true_type
77 __allow_vector()
78 {
79 return std::true_type{};
80 }
81 static constexpr std::true_type
82 __allow_parallel()
83 {
84 return std::true_type{};
85 }
86};
87
88class unsequenced_policy
89{
90 public:
91 // For internal use only
92 static constexpr std::true_type
93 __allow_unsequenced()
94 {
95 return std::true_type{};
96 }
97 static constexpr std::true_type
98 __allow_vector()
99 {
100 return std::true_type{};
101 }
102 static constexpr std::false_type
103 __allow_parallel()
104 {
105 return std::false_type{};
106 }
107};
108
109// 2.8, Execution policy objects
110constexpr sequenced_policy seq{};
111constexpr parallel_policy par{};
112constexpr parallel_unsequenced_policy par_unseq{};
113constexpr unsequenced_policy unseq{};
114
115// 2.3, Execution policy type trait
116template <class _Tp>
117struct is_execution_policy : std::false_type
118{
119};
120
121template <>
122struct is_execution_policy<__pstl::execution::sequenced_policy> : std::true_type
123{
124};
125template <>
126struct is_execution_policy<__pstl::execution::parallel_policy> : std::true_type
127{
128};
129template <>
130struct is_execution_policy<__pstl::execution::parallel_unsequenced_policy> : std::true_type
131{
132};
133template <>
134struct is_execution_policy<__pstl::execution::unsequenced_policy> : std::true_type
135{
136};
137
138#if _PSTL_CPP14_VARIABLE_TEMPLATES_PRESENT
139template <class _Tp>
140constexpr bool is_execution_policy_v = __pstl::execution::is_execution_policy<_Tp>::value;
141#endif
142
143} // namespace v1
144} // namespace execution
145
146namespace __internal
147{
148template <class _ExecPolicy, class _Tp>
149#if _GLIBCXX_RELEASE >= 9
150using __enable_if_execution_policy =
151 typename std::enable_if<__pstl::execution::is_execution_policy<std::__remove_cvref_t<_ExecPolicy>>::value,
152 _Tp>::type;
153#else
154using __enable_if_execution_policy =
155 typename std::enable_if<__pstl::execution::is_execution_policy<typename std::decay<_ExecPolicy>::type>::value,
156 _Tp>::type;
157#endif
158} // namespace __internal
159
160} // namespace __pstl
161
162#endif /* _PSTL_EXECUTION_POLICY_DEFS_H */
163