any_completion_executor.hpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. //
  2. // any_completion_executor.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2024 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_ANY_COMPLETION_EXECUTOR_HPP
  11. #define BOOST_ASIO_ANY_COMPLETION_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. #if defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT)
  17. # include <boost/asio/executor.hpp>
  18. #else // defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT)
  19. # include <boost/asio/execution.hpp>
  20. #endif // defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT)
  21. #include <boost/asio/detail/push_options.hpp>
  22. namespace boost {
  23. namespace asio {
  24. #if defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT)
  25. typedef executor any_completion_executor;
  26. #else // defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT)
  27. /// Polymorphic executor type for use with I/O objects.
  28. /**
  29. * The @c any_completion_executor type is a polymorphic executor that supports
  30. * the set of properties required for the execution of completion handlers. It
  31. * is defined as the execution::any_executor class template parameterised as
  32. * follows:
  33. * @code execution::any_executor<
  34. * execution::prefer_only<execution::outstanding_work_t::tracked_t>,
  35. * execution::prefer_only<execution::outstanding_work_t::untracked_t>
  36. * execution::prefer_only<execution::relationship_t::fork_t>,
  37. * execution::prefer_only<execution::relationship_t::continuation_t>
  38. * > @endcode
  39. */
  40. class any_completion_executor :
  41. #if defined(GENERATING_DOCUMENTATION)
  42. public execution::any_executor<...>
  43. #else // defined(GENERATING_DOCUMENTATION)
  44. public execution::any_executor<
  45. execution::prefer_only<execution::outstanding_work_t::tracked_t>,
  46. execution::prefer_only<execution::outstanding_work_t::untracked_t>,
  47. execution::prefer_only<execution::relationship_t::fork_t>,
  48. execution::prefer_only<execution::relationship_t::continuation_t>
  49. >
  50. #endif // defined(GENERATING_DOCUMENTATION)
  51. {
  52. public:
  53. #if !defined(GENERATING_DOCUMENTATION)
  54. typedef execution::any_executor<
  55. execution::prefer_only<execution::outstanding_work_t::tracked_t>,
  56. execution::prefer_only<execution::outstanding_work_t::untracked_t>,
  57. execution::prefer_only<execution::relationship_t::fork_t>,
  58. execution::prefer_only<execution::relationship_t::continuation_t>
  59. > base_type;
  60. typedef void supportable_properties_type(
  61. execution::prefer_only<execution::outstanding_work_t::tracked_t>,
  62. execution::prefer_only<execution::outstanding_work_t::untracked_t>,
  63. execution::prefer_only<execution::relationship_t::fork_t>,
  64. execution::prefer_only<execution::relationship_t::continuation_t>
  65. );
  66. #endif // !defined(GENERATING_DOCUMENTATION)
  67. /// Default constructor.
  68. BOOST_ASIO_DECL any_completion_executor() noexcept;
  69. /// Construct in an empty state. Equivalent effects to default constructor.
  70. BOOST_ASIO_DECL any_completion_executor(nullptr_t) noexcept;
  71. /// Copy constructor.
  72. BOOST_ASIO_DECL any_completion_executor(
  73. const any_completion_executor& e) noexcept;
  74. /// Move constructor.
  75. BOOST_ASIO_DECL any_completion_executor(
  76. any_completion_executor&& e) noexcept;
  77. /// Construct to point to the same target as another any_executor.
  78. #if defined(GENERATING_DOCUMENTATION)
  79. template <class... OtherSupportableProperties>
  80. any_completion_executor(
  81. execution::any_executor<OtherSupportableProperties...> e);
  82. #else // defined(GENERATING_DOCUMENTATION)
  83. template <typename OtherAnyExecutor>
  84. any_completion_executor(OtherAnyExecutor e,
  85. constraint_t<
  86. conditional<
  87. !is_same<OtherAnyExecutor, any_completion_executor>::value
  88. && is_base_of<execution::detail::any_executor_base,
  89. OtherAnyExecutor>::value,
  90. typename execution::detail::supportable_properties<
  91. 0, supportable_properties_type>::template
  92. is_valid_target<OtherAnyExecutor>,
  93. false_type
  94. >::type::value
  95. > = 0)
  96. : base_type(static_cast<OtherAnyExecutor&&>(e))
  97. {
  98. }
  99. #endif // defined(GENERATING_DOCUMENTATION)
  100. /// Construct to point to the same target as another any_executor.
  101. #if defined(GENERATING_DOCUMENTATION)
  102. template <class... OtherSupportableProperties>
  103. any_completion_executor(std::nothrow_t,
  104. execution::any_executor<OtherSupportableProperties...> e);
  105. #else // defined(GENERATING_DOCUMENTATION)
  106. template <typename OtherAnyExecutor>
  107. any_completion_executor(std::nothrow_t, OtherAnyExecutor e,
  108. constraint_t<
  109. conditional<
  110. !is_same<OtherAnyExecutor, any_completion_executor>::value
  111. && is_base_of<execution::detail::any_executor_base,
  112. OtherAnyExecutor>::value,
  113. typename execution::detail::supportable_properties<
  114. 0, supportable_properties_type>::template
  115. is_valid_target<OtherAnyExecutor>,
  116. false_type
  117. >::type::value
  118. > = 0) noexcept
  119. : base_type(std::nothrow, static_cast<OtherAnyExecutor&&>(e))
  120. {
  121. }
  122. #endif // defined(GENERATING_DOCUMENTATION)
  123. /// Construct to point to the same target as another any_executor.
  124. BOOST_ASIO_DECL any_completion_executor(std::nothrow_t,
  125. const any_completion_executor& e) noexcept;
  126. /// Construct to point to the same target as another any_executor.
  127. BOOST_ASIO_DECL any_completion_executor(std::nothrow_t,
  128. any_completion_executor&& e) noexcept;
  129. /// Construct a polymorphic wrapper for the specified executor.
  130. #if defined(GENERATING_DOCUMENTATION)
  131. template <BOOST_ASIO_EXECUTION_EXECUTOR Executor>
  132. any_completion_executor(Executor e);
  133. #else // defined(GENERATING_DOCUMENTATION)
  134. template <BOOST_ASIO_EXECUTION_EXECUTOR Executor>
  135. any_completion_executor(Executor e,
  136. constraint_t<
  137. conditional<
  138. !is_same<Executor, any_completion_executor>::value
  139. && !is_base_of<execution::detail::any_executor_base,
  140. Executor>::value,
  141. execution::detail::is_valid_target_executor<
  142. Executor, supportable_properties_type>,
  143. false_type
  144. >::type::value
  145. > = 0)
  146. : base_type(static_cast<Executor&&>(e))
  147. {
  148. }
  149. #endif // defined(GENERATING_DOCUMENTATION)
  150. /// Construct a polymorphic wrapper for the specified executor.
  151. #if defined(GENERATING_DOCUMENTATION)
  152. template <BOOST_ASIO_EXECUTION_EXECUTOR Executor>
  153. any_completion_executor(std::nothrow_t, Executor e);
  154. #else // defined(GENERATING_DOCUMENTATION)
  155. template <BOOST_ASIO_EXECUTION_EXECUTOR Executor>
  156. any_completion_executor(std::nothrow_t, Executor e,
  157. constraint_t<
  158. conditional<
  159. !is_same<Executor, any_completion_executor>::value
  160. && !is_base_of<execution::detail::any_executor_base,
  161. Executor>::value,
  162. execution::detail::is_valid_target_executor<
  163. Executor, supportable_properties_type>,
  164. false_type
  165. >::type::value
  166. > = 0) noexcept
  167. : base_type(std::nothrow, static_cast<Executor&&>(e))
  168. {
  169. }
  170. #endif // defined(GENERATING_DOCUMENTATION)
  171. /// Assignment operator.
  172. BOOST_ASIO_DECL any_completion_executor& operator=(
  173. const any_completion_executor& e) noexcept;
  174. /// Move assignment operator.
  175. BOOST_ASIO_DECL any_completion_executor& operator=(
  176. any_completion_executor&& e) noexcept;
  177. /// Assignment operator that sets the polymorphic wrapper to the empty state.
  178. BOOST_ASIO_DECL any_completion_executor& operator=(nullptr_t);
  179. /// Destructor.
  180. BOOST_ASIO_DECL ~any_completion_executor();
  181. /// Swap targets with another polymorphic wrapper.
  182. BOOST_ASIO_DECL void swap(any_completion_executor& other) noexcept;
  183. /// Obtain a polymorphic wrapper with the specified property.
  184. /**
  185. * Do not call this function directly. It is intended for use with the
  186. * boost::asio::require and boost::asio::prefer customisation points.
  187. *
  188. * For example:
  189. * @code any_completion_executor ex = ...;
  190. * auto ex2 = boost::asio::require(ex, execution::relationship.fork); @endcode
  191. */
  192. template <typename Property>
  193. any_completion_executor require(const Property& p,
  194. constraint_t<
  195. traits::require_member<const base_type&, const Property&>::is_valid
  196. > = 0) const
  197. {
  198. return static_cast<const base_type&>(*this).require(p);
  199. }
  200. /// Obtain a polymorphic wrapper with the specified property.
  201. /**
  202. * Do not call this function directly. It is intended for use with the
  203. * boost::asio::prefer customisation point.
  204. *
  205. * For example:
  206. * @code any_completion_executor ex = ...;
  207. * auto ex2 = boost::asio::prefer(ex, execution::relationship.fork); @endcode
  208. */
  209. template <typename Property>
  210. any_completion_executor prefer(const Property& p,
  211. constraint_t<
  212. traits::prefer_member<const base_type&, const Property&>::is_valid
  213. > = 0) const
  214. {
  215. return static_cast<const base_type&>(*this).prefer(p);
  216. }
  217. };
  218. #if !defined(GENERATING_DOCUMENTATION)
  219. template <>
  220. BOOST_ASIO_DECL any_completion_executor any_completion_executor::prefer(
  221. const execution::outstanding_work_t::tracked_t&, int) const;
  222. template <>
  223. BOOST_ASIO_DECL any_completion_executor any_completion_executor::prefer(
  224. const execution::outstanding_work_t::untracked_t&, int) const;
  225. template <>
  226. BOOST_ASIO_DECL any_completion_executor any_completion_executor::prefer(
  227. const execution::relationship_t::fork_t&, int) const;
  228. template <>
  229. BOOST_ASIO_DECL any_completion_executor any_completion_executor::prefer(
  230. const execution::relationship_t::continuation_t&, int) const;
  231. namespace traits {
  232. #if !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
  233. template <>
  234. struct equality_comparable<any_completion_executor>
  235. {
  236. static const bool is_valid = true;
  237. static const bool is_noexcept = true;
  238. };
  239. #endif // !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
  240. #if !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
  241. template <typename F>
  242. struct execute_member<any_completion_executor, F>
  243. {
  244. static const bool is_valid = true;
  245. static const bool is_noexcept = false;
  246. typedef void result_type;
  247. };
  248. #endif // !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
  249. #if !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
  250. template <typename Prop>
  251. struct query_member<any_completion_executor, Prop> :
  252. query_member<any_completion_executor::base_type, Prop>
  253. {
  254. };
  255. #endif // !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
  256. #if !defined(BOOST_ASIO_HAS_DEDUCED_REQUIRE_MEMBER_TRAIT)
  257. template <typename Prop>
  258. struct require_member<any_completion_executor, Prop> :
  259. require_member<any_completion_executor::base_type, Prop>
  260. {
  261. typedef any_completion_executor result_type;
  262. };
  263. #endif // !defined(BOOST_ASIO_HAS_DEDUCED_REQUIRE_MEMBER_TRAIT)
  264. #if !defined(BOOST_ASIO_HAS_DEDUCED_PREFER_MEMBER_TRAIT)
  265. template <typename Prop>
  266. struct prefer_member<any_completion_executor, Prop> :
  267. prefer_member<any_completion_executor::base_type, Prop>
  268. {
  269. typedef any_completion_executor result_type;
  270. };
  271. #endif // !defined(BOOST_ASIO_HAS_DEDUCED_PREFER_MEMBER_TRAIT)
  272. } // namespace traits
  273. #endif // !defined(GENERATING_DOCUMENTATION)
  274. #endif // defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT)
  275. } // namespace asio
  276. } // namespace boost
  277. #include <boost/asio/detail/pop_options.hpp>
  278. #if defined(BOOST_ASIO_HEADER_ONLY) \
  279. && !defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT)
  280. # include <boost/asio/impl/any_completion_executor.ipp>
  281. #endif // defined(BOOST_ASIO_HEADER_ONLY)
  282. // && !defined(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT)
  283. #endif // BOOST_ASIO_ANY_COMPLETION_EXECUTOR_HPP