executor.hpp 7.2 KB

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