receiver.hpp 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. //
  2. // execution/receiver.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_RECEIVER_HPP
  11. #define BOOST_ASIO_EXECUTION_RECEIVER_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/detail/variadic_templates.hpp>
  18. #include <boost/asio/execution/set_done.hpp>
  19. #include <boost/asio/execution/set_error.hpp>
  20. #include <boost/asio/execution/set_value.hpp>
  21. #if defined(BOOST_ASIO_HAS_STD_EXCEPTION_PTR)
  22. # include <exception>
  23. #else // defined(BOOST_ASIO_HAS_STD_EXCEPTION_PTR)
  24. # include <boost/system/error_code.hpp>
  25. #endif // defined(BOOST_ASIO_HAS_STD_EXCEPTION_PTR)
  26. #if defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_FREE_TRAIT) \
  27. && defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_MEMBER_TRAIT) \
  28. && defined(BOOST_ASIO_HAS_DEDUCED_SET_ERROR_FREE_TRAIT) \
  29. && defined(BOOST_ASIO_HAS_DEDUCED_SET_ERROR_MEMBER_TRAIT) \
  30. && defined(BOOST_ASIO_HAS_DEDUCED_SET_VALUE_FREE_TRAIT) \
  31. && defined(BOOST_ASIO_HAS_DEDUCED_SET_VALUE_MEMBER_TRAIT) \
  32. && defined(BOOST_ASIO_HAS_DEDUCED_RECEIVER_OF_FREE_TRAIT) \
  33. && defined(BOOST_ASIO_HAS_DEDUCED_RECEIVER_OF_MEMBER_TRAIT)
  34. # define BOOST_ASIO_HAS_DEDUCED_EXECUTION_IS_RECEIVER_TRAIT 1
  35. #endif // defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_FREE_TRAIT)
  36. // && defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_MEMBER_TRAIT)
  37. // && defined(BOOST_ASIO_HAS_DEDUCED_SET_ERROR_FREE_TRAIT)
  38. // && defined(BOOST_ASIO_HAS_DEDUCED_SET_ERROR_MEMBER_TRAIT)
  39. // && defined(BOOST_ASIO_HAS_DEDUCED_SET_VALUE_FREE_TRAIT)
  40. // && defined(BOOST_ASIO_HAS_DEDUCED_SET_VALUE_MEMBER_TRAIT)
  41. // && defined(BOOST_ASIO_HAS_DEDUCED_RECEIVER_OF_FREE_TRAIT)
  42. // && defined(BOOST_ASIO_HAS_DEDUCED_RECEIVER_OF_MEMBER_TRAIT)
  43. #include <boost/asio/detail/push_options.hpp>
  44. namespace boost {
  45. namespace asio {
  46. namespace execution {
  47. namespace detail {
  48. template <typename T, typename E>
  49. struct is_receiver_base :
  50. integral_constant<bool,
  51. is_move_constructible<typename remove_cvref<T>::type>::value
  52. && is_constructible<typename remove_cvref<T>::type, T>::value
  53. >
  54. {
  55. };
  56. } // namespace detail
  57. #if defined(BOOST_ASIO_HAS_STD_EXCEPTION_PTR)
  58. # define BOOST_ASIO_EXECUTION_RECEIVER_ERROR_DEFAULT = std::exception_ptr
  59. #else // defined(BOOST_ASIO_HAS_STD_EXCEPTION_PTR)
  60. # define BOOST_ASIO_EXECUTION_RECEIVER_ERROR_DEFAULT \
  61. = ::boost::system::error_code
  62. #endif // defined(BOOST_ASIO_HAS_STD_EXCEPTION_PTR)
  63. /// The is_receiver trait detects whether a type T satisfies the
  64. /// execution::receiver concept.
  65. /**
  66. * Class template @c is_receiver is a type trait that is derived from @c
  67. * true_type if the type @c T meets the concept definition for a receiver for
  68. * error type @c E, otherwise @c false_type.
  69. */
  70. template <typename T, typename E BOOST_ASIO_EXECUTION_RECEIVER_ERROR_DEFAULT>
  71. struct is_receiver :
  72. #if defined(GENERATING_DOCUMENTATION)
  73. integral_constant<bool, automatically_determined>
  74. #else // defined(GENERATING_DOCUMENTATION)
  75. conditional<
  76. can_set_done<typename remove_cvref<T>::type>::value
  77. && is_nothrow_set_done<typename remove_cvref<T>::type>::value
  78. && can_set_error<typename remove_cvref<T>::type, E>::value
  79. && is_nothrow_set_error<typename remove_cvref<T>::type, E>::value,
  80. detail::is_receiver_base<T, E>,
  81. false_type
  82. >::type
  83. #endif // defined(GENERATING_DOCUMENTATION)
  84. {
  85. };
  86. #if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
  87. template <typename T, typename E BOOST_ASIO_EXECUTION_RECEIVER_ERROR_DEFAULT>
  88. BOOST_ASIO_CONSTEXPR const bool is_receiver_v = is_receiver<T, E>::value;
  89. #endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
  90. #if defined(BOOST_ASIO_HAS_CONCEPTS)
  91. template <typename T, typename E BOOST_ASIO_EXECUTION_RECEIVER_ERROR_DEFAULT>
  92. BOOST_ASIO_CONCEPT receiver = is_receiver<T, E>::value;
  93. #define BOOST_ASIO_EXECUTION_RECEIVER ::boost::asio::execution::receiver
  94. #else // defined(BOOST_ASIO_HAS_CONCEPTS)
  95. #define BOOST_ASIO_EXECUTION_RECEIVER typename
  96. #endif // defined(BOOST_ASIO_HAS_CONCEPTS)
  97. #if defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES) \
  98. || defined(GENERATING_DOCUMENTATION)
  99. /// The is_receiver_of trait detects whether a type T satisfies the
  100. /// execution::receiver_of concept for some set of value arguments.
  101. /**
  102. * Class template @c is_receiver_of is a type trait that is derived from @c
  103. * true_type if the type @c T meets the concept definition for a receiver for
  104. * value arguments @c Vs, otherwise @c false_type.
  105. */
  106. template <typename T, typename... Vs>
  107. struct is_receiver_of :
  108. #if defined(GENERATING_DOCUMENTATION)
  109. integral_constant<bool, automatically_determined>
  110. #else // defined(GENERATING_DOCUMENTATION)
  111. conditional<
  112. is_receiver<T>::value,
  113. can_set_value<typename remove_cvref<T>::type, Vs...>,
  114. false_type
  115. >::type
  116. #endif // defined(GENERATING_DOCUMENTATION)
  117. {
  118. };
  119. #if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
  120. template <typename T, typename... Vs>
  121. BOOST_ASIO_CONSTEXPR const bool is_receiver_of_v =
  122. is_receiver_of<T, Vs...>::value;
  123. #endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
  124. #if defined(BOOST_ASIO_HAS_CONCEPTS)
  125. template <typename T, typename... Vs>
  126. BOOST_ASIO_CONCEPT receiver_of = is_receiver_of<T, Vs...>::value;
  127. #define BOOST_ASIO_EXECUTION_RECEIVER_OF_0 \
  128. ::boost::asio::execution::receiver_of
  129. #define BOOST_ASIO_EXECUTION_RECEIVER_OF_1(v) \
  130. ::boost::asio::execution::receiver_of<v>
  131. #else // defined(BOOST_ASIO_HAS_CONCEPTS)
  132. #define BOOST_ASIO_EXECUTION_RECEIVER_OF_0 typename
  133. #define BOOST_ASIO_EXECUTION_RECEIVER_OF_1(v) typename
  134. #endif // defined(BOOST_ASIO_HAS_CONCEPTS)
  135. #else // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
  136. // || defined(GENERATING_DOCUMENTATION)
  137. template <typename T, typename = void,
  138. typename = void, typename = void, typename = void, typename = void,
  139. typename = void, typename = void, typename = void, typename = void>
  140. struct is_receiver_of;
  141. template <typename T>
  142. struct is_receiver_of<T> :
  143. conditional<
  144. is_receiver<T>::value,
  145. can_set_value<typename remove_cvref<T>::type>,
  146. false_type
  147. >::type
  148. {
  149. };
  150. #define BOOST_ASIO_PRIVATE_RECEIVER_OF_TRAITS_DEF(n) \
  151. template <typename T, BOOST_ASIO_VARIADIC_TPARAMS(n)> \
  152. struct is_receiver_of<T, BOOST_ASIO_VARIADIC_TARGS(n)> : \
  153. conditional< \
  154. conditional<true, is_receiver<T>, void>::type::value, \
  155. can_set_value< \
  156. typename remove_cvref<T>::type, \
  157. BOOST_ASIO_VARIADIC_TARGS(n)>, \
  158. false_type \
  159. >::type \
  160. { \
  161. }; \
  162. /**/
  163. BOOST_ASIO_VARIADIC_GENERATE(BOOST_ASIO_PRIVATE_RECEIVER_OF_TRAITS_DEF)
  164. #undef BOOST_ASIO_PRIVATE_RECEIVER_OF_TRAITS_DEF
  165. #define BOOST_ASIO_EXECUTION_RECEIVER_OF_0 typename
  166. #define BOOST_ASIO_EXECUTION_RECEIVER_OF_1(v) typename
  167. #endif // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
  168. // || defined(GENERATING_DOCUMENTATION)
  169. #if defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES) \
  170. || defined(GENERATING_DOCUMENTATION)
  171. /// The is_nothrow_receiver_of trait detects whether a type T satisfies the
  172. /// execution::receiver_of concept for some set of value arguments, with a
  173. /// noexcept @c set_value operation.
  174. /**
  175. * Class template @c is_nothrow_receiver_of is a type trait that is derived
  176. * from @c true_type if the type @c T meets the concept definition for a
  177. * receiver for value arguments @c Vs, and the expression
  178. * <tt>execution::set_value(declval<T>(), declval<Ts>()...)</tt> is noexcept,
  179. * otherwise @c false_type.
  180. */
  181. template <typename T, typename... Vs>
  182. struct is_nothrow_receiver_of :
  183. #if defined(GENERATING_DOCUMENTATION)
  184. integral_constant<bool, automatically_determined>
  185. #else // defined(GENERATING_DOCUMENTATION)
  186. integral_constant<bool,
  187. is_receiver_of<T, Vs...>::value
  188. && is_nothrow_set_value<typename remove_cvref<T>::type, Vs...>::value
  189. >
  190. #endif // defined(GENERATING_DOCUMENTATION)
  191. {
  192. };
  193. #if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
  194. template <typename T, typename... Vs>
  195. BOOST_ASIO_CONSTEXPR const bool is_nothrow_receiver_of_v =
  196. is_nothrow_receiver_of<T, Vs...>::value;
  197. #endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
  198. #else // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
  199. // || defined(GENERATING_DOCUMENTATION)
  200. template <typename T, typename = void,
  201. typename = void, typename = void, typename = void, typename = void,
  202. typename = void, typename = void, typename = void, typename = void>
  203. struct is_nothrow_receiver_of;
  204. template <typename T>
  205. struct is_nothrow_receiver_of<T> :
  206. integral_constant<bool,
  207. is_receiver_of<T>::value
  208. && is_nothrow_set_value<typename remove_cvref<T>::type>::value
  209. >
  210. {
  211. };
  212. #define BOOST_ASIO_PRIVATE_NOTHROW_RECEIVER_OF_TRAITS_DEF(n) \
  213. template <typename T, BOOST_ASIO_VARIADIC_TPARAMS(n)> \
  214. struct is_nothrow_receiver_of<T, BOOST_ASIO_VARIADIC_TARGS(n)> : \
  215. integral_constant<bool, \
  216. is_receiver_of<T, BOOST_ASIO_VARIADIC_TARGS(n)>::value \
  217. && is_nothrow_set_value<typename remove_cvref<T>::type, \
  218. BOOST_ASIO_VARIADIC_TARGS(n)>::value \
  219. > \
  220. { \
  221. }; \
  222. /**/
  223. BOOST_ASIO_VARIADIC_GENERATE(BOOST_ASIO_PRIVATE_NOTHROW_RECEIVER_OF_TRAITS_DEF)
  224. #undef BOOST_ASIO_PRIVATE_NOTHROW_RECEIVER_OF_TRAITS_DEF
  225. #endif // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
  226. // || defined(GENERATING_DOCUMENTATION)
  227. } // namespace execution
  228. } // namespace asio
  229. } // namespace boost
  230. #include <boost/asio/detail/pop_options.hpp>
  231. #endif // BOOST_ASIO_EXECUTION_RECEIVER_HPP