set_done.hpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. //
  2. // execution/set_done.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_SET_DONE_HPP
  11. #define BOOST_ASIO_EXECUTION_SET_DONE_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. #if !defined(BOOST_ASIO_NO_DEPRECATED)
  17. #include <boost/asio/detail/type_traits.hpp>
  18. #include <boost/asio/traits/set_done_member.hpp>
  19. #include <boost/asio/traits/set_done_free.hpp>
  20. #include <boost/asio/detail/push_options.hpp>
  21. #if defined(GENERATING_DOCUMENTATION)
  22. namespace boost {
  23. namespace asio {
  24. namespace execution {
  25. /// A customisation point that delivers a done notification to a receiver.
  26. /**
  27. * The name <tt>execution::set_done</tt> denotes a customisation point object.
  28. * The expression <tt>execution::set_done(R)</tt> for some subexpression
  29. * <tt>R</tt> is expression-equivalent to:
  30. *
  31. * @li <tt>R.set_done()</tt>, if that expression is valid. If the function
  32. * selected does not signal the receiver <tt>R</tt>'s done channel, the
  33. * program is ill-formed with no diagnostic required.
  34. *
  35. * @li Otherwise, <tt>set_done(R)</tt>, if that expression is valid, with
  36. * overload resolution performed in a context that includes the declaration
  37. * <tt>void set_done();</tt> and that does not include a declaration of
  38. * <tt>execution::set_done</tt>. If the function selected by overload
  39. * resolution does not signal the receiver <tt>R</tt>'s done channel, the
  40. * program is ill-formed with no diagnostic required.
  41. *
  42. * @li Otherwise, <tt>execution::set_done(R)</tt> is ill-formed.
  43. */
  44. inline constexpr unspecified set_done = unspecified;
  45. /// A type trait that determines whether a @c set_done expression is
  46. /// well-formed.
  47. /**
  48. * Class template @c can_set_done is a trait that is derived from
  49. * @c true_type if the expression <tt>execution::set_done(std::declval<R>(),
  50. * std::declval<E>())</tt> is well formed; otherwise @c false_type.
  51. */
  52. template <typename R>
  53. struct can_set_done :
  54. integral_constant<bool, automatically_determined>
  55. {
  56. };
  57. } // namespace execution
  58. } // namespace asio
  59. } // namespace boost
  60. #else // defined(GENERATING_DOCUMENTATION)
  61. namespace boost_asio_execution_set_done_fn {
  62. using boost::asio::decay;
  63. using boost::asio::declval;
  64. using boost::asio::enable_if;
  65. using boost::asio::traits::set_done_free;
  66. using boost::asio::traits::set_done_member;
  67. void set_done();
  68. enum overload_type
  69. {
  70. call_member,
  71. call_free,
  72. ill_formed
  73. };
  74. template <typename R, typename = void, typename = void>
  75. struct call_traits
  76. {
  77. BOOST_ASIO_STATIC_CONSTEXPR(overload_type, overload = ill_formed);
  78. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
  79. typedef void result_type;
  80. };
  81. template <typename R>
  82. struct call_traits<R,
  83. typename enable_if<
  84. set_done_member<R>::is_valid
  85. >::type> :
  86. set_done_member<R>
  87. {
  88. BOOST_ASIO_STATIC_CONSTEXPR(overload_type, overload = call_member);
  89. };
  90. template <typename R>
  91. struct call_traits<R,
  92. typename enable_if<
  93. !set_done_member<R>::is_valid
  94. >::type,
  95. typename enable_if<
  96. set_done_free<R>::is_valid
  97. >::type> :
  98. set_done_free<R>
  99. {
  100. BOOST_ASIO_STATIC_CONSTEXPR(overload_type, overload = call_free);
  101. };
  102. struct impl
  103. {
  104. #if defined(BOOST_ASIO_HAS_MOVE)
  105. template <typename R>
  106. BOOST_ASIO_CONSTEXPR typename enable_if<
  107. call_traits<R>::overload == call_member,
  108. typename call_traits<R>::result_type
  109. >::type
  110. operator()(R&& r) const
  111. BOOST_ASIO_NOEXCEPT_IF((
  112. call_traits<R>::is_noexcept))
  113. {
  114. return BOOST_ASIO_MOVE_CAST(R)(r).set_done();
  115. }
  116. template <typename R>
  117. BOOST_ASIO_CONSTEXPR typename enable_if<
  118. call_traits<R>::overload == call_free,
  119. typename call_traits<R>::result_type
  120. >::type
  121. operator()(R&& r) const
  122. BOOST_ASIO_NOEXCEPT_IF((
  123. call_traits<R>::is_noexcept))
  124. {
  125. return set_done(BOOST_ASIO_MOVE_CAST(R)(r));
  126. }
  127. #else // defined(BOOST_ASIO_HAS_MOVE)
  128. template <typename R>
  129. BOOST_ASIO_CONSTEXPR typename enable_if<
  130. call_traits<R&>::overload == call_member,
  131. typename call_traits<R&>::result_type
  132. >::type
  133. operator()(R& r) const
  134. BOOST_ASIO_NOEXCEPT_IF((
  135. call_traits<R&>::is_noexcept))
  136. {
  137. return r.set_done();
  138. }
  139. template <typename R>
  140. BOOST_ASIO_CONSTEXPR typename enable_if<
  141. call_traits<const R&>::overload == call_member,
  142. typename call_traits<const R&>::result_type
  143. >::type
  144. operator()(const R& r) const
  145. BOOST_ASIO_NOEXCEPT_IF((
  146. call_traits<const R&>::is_noexcept))
  147. {
  148. return r.set_done();
  149. }
  150. template <typename R>
  151. BOOST_ASIO_CONSTEXPR typename enable_if<
  152. call_traits<R&>::overload == call_free,
  153. typename call_traits<R&>::result_type
  154. >::type
  155. operator()(R& r) const
  156. BOOST_ASIO_NOEXCEPT_IF((
  157. call_traits<R&>::is_noexcept))
  158. {
  159. return set_done(r);
  160. }
  161. template <typename R>
  162. BOOST_ASIO_CONSTEXPR typename enable_if<
  163. call_traits<const R&>::overload == call_free,
  164. typename call_traits<const R&>::result_type
  165. >::type
  166. operator()(const R& r) const
  167. BOOST_ASIO_NOEXCEPT_IF((
  168. call_traits<const R&>::is_noexcept))
  169. {
  170. return set_done(r);
  171. }
  172. #endif // defined(BOOST_ASIO_HAS_MOVE)
  173. };
  174. template <typename T = impl>
  175. struct static_instance
  176. {
  177. static const T instance;
  178. };
  179. template <typename T>
  180. const T static_instance<T>::instance = {};
  181. } // namespace boost_asio_execution_set_done_fn
  182. namespace boost {
  183. namespace asio {
  184. namespace execution {
  185. namespace {
  186. static BOOST_ASIO_CONSTEXPR const boost_asio_execution_set_done_fn::impl&
  187. set_done = boost_asio_execution_set_done_fn::static_instance<>::instance;
  188. } // namespace
  189. template <typename R>
  190. struct can_set_done :
  191. integral_constant<bool,
  192. boost_asio_execution_set_done_fn::call_traits<R>::overload !=
  193. boost_asio_execution_set_done_fn::ill_formed>
  194. {
  195. };
  196. #if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
  197. template <typename R>
  198. constexpr bool can_set_done_v = can_set_done<R>::value;
  199. #endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
  200. template <typename R>
  201. struct is_nothrow_set_done :
  202. integral_constant<bool,
  203. boost_asio_execution_set_done_fn::call_traits<R>::is_noexcept>
  204. {
  205. };
  206. #if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
  207. template <typename R>
  208. constexpr bool is_nothrow_set_done_v
  209. = is_nothrow_set_done<R>::value;
  210. #endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
  211. } // namespace execution
  212. } // namespace asio
  213. } // namespace boost
  214. #endif // defined(GENERATING_DOCUMENTATION)
  215. #include <boost/asio/detail/pop_options.hpp>
  216. #endif // !defined(BOOST_ASIO_NO_DEPRECATED)
  217. #endif // BOOST_ASIO_EXECUTION_SET_DONE_HPP