any_io_executor.hpp 9.6 KB

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