1e40139ffSDimitry Andric// -*- C++ -*-
2349cc55cSDimitry Andric//===----------------------------------------------------------------------===//
3e40139ffSDimitry Andric//
4e40139ffSDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5e40139ffSDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
6e40139ffSDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7e40139ffSDimitry Andric//
8e40139ffSDimitry Andric//===----------------------------------------------------------------------===//
9e40139ffSDimitry Andric
10e40139ffSDimitry Andric#ifndef _LIBCPP_EXECUTION
11e40139ffSDimitry Andric#define _LIBCPP_EXECUTION
12e40139ffSDimitry Andric
13*fe013be4SDimitry Andric/*
14*fe013be4SDimitry Andricnamespace std::execution {
15*fe013be4SDimitry Andric  struct sequenced_policy;
16*fe013be4SDimitry Andric  struct parallel_policy;
17*fe013be4SDimitry Andric  struct parallel_unsequenced_policy;
18*fe013be4SDimitry Andric  struct unsequenced_policy; // since C++20
19*fe013be4SDimitry Andric
20*fe013be4SDimitry Andric  inline constexpr sequenced_policy seq = implementation-defined;
21*fe013be4SDimitry Andric  inline constexpr parallel_policy par = implementation-defined;
22*fe013be4SDimitry Andric  inline constexpr parallel_unsequenced_policy par_unseq = implementation-defined;
23*fe013be4SDimitry Andric  inline constexpr unsequenced_policy unseq = implementation-defined; // since C++20
24*fe013be4SDimitry Andric}
25*fe013be4SDimitry Andric
26*fe013be4SDimitry Andricnamespace std {
27*fe013be4SDimitry Andric  template <class T>
28*fe013be4SDimitry Andric  struct is_execution_policy;
29*fe013be4SDimitry Andric
30*fe013be4SDimitry Andric  template <class T>
31*fe013be4SDimitry Andric  inline constexpr bool is_execution_policy_v;
32*fe013be4SDimitry Andric}
33*fe013be4SDimitry Andric*/
34*fe013be4SDimitry Andric
3581ad6265SDimitry Andric#include <__assert> // all public C++ headers provide the assertion handler
36e40139ffSDimitry Andric#include <__config>
37*fe013be4SDimitry Andric#include <__type_traits/is_execution_policy.h>
38*fe013be4SDimitry Andric#include <__type_traits/is_same.h>
39*fe013be4SDimitry Andric#include <__type_traits/remove_cvref.h>
4004eeddc0SDimitry Andric#include <version>
41e40139ffSDimitry Andric
420eae32dcSDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
430eae32dcSDimitry Andric#  pragma GCC system_header
440eae32dcSDimitry Andric#endif
450eae32dcSDimitry Andric
46*fe013be4SDimitry Andric#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
47*fe013be4SDimitry Andric
48*fe013be4SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD
49*fe013be4SDimitry Andric
50*fe013be4SDimitry Andricnamespace execution {
51*fe013be4SDimitry Andricstruct sequenced_policy {
52*fe013be4SDimitry Andric  _LIBCPP_HIDE_FROM_ABI constexpr explicit sequenced_policy(__disable_user_instantiations_tag) {}
53*fe013be4SDimitry Andric  sequenced_policy(const sequenced_policy&)            = delete;
54*fe013be4SDimitry Andric  sequenced_policy& operator=(const sequenced_policy&) = delete;
55*fe013be4SDimitry Andric};
56*fe013be4SDimitry Andric
57*fe013be4SDimitry Andricinline constexpr sequenced_policy seq{__disable_user_instantiations_tag{}};
58*fe013be4SDimitry Andric
59*fe013be4SDimitry Andricstruct parallel_policy {
60*fe013be4SDimitry Andric  _LIBCPP_HIDE_FROM_ABI constexpr explicit parallel_policy(__disable_user_instantiations_tag) {}
61*fe013be4SDimitry Andric  parallel_policy(const parallel_policy&)            = delete;
62*fe013be4SDimitry Andric  parallel_policy& operator=(const parallel_policy&) = delete;
63*fe013be4SDimitry Andric};
64*fe013be4SDimitry Andric
65*fe013be4SDimitry Andricinline constexpr parallel_policy par{__disable_user_instantiations_tag{}};
66*fe013be4SDimitry Andric
67*fe013be4SDimitry Andricstruct parallel_unsequenced_policy {
68*fe013be4SDimitry Andric  _LIBCPP_HIDE_FROM_ABI constexpr explicit parallel_unsequenced_policy(__disable_user_instantiations_tag) {}
69*fe013be4SDimitry Andric  parallel_unsequenced_policy(const parallel_unsequenced_policy&)            = delete;
70*fe013be4SDimitry Andric  parallel_unsequenced_policy& operator=(const parallel_unsequenced_policy&) = delete;
71*fe013be4SDimitry Andric};
72*fe013be4SDimitry Andric
73*fe013be4SDimitry Andricinline constexpr parallel_unsequenced_policy par_unseq{__disable_user_instantiations_tag{}};
74*fe013be4SDimitry Andric
75*fe013be4SDimitry Andricstruct __unsequenced_policy {
76*fe013be4SDimitry Andric  _LIBCPP_HIDE_FROM_ABI constexpr explicit __unsequenced_policy(__disable_user_instantiations_tag) {}
77*fe013be4SDimitry Andric  __unsequenced_policy(const __unsequenced_policy&)            = delete;
78*fe013be4SDimitry Andric  __unsequenced_policy& operator=(const __unsequenced_policy&) = delete;
79*fe013be4SDimitry Andric};
80*fe013be4SDimitry Andric
81*fe013be4SDimitry Andricconstexpr __unsequenced_policy __unseq{__disable_user_instantiations_tag{}};
82*fe013be4SDimitry Andric
83*fe013be4SDimitry Andric#  if _LIBCPP_STD_VER >= 20
84*fe013be4SDimitry Andric
85*fe013be4SDimitry Andricstruct unsequenced_policy {
86*fe013be4SDimitry Andric  _LIBCPP_HIDE_FROM_ABI constexpr explicit unsequenced_policy(__disable_user_instantiations_tag) {}
87*fe013be4SDimitry Andric  unsequenced_policy(const unsequenced_policy&)            = delete;
88*fe013be4SDimitry Andric  unsequenced_policy& operator=(const unsequenced_policy&) = delete;
89*fe013be4SDimitry Andric};
90*fe013be4SDimitry Andric
91*fe013be4SDimitry Andricinline constexpr unsequenced_policy unseq{__disable_user_instantiations_tag{}};
92*fe013be4SDimitry Andric
93*fe013be4SDimitry Andric#  endif // _LIBCPP_STD_VER >= 20
94*fe013be4SDimitry Andric
95*fe013be4SDimitry Andric} // namespace execution
96*fe013be4SDimitry Andric
97*fe013be4SDimitry Andrictemplate <>
98*fe013be4SDimitry Andricinline constexpr bool is_execution_policy_v<execution::sequenced_policy> = true;
99*fe013be4SDimitry Andric
100*fe013be4SDimitry Andrictemplate <>
101*fe013be4SDimitry Andricinline constexpr bool is_execution_policy_v<execution::parallel_policy> = true;
102*fe013be4SDimitry Andric
103*fe013be4SDimitry Andrictemplate <>
104*fe013be4SDimitry Andricinline constexpr bool is_execution_policy_v<execution::parallel_unsequenced_policy> = true;
105*fe013be4SDimitry Andric
106*fe013be4SDimitry Andrictemplate <>
107*fe013be4SDimitry Andricinline constexpr bool is_execution_policy_v<execution::__unsequenced_policy> = true;
108*fe013be4SDimitry Andric
109*fe013be4SDimitry Andrictemplate <>
110*fe013be4SDimitry Andricinline constexpr bool __is_parallel_execution_policy_impl<execution::parallel_policy> = true;
111*fe013be4SDimitry Andric
112*fe013be4SDimitry Andrictemplate <>
113*fe013be4SDimitry Andricinline constexpr bool __is_parallel_execution_policy_impl<execution::parallel_unsequenced_policy> = true;
114*fe013be4SDimitry Andric
115*fe013be4SDimitry Andrictemplate <>
116*fe013be4SDimitry Andricinline constexpr bool __is_unsequenced_execution_policy_impl<execution::__unsequenced_policy> = true;
117*fe013be4SDimitry Andric
118*fe013be4SDimitry Andrictemplate <>
119*fe013be4SDimitry Andricinline constexpr bool __is_unsequenced_execution_policy_impl<execution::parallel_unsequenced_policy> = true;
120*fe013be4SDimitry Andric
121*fe013be4SDimitry Andric#  if _LIBCPP_STD_VER >= 20
122*fe013be4SDimitry Andrictemplate <>
123*fe013be4SDimitry Andricinline constexpr bool is_execution_policy_v<execution::unsequenced_policy> = true;
124*fe013be4SDimitry Andric
125*fe013be4SDimitry Andrictemplate <>
126*fe013be4SDimitry Andricinline constexpr bool __is_unsequenced_execution_policy_impl<execution::unsequenced_policy> = true;
127*fe013be4SDimitry Andric
128*fe013be4SDimitry Andric#  endif
129*fe013be4SDimitry Andric
130*fe013be4SDimitry Andrictemplate <class _Tp>
131*fe013be4SDimitry Andricstruct is_execution_policy : bool_constant<is_execution_policy_v<_Tp>> {};
132*fe013be4SDimitry Andric
133*fe013be4SDimitry Andrictemplate <class _ExecutionPolicy>
134*fe013be4SDimitry Andric_LIBCPP_HIDE_FROM_ABI auto __remove_parallel_policy(const _ExecutionPolicy&) {
135*fe013be4SDimitry Andric  if constexpr (is_same_v<_ExecutionPolicy, execution::parallel_policy>) {
136*fe013be4SDimitry Andric    return execution::sequenced_policy(execution::__disable_user_instantiations_tag{});
137*fe013be4SDimitry Andric  } else if constexpr (is_same_v<_ExecutionPolicy, execution::parallel_unsequenced_policy>) {
138*fe013be4SDimitry Andric    return execution::__unsequenced_policy{execution::__disable_user_instantiations_tag{}};
139*fe013be4SDimitry Andric  }
140*fe013be4SDimitry Andric}
141*fe013be4SDimitry Andric
142*fe013be4SDimitry Andric_LIBCPP_END_NAMESPACE_STD
143*fe013be4SDimitry Andric
144*fe013be4SDimitry Andric#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
145*fe013be4SDimitry Andric
146e40139ffSDimitry Andric#endif // _LIBCPP_EXECUTION
147