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};
26
27// 2.5, Parallel execution policy
28class parallel_policy
29{
30};
31
32// 2.6, Parallel+Vector execution policy
33class parallel_unsequenced_policy
34{
35};
36
37class unsequenced_policy
38{
39};
40
41// 2.8, Execution policy objects
42_GLIBCXX17_INLINE constexpr sequenced_policy seq{};
43_GLIBCXX17_INLINE constexpr parallel_policy par{};
44_GLIBCXX17_INLINE constexpr parallel_unsequenced_policy par_unseq{};
45_GLIBCXX17_INLINE constexpr unsequenced_policy unseq{};
46
47// 2.3, Execution policy type trait
48template <class _Tp>
49struct is_execution_policy : std::false_type
50{
51};
52
53template <>
54struct is_execution_policy<__pstl::execution::sequenced_policy> : std::true_type
55{
56};
57template <>
58struct is_execution_policy<__pstl::execution::parallel_policy> : std::true_type
59{
60};
61template <>
62struct is_execution_policy<__pstl::execution::parallel_unsequenced_policy> : std::true_type
63{
64};
65template <>
66struct is_execution_policy<__pstl::execution::unsequenced_policy> : std::true_type
67{
68};
69
70#if defined (_PSTL_CPP14_VARIABLE_TEMPLATES_PRESENT)
71template <class _Tp>
72constexpr bool is_execution_policy_v = __pstl::execution::is_execution_policy<_Tp>::value;
73#endif
74
75} // namespace v1
76} // namespace execution
77
78namespace __internal
79{
80template <class _ExecPolicy, class _Tp>
81#if _GLIBCXX_RELEASE >= 9
82using __enable_if_execution_policy =
83 typename std::enable_if<__pstl::execution::is_execution_policy<std::__remove_cvref_t<_ExecPolicy>>::value,
84 _Tp>::type;
85#else
86using __enable_if_execution_policy =
87 typename std::enable_if<__pstl::execution::is_execution_policy<typename std::decay<_ExecPolicy>::type>::value,
88 _Tp>::type;
89#endif
90
91template <class _IsVector>
92struct __serial_tag;
93template <class _IsVector>
94struct __parallel_tag;
95
96} // namespace __internal
97
98} // namespace __pstl
99
100#endif /* _PSTL_EXECUTION_POLICY_DEFS_H */
101