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