xref: /llvm-project/pstl/include/pstl/internal/execution_defs.h (revision 843c12d6a0cdfd64c5a92e24eb58ba9ee17ca1ee)
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 _PSTL_EXECUTION_POLICY_DEFS_H
11 #define _PSTL_EXECUTION_POLICY_DEFS_H
12 
13 #include <type_traits>
14 
15 #include "pstl_config.h"
16 
17 _PSTL_HIDE_FROM_ABI_PUSH
18 
19 namespace __pstl
20 {
21 namespace execution
22 {
23 inline namespace v1
24 {
25 
26 // 2.4, Sequential execution policy
27 class sequenced_policy
28 {
29 };
30 
31 // 2.5, Parallel execution policy
32 class parallel_policy
33 {
34 };
35 
36 // 2.6, Parallel+Vector execution policy
37 class parallel_unsequenced_policy
38 {
39 };
40 
41 class unsequenced_policy
42 {
43 };
44 
45 // 2.8, Execution policy objects
46 constexpr sequenced_policy seq{};
47 constexpr parallel_policy par{};
48 constexpr parallel_unsequenced_policy par_unseq{};
49 constexpr unsequenced_policy unseq{};
50 
51 // 2.3, Execution policy type trait
52 template <class T>
53 struct is_execution_policy : std::false_type
54 {
55 };
56 
57 template <>
58 struct is_execution_policy<__pstl::execution::sequenced_policy> : std::true_type
59 {
60 };
61 template <>
62 struct is_execution_policy<__pstl::execution::parallel_policy> : std::true_type
63 {
64 };
65 template <>
66 struct is_execution_policy<__pstl::execution::parallel_unsequenced_policy> : std::true_type
67 {
68 };
69 template <>
70 struct is_execution_policy<__pstl::execution::unsequenced_policy> : std::true_type
71 {
72 };
73 
74 #if defined(_PSTL_CPP14_VARIABLE_TEMPLATES_PRESENT)
75 template <class T>
76 constexpr bool is_execution_policy_v = __pstl::execution::is_execution_policy<T>::value;
77 #endif
78 
79 } // namespace v1
80 } // namespace execution
81 
82 namespace __internal
83 {
84 template <class ExecPolicy, class T>
85 using __enable_if_execution_policy =
86     typename std::enable_if<__pstl::execution::is_execution_policy<typename std::decay<ExecPolicy>::type>::value,
87                             T>::type;
88 
89 template <class _IsVector>
90 struct __serial_tag;
91 template <class _IsVector>
92 struct __parallel_tag;
93 
94 } // namespace __internal
95 
96 } // namespace __pstl
97 
98 _PSTL_HIDE_FROM_ABI_POP
99 
100 #endif /* _PSTL_EXECUTION_POLICY_DEFS_H */
101