2 // execution/executor.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com)
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)
11 #ifndef BOOST_ASIO_EXECUTION_EXECUTOR_HPP
12 #define BOOST_ASIO_EXECUTION_EXECUTOR_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/config.hpp>
19 #include <boost/asio/detail/type_traits.hpp>
20 #include <boost/asio/execution/execute.hpp>
21 #include <boost/asio/execution/invocable_archetype.hpp>
22 #include <boost/asio/traits/equality_comparable.hpp>
24 #if defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_FREE_TRAIT) \
25 && defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT) \
26 && defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
27 # define BOOST_ASIO_HAS_DEDUCED_EXECUTION_IS_EXECUTOR_TRAIT 1
28 #endif // defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_FREE_TRAIT)
29 // && defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
30 // && defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
32 #include <boost/asio/detail/push_options.hpp>
39 template <typename T, typename F,
40 typename = void, typename = void, typename = void, typename = void,
41 typename = void, typename = void, typename = void, typename = void>
42 struct is_executor_of_impl : false_type
46 template <typename T, typename F>
47 struct is_executor_of_impl<T, F,
49 can_execute<typename add_const<T>::type, F>::value
52 typename result_of<typename decay<F>::type&()>::type
55 is_constructible<typename decay<F>::type, F>::value
58 is_move_constructible<typename decay<F>::type>::value
60 #if defined(BOOST_ASIO_HAS_NOEXCEPT)
62 is_nothrow_copy_constructible<T>::value
65 is_nothrow_destructible<T>::value
67 #else // defined(BOOST_ASIO_HAS_NOEXCEPT)
69 is_copy_constructible<T>::value
72 is_destructible<T>::value
74 #endif // defined(BOOST_ASIO_HAS_NOEXCEPT)
76 traits::equality_comparable<T>::is_valid
79 traits::equality_comparable<T>::is_noexcept
84 template <typename T, typename = void>
87 typedef std::size_t type;
91 struct executor_shape<T,
93 typename T::shape_type
96 typedef typename T::shape_type type;
99 template <typename T, typename Default, typename = void>
100 struct executor_index
102 typedef Default type;
105 template <typename T, typename Default>
106 struct executor_index<T, Default,
108 typename T::index_type
111 typedef typename T::index_type type;
114 } // namespace detail
116 /// The is_executor trait detects whether a type T satisfies the
117 /// execution::executor concept.
119 * Class template @c is_executor is a UnaryTypeTrait that is derived from @c
120 * true_type if the type @c T meets the concept definition for an executor,
121 * otherwise @c false_type.
123 template <typename T>
125 #if defined(GENERATING_DOCUMENTATION)
126 integral_constant<bool, automatically_determined>
127 #else // defined(GENERATING_DOCUMENTATION)
128 detail::is_executor_of_impl<T, invocable_archetype>
129 #endif // defined(GENERATING_DOCUMENTATION)
133 #if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
135 template <typename T>
136 BOOST_ASIO_CONSTEXPR const bool is_executor_v = is_executor<T>::value;
138 #endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
140 #if defined(BOOST_ASIO_HAS_CONCEPTS)
142 template <typename T>
143 BOOST_ASIO_CONCEPT executor = is_executor<T>::value;
145 #define BOOST_ASIO_EXECUTION_EXECUTOR ::boost::asio::execution::executor
147 #else // defined(BOOST_ASIO_HAS_CONCEPTS)
149 #define BOOST_ASIO_EXECUTION_EXECUTOR typename
151 #endif // defined(BOOST_ASIO_HAS_CONCEPTS)
153 /// The is_executor_of trait detects whether a type T satisfies the
154 /// execution::executor_of concept for some set of value arguments.
156 * Class template @c is_executor_of is a type trait that is derived from @c
157 * true_type if the type @c T meets the concept definition for an executor
158 * that is invocable with a function object of type @c F, otherwise @c
161 template <typename T, typename F>
162 struct is_executor_of :
163 #if defined(GENERATING_DOCUMENTATION)
164 integral_constant<bool, automatically_determined>
165 #else // defined(GENERATING_DOCUMENTATION)
166 integral_constant<bool,
167 is_executor<T>::value && detail::is_executor_of_impl<T, F>::value
169 #endif // defined(GENERATING_DOCUMENTATION)
173 #if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
175 template <typename T, typename F>
176 BOOST_ASIO_CONSTEXPR const bool is_executor_of_v =
177 is_executor_of<T, F>::value;
179 #endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
181 #if defined(BOOST_ASIO_HAS_CONCEPTS)
183 template <typename T, typename F>
184 BOOST_ASIO_CONCEPT executor_of = is_executor_of<T, F>::value;
186 #define BOOST_ASIO_EXECUTION_EXECUTOR_OF(f) \
187 ::boost::asio::execution::executor_of<f>
189 #else // defined(BOOST_ASIO_HAS_CONCEPTS)
191 #define BOOST_ASIO_EXECUTION_EXECUTOR_OF typename
193 #endif // defined(BOOST_ASIO_HAS_CONCEPTS)
195 /// The executor_shape trait detects the type used by an executor to represent
196 /// the shape of a bulk operation.
198 * Class template @c executor_shape is a type trait with a nested type alias
199 * @c type whose type is @c T::shape_type if @c T::shape_type is valid,
200 * otherwise @c std::size_t.
202 template <typename T>
203 struct executor_shape
204 #if !defined(GENERATING_DOCUMENTATION)
205 : detail::executor_shape<T>
206 #endif // !defined(GENERATING_DOCUMENTATION)
208 #if defined(GENERATING_DOCUMENTATION)
209 /// @c T::shape_type if @c T::shape_type is valid, otherwise @c std::size_t.
210 typedef automatically_determined type;
211 #endif // defined(GENERATING_DOCUMENTATION)
214 #if defined(BOOST_ASIO_HAS_ALIAS_TEMPLATES)
216 template <typename T>
217 using executor_shape_t = typename executor_shape<T>::type;
219 #endif // defined(BOOST_ASIO_HAS_ALIAS_TEMPLATES)
221 /// The executor_index trait detects the type used by an executor to represent
222 /// an index within a bulk operation.
224 * Class template @c executor_index is a type trait with a nested type alias
225 * @c type whose type is @c T::index_type if @c T::index_type is valid,
226 * otherwise @c executor_shape_t<T>.
228 template <typename T>
229 struct executor_index
230 #if !defined(GENERATING_DOCUMENTATION)
231 : detail::executor_index<T, typename executor_shape<T>::type>
232 #endif // !defined(GENERATING_DOCUMENTATION)
234 #if defined(GENERATING_DOCUMENTATION)
235 /// @c T::index_type if @c T::index_type is valid, otherwise
236 /// @c executor_shape_t<T>.
237 typedef automatically_determined type;
238 #endif // defined(GENERATING_DOCUMENTATION)
241 #if defined(BOOST_ASIO_HAS_ALIAS_TEMPLATES)
243 template <typename T>
244 using executor_index_t = typename executor_index<T>::type;
246 #endif // defined(BOOST_ASIO_HAS_ALIAS_TEMPLATES)
248 } // namespace execution
252 #include <boost/asio/detail/pop_options.hpp>
254 #endif // BOOST_ASIO_EXECUTION_EXECUTOR_HPP