Clementine
executor.hpp
1 //
2 // execution/executor.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2020 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 //
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 //
10 
11 #ifndef ASIO_EXECUTION_EXECUTOR_HPP
12 #define ASIO_EXECUTION_EXECUTOR_HPP
13 
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17 
18 #include "asio/detail/config.hpp"
19 #include "asio/detail/type_traits.hpp"
20 #include "asio/execution/execute.hpp"
21 #include "asio/execution/invocable_archetype.hpp"
22 #include "asio/traits/equality_comparable.hpp"
23 
24 #if defined(ASIO_HAS_DEDUCED_EXECUTE_FREE_TRAIT) \
25  && defined(ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT) \
26  && defined(ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
27 # define ASIO_HAS_DEDUCED_EXECUTION_IS_EXECUTOR_TRAIT 1
28 #endif // defined(ASIO_HAS_DEDUCED_EXECUTE_FREE_TRAIT)
29  // && defined(ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
30  // && defined(ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
31 
32 #include "asio/detail/push_options.hpp"
33 
34 namespace asio {
35 namespace execution {
36 namespace detail {
37 
38 template <typename T, typename F>
40  integral_constant<bool,
41  conditional<true, true_type,
42  typename result_of<typename decay<F>::type&()>::type
43  >::type::value
44  && is_constructible<typename decay<F>::type, F>::value
45  && is_move_constructible<typename decay<F>::type>::value
46 #if defined(ASIO_HAS_NOEXCEPT)
47  && is_nothrow_copy_constructible<T>::value
48  && is_nothrow_destructible<T>::value
49 #else // defined(ASIO_HAS_NOEXCEPT)
50  && is_copy_constructible<T>::value
51  && is_destructible<T>::value
52 #endif // defined(ASIO_HAS_NOEXCEPT)
53  && traits::equality_comparable<T>::is_valid
54  && traits::equality_comparable<T>::is_noexcept
55  >
56 {
57 };
58 
59 template <typename T, typename F>
61  conditional<
62  can_execute<typename add_const<T>::type, F>::value,
63  is_executor_of_impl_base<T, F>,
64  false_type
65  >::type
66 {
67 };
68 
69 template <typename T, typename = void>
71 {
72  typedef std::size_t type;
73 };
74 
75 template <typename T>
76 struct executor_shape<T,
77  typename void_type<
78  typename T::shape_type
79  >::type>
80 {
81  typedef typename T::shape_type type;
82 };
83 
84 template <typename T, typename Default, typename = void>
86 {
87  typedef Default type;
88 };
89 
90 template <typename T, typename Default>
91 struct executor_index<T, Default,
92  typename void_type<
93  typename T::index_type
94  >::type>
95 {
96  typedef typename T::index_type type;
97 };
98 
99 } // namespace detail
100 
103 
108 template <typename T>
109 struct is_executor :
110 #if defined(GENERATING_DOCUMENTATION)
111  integral_constant<bool, automatically_determined>
112 #else // defined(GENERATING_DOCUMENTATION)
113  detail::is_executor_of_impl<T, invocable_archetype>
114 #endif // defined(GENERATING_DOCUMENTATION)
115 {
116 };
117 
118 #if defined(ASIO_HAS_VARIABLE_TEMPLATES)
119 
120 template <typename T>
121 ASIO_CONSTEXPR const bool is_executor_v = is_executor<T>::value;
122 
123 #endif // defined(ASIO_HAS_VARIABLE_TEMPLATES)
124 
125 #if defined(ASIO_HAS_CONCEPTS)
126 
127 template <typename T>
128 ASIO_CONCEPT executor = is_executor<T>::value;
129 
130 #define ASIO_EXECUTION_EXECUTOR ::asio::execution::executor
131 
132 #else // defined(ASIO_HAS_CONCEPTS)
133 
134 #define ASIO_EXECUTION_EXECUTOR typename
135 
136 #endif // defined(ASIO_HAS_CONCEPTS)
137 
140 
146 template <typename T, typename F>
148 #if defined(GENERATING_DOCUMENTATION)
149  integral_constant<bool, automatically_determined>
150 #else // defined(GENERATING_DOCUMENTATION)
151  integral_constant<bool,
152  is_executor<T>::value && detail::is_executor_of_impl<T, F>::value
153  >
154 #endif // defined(GENERATING_DOCUMENTATION)
155 {
156 };
157 
158 #if defined(ASIO_HAS_VARIABLE_TEMPLATES)
159 
160 template <typename T, typename F>
161 ASIO_CONSTEXPR const bool is_executor_of_v =
163 
164 #endif // defined(ASIO_HAS_VARIABLE_TEMPLATES)
165 
166 #if defined(ASIO_HAS_CONCEPTS)
167 
168 template <typename T, typename F>
169 ASIO_CONCEPT executor_of = is_executor_of<T, F>::value;
170 
171 #define ASIO_EXECUTION_EXECUTOR_OF(f) \
172  ::asio::execution::executor_of<f>
173 
174 #else // defined(ASIO_HAS_CONCEPTS)
175 
176 #define ASIO_EXECUTION_EXECUTOR_OF typename
177 
178 #endif // defined(ASIO_HAS_CONCEPTS)
179 
182 
187 template <typename T>
189 #if !defined(GENERATING_DOCUMENTATION)
191 #endif // !defined(GENERATING_DOCUMENTATION)
192 {
193 #if defined(GENERATING_DOCUMENTATION)
194  typedef automatically_determined type;
196 #endif // defined(GENERATING_DOCUMENTATION)
197 };
198 
199 #if defined(ASIO_HAS_ALIAS_TEMPLATES)
200 
201 template <typename T>
202 using executor_shape_t = typename executor_shape<T>::type;
203 
204 #endif // defined(ASIO_HAS_ALIAS_TEMPLATES)
205 
208 
213 template <typename T>
215 #if !defined(GENERATING_DOCUMENTATION)
216  : detail::executor_index<T, typename executor_shape<T>::type>
217 #endif // !defined(GENERATING_DOCUMENTATION)
218 {
219 #if defined(GENERATING_DOCUMENTATION)
220  typedef automatically_determined type;
223 #endif // defined(GENERATING_DOCUMENTATION)
224 };
225 
226 #if defined(ASIO_HAS_ALIAS_TEMPLATES)
227 
228 template <typename T>
229 using executor_index_t = typename executor_index<T>::type;
230 
231 #endif // defined(ASIO_HAS_ALIAS_TEMPLATES)
232 
233 } // namespace execution
234 } // namespace asio
235 
236 #include "asio/detail/pop_options.hpp"
237 
238 #endif // ASIO_EXECUTION_EXECUTOR_HPP
Definition: type_traits.hpp:135
The executor_index trait detects the type used by an executor to represent an index within a bulk ope...
Definition: executor.hpp:214
Polymorphic wrapper for executors.
Definition: executor.hpp:47
The is_executor_of trait detects whether a type T satisfies the execution::executor_of concept for so...
Definition: executor.hpp:147
Definition: chrono.h:284
Definition: executor.hpp:70
Definition: handler_work.hpp:37
Definition: executor.hpp:85
The executor_shape trait detects the type used by an executor to represent the shape of a bulk operat...
Definition: executor.hpp:188
Definition: any_io_executor.hpp:28
The is_executor trait detects whether a type T satisfies the execution::executor concept.
Definition: executor.hpp:109