1 /* 2 * Copyright (c) 2025 Lucian Radu Teodorescu 3 * 4 * Licensed under the Apache License Version 2.0 with LLVM Exceptions 5 * (the "License"); you may not use this file except in compliance with 6 * the License. You may obtain a copy of the License at 7 * 8 * https://llvm.org/LICENSE.txt 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #pragma once 17 18 #include "__config.hpp" 19 20 #if STDEXEC_HAS_EXECUTION_POLICY() 21 # include <execution> 22 #endif 23 24 namespace stdexec { 25 26 #if STDEXEC_HAS_EXECUTION_POLICY() 27 28 using sequenced_policy = std::execution::sequenced_policy; 29 using parallel_policy = std::execution::parallel_policy; 30 using parallel_unsequenced_policy = std::execution::parallel_unsequenced_policy; 31 32 constexpr auto seq = std::execution::seq; 33 constexpr auto par = std::execution::par; 34 constexpr auto par_unseq = std::execution::par_unseq; 35 36 using std::is_execution_policy_v; 37 using std::is_execution_policy; 38 39 #else 40 41 struct __hidden_construction { }; 42 43 struct sequenced_policy { 44 constexpr explicit sequenced_policy(__hidden_construction) { }; 45 sequenced_policy(const sequenced_policy&) = delete; 46 sequenced_policy& operator=(const sequenced_policy&) = delete; 47 }; 48 49 struct parallel_policy { 50 constexpr explicit parallel_policy(__hidden_construction) { }; 51 parallel_policy(const parallel_policy&) = delete; 52 parallel_policy& operator=(const parallel_policy&) = delete; 53 }; 54 55 struct parallel_unsequenced_policy { 56 constexpr explicit parallel_unsequenced_policy(__hidden_construction) { }; 57 parallel_unsequenced_policy(const parallel_unsequenced_policy&) = delete; 58 parallel_unsequenced_policy& operator=(const parallel_unsequenced_policy&) = delete; 59 }; 60 61 inline constexpr sequenced_policy seq{__hidden_construction{}}; 62 inline constexpr parallel_policy par{__hidden_construction{}}; 63 inline constexpr parallel_unsequenced_policy par_unseq{__hidden_construction{}}; 64 65 template <typename> 66 inline constexpr bool is_execution_policy_v = false; 67 68 template <> 69 inline constexpr bool is_execution_policy_v<sequenced_policy> = true; 70 71 template <> 72 inline constexpr bool is_execution_policy_v<parallel_policy> = true; 73 74 template <> 75 inline constexpr bool is_execution_policy_v<parallel_unsequenced_policy> = true; 76 77 template <class _T> 78 struct is_execution_policy : std::bool_constant<is_execution_policy_v<_T>> { }; 79 80 #endif 81 82 #if STDEXEC_HAS_UNSEQUENCED_EXECUTION_POLICY() 83 84 using unsequenced_policy = std::execution::unsequenced_policy; 85 86 constexpr auto unseq = std::execution::unseq; 87 88 #else 89 90 # if STDEXEC_HAS_EXECUTION_POLICY() 91 // already defined above 92 struct __hidden_construction { }; 93 # endif 94 95 struct unsequenced_policy { unsequenced_policystdexec::unsequenced_policy96 constexpr explicit unsequenced_policy(__hidden_construction) { }; 97 unsequenced_policy(const unsequenced_policy&) = delete; 98 unsequenced_policy& operator=(const unsequenced_policy&) = delete; 99 }; 100 101 inline constexpr unsequenced_policy unseq{__hidden_construction{}}; 102 103 template <> 104 inline constexpr bool is_execution_policy_v<unsequenced_policy> = true; 105 106 #endif 107 108 } // namespace stdexec