any_completion_executor.hpp 11 KB

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