executor.hpp 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. //
  2. // execution/executor.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2023 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. #ifndef BOOST_ASIO_EXECUTION_EXECUTOR_HPP
  11. #define BOOST_ASIO_EXECUTION_EXECUTOR_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/detail/config.hpp>
  16. #include <boost/asio/detail/type_traits.hpp>
  17. #include <boost/asio/execution/invocable_archetype.hpp>
  18. #include <boost/asio/traits/equality_comparable.hpp>
  19. #include <boost/asio/traits/execute_member.hpp>
  20. #if !defined(BOOST_ASIO_NO_DEPRECATED)
  21. # include <boost/asio/execution/execute.hpp>
  22. #endif // !defined(BOOST_ASIO_NO_DEPRECATED)
  23. #if defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_FREE_TRAIT) \
  24. && defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT) \
  25. && defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
  26. # define BOOST_ASIO_HAS_DEDUCED_EXECUTION_IS_EXECUTOR_TRAIT 1
  27. #endif // defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_FREE_TRAIT)
  28. // && defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
  29. // && defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
  30. #include <boost/asio/detail/push_options.hpp>
  31. namespace boost {
  32. namespace asio {
  33. namespace execution {
  34. namespace detail {
  35. template <typename T, typename F,
  36. typename = void, typename = void, typename = void, typename = void,
  37. typename = void, typename = void, typename = void, typename = void>
  38. struct is_executor_of_impl : false_type
  39. {
  40. };
  41. template <typename T, typename F>
  42. struct is_executor_of_impl<T, F,
  43. #if defined(BOOST_ASIO_NO_DEPRECATED)
  44. typename enable_if<
  45. traits::execute_member<typename add_const<T>::type, F>::is_valid
  46. >::type,
  47. #else // defined(BOOST_ASIO_NO_DEPRECATED)
  48. typename enable_if<
  49. can_execute<typename add_const<T>::type, F>::value
  50. >::type,
  51. #endif // defined(BOOST_ASIO_NO_DEPRECATED)
  52. typename void_type<
  53. typename result_of<typename decay<F>::type&()>::type
  54. >::type,
  55. typename enable_if<
  56. is_constructible<typename decay<F>::type, F>::value
  57. >::type,
  58. typename enable_if<
  59. is_move_constructible<typename decay<F>::type>::value
  60. >::type,
  61. #if defined(BOOST_ASIO_HAS_NOEXCEPT)
  62. typename enable_if<
  63. is_nothrow_copy_constructible<T>::value
  64. >::type,
  65. typename enable_if<
  66. is_nothrow_destructible<T>::value
  67. >::type,
  68. #else // defined(BOOST_ASIO_HAS_NOEXCEPT)
  69. typename enable_if<
  70. is_copy_constructible<T>::value
  71. >::type,
  72. typename enable_if<
  73. is_destructible<T>::value
  74. >::type,
  75. #endif // defined(BOOST_ASIO_HAS_NOEXCEPT)
  76. typename enable_if<
  77. traits::equality_comparable<T>::is_valid
  78. >::type,
  79. typename enable_if<
  80. traits::equality_comparable<T>::is_noexcept
  81. >::type> : true_type
  82. {
  83. };
  84. template <typename T, typename = void>
  85. struct executor_shape
  86. {
  87. typedef std::size_t type;
  88. };
  89. template <typename T>
  90. struct executor_shape<T,
  91. typename void_type<
  92. typename T::shape_type
  93. >::type>
  94. {
  95. typedef typename T::shape_type type;
  96. };
  97. template <typename T, typename Default, typename = void>
  98. struct executor_index
  99. {
  100. typedef Default type;
  101. };
  102. template <typename T, typename Default>
  103. struct executor_index<T, Default,
  104. typename void_type<
  105. typename T::index_type
  106. >::type>
  107. {
  108. typedef typename T::index_type type;
  109. };
  110. } // namespace detail
  111. /// The is_executor trait detects whether a type T satisfies the
  112. /// execution::executor concept.
  113. /**
  114. * Class template @c is_executor is a UnaryTypeTrait that is derived from @c
  115. * true_type if the type @c T meets the concept definition for an executor,
  116. * otherwise @c false_type.
  117. */
  118. template <typename T>
  119. struct is_executor :
  120. #if defined(GENERATING_DOCUMENTATION)
  121. integral_constant<bool, automatically_determined>
  122. #else // defined(GENERATING_DOCUMENTATION)
  123. detail::is_executor_of_impl<T, invocable_archetype>
  124. #endif // defined(GENERATING_DOCUMENTATION)
  125. {
  126. };
  127. #if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
  128. template <typename T>
  129. BOOST_ASIO_CONSTEXPR const bool is_executor_v = is_executor<T>::value;
  130. #endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
  131. #if defined(BOOST_ASIO_HAS_CONCEPTS)
  132. template <typename T>
  133. BOOST_ASIO_CONCEPT executor = is_executor<T>::value;
  134. #define BOOST_ASIO_EXECUTION_EXECUTOR ::boost::asio::execution::executor
  135. #else // defined(BOOST_ASIO_HAS_CONCEPTS)
  136. #define BOOST_ASIO_EXECUTION_EXECUTOR typename
  137. #endif // defined(BOOST_ASIO_HAS_CONCEPTS)
  138. /// The is_executor_of trait detects whether a type T satisfies the
  139. /// execution::executor_of concept for some set of value arguments.
  140. /**
  141. * Class template @c is_executor_of is a type trait that is derived from @c
  142. * true_type if the type @c T meets the concept definition for an executor
  143. * that is invocable with a function object of type @c F, otherwise @c
  144. * false_type.
  145. */
  146. template <typename T, typename F>
  147. struct is_executor_of :
  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. #if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
  158. template <typename T, typename F>
  159. BOOST_ASIO_CONSTEXPR const bool is_executor_of_v =
  160. is_executor_of<T, F>::value;
  161. #endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
  162. #if defined(BOOST_ASIO_HAS_CONCEPTS)
  163. template <typename T, typename F>
  164. BOOST_ASIO_CONCEPT executor_of = is_executor_of<T, F>::value;
  165. #define BOOST_ASIO_EXECUTION_EXECUTOR_OF(f) \
  166. ::boost::asio::execution::executor_of<f>
  167. #else // defined(BOOST_ASIO_HAS_CONCEPTS)
  168. #define BOOST_ASIO_EXECUTION_EXECUTOR_OF typename
  169. #endif // defined(BOOST_ASIO_HAS_CONCEPTS)
  170. /// The executor_shape trait detects the type used by an executor to represent
  171. /// the shape of a bulk operation.
  172. /**
  173. * Class template @c executor_shape is a type trait with a nested type alias
  174. * @c type whose type is @c T::shape_type if @c T::shape_type is valid,
  175. * otherwise @c std::size_t.
  176. */
  177. template <typename T>
  178. struct executor_shape
  179. #if !defined(GENERATING_DOCUMENTATION)
  180. : detail::executor_shape<T>
  181. #endif // !defined(GENERATING_DOCUMENTATION)
  182. {
  183. #if defined(GENERATING_DOCUMENTATION)
  184. /// @c T::shape_type if @c T::shape_type is valid, otherwise @c std::size_t.
  185. typedef automatically_determined type;
  186. #endif // defined(GENERATING_DOCUMENTATION)
  187. };
  188. #if defined(BOOST_ASIO_HAS_ALIAS_TEMPLATES)
  189. template <typename T>
  190. using executor_shape_t = typename executor_shape<T>::type;
  191. #endif // defined(BOOST_ASIO_HAS_ALIAS_TEMPLATES)
  192. /// The executor_index trait detects the type used by an executor to represent
  193. /// an index within a bulk operation.
  194. /**
  195. * Class template @c executor_index is a type trait with a nested type alias
  196. * @c type whose type is @c T::index_type if @c T::index_type is valid,
  197. * otherwise @c executor_shape_t<T>.
  198. */
  199. template <typename T>
  200. struct executor_index
  201. #if !defined(GENERATING_DOCUMENTATION)
  202. : detail::executor_index<T, typename executor_shape<T>::type>
  203. #endif // !defined(GENERATING_DOCUMENTATION)
  204. {
  205. #if defined(GENERATING_DOCUMENTATION)
  206. /// @c T::index_type if @c T::index_type is valid, otherwise
  207. /// @c executor_shape_t<T>.
  208. typedef automatically_determined type;
  209. #endif // defined(GENERATING_DOCUMENTATION)
  210. };
  211. #if defined(BOOST_ASIO_HAS_ALIAS_TEMPLATES)
  212. template <typename T>
  213. using executor_index_t = typename executor_index<T>::type;
  214. #endif // defined(BOOST_ASIO_HAS_ALIAS_TEMPLATES)
  215. } // namespace execution
  216. } // namespace asio
  217. } // namespace boost
  218. #include <boost/asio/detail/pop_options.hpp>
  219. #endif // BOOST_ASIO_EXECUTION_EXECUTOR_HPP