mapping.hpp 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162
  1. //
  2. // execution/mapping.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_MAPPING_HPP
  11. #define BOOST_ASIO_EXECUTION_MAPPING_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/execution/executor.hpp>
  18. #include <boost/asio/execution/scheduler.hpp>
  19. #include <boost/asio/execution/sender.hpp>
  20. #include <boost/asio/is_applicable_property.hpp>
  21. #include <boost/asio/query.hpp>
  22. #include <boost/asio/traits/query_free.hpp>
  23. #include <boost/asio/traits/query_member.hpp>
  24. #include <boost/asio/traits/query_static_constexpr_member.hpp>
  25. #include <boost/asio/traits/static_query.hpp>
  26. #include <boost/asio/traits/static_require.hpp>
  27. #include <boost/asio/detail/push_options.hpp>
  28. namespace boost {
  29. namespace asio {
  30. #if defined(GENERATING_DOCUMENTATION)
  31. namespace execution {
  32. /// A property to describe what guarantees an executor makes about the mapping
  33. /// of execution agents on to threads of execution.
  34. struct mapping_t
  35. {
  36. /// The mapping_t property applies to executors, senders, and schedulers.
  37. template <typename T>
  38. static constexpr bool is_applicable_property_v =
  39. is_executor_v<T> || is_sender_v<T> || is_scheduler_v<T>;
  40. /// The top-level mapping_t property cannot be required.
  41. static constexpr bool is_requirable = false;
  42. /// The top-level mapping_t property cannot be preferred.
  43. static constexpr bool is_preferable = false;
  44. /// The type returned by queries against an @c any_executor.
  45. typedef mapping_t polymorphic_query_result_type;
  46. /// A sub-property that indicates that execution agents are mapped on to
  47. /// threads of execution.
  48. struct thread_t
  49. {
  50. /// The mapping_t::thread_t property applies to executors, senders, and
  51. /// schedulers.
  52. template <typename T>
  53. static constexpr bool is_applicable_property_v =
  54. is_executor_v<T> || is_sender_v<T> || is_scheduler_v<T>;
  55. /// The mapping_t::thread_t property can be required.
  56. static constexpr bool is_requirable = true;
  57. /// The mapping_t::thread_t property can be preferred.
  58. static constexpr bool is_preferable = true;
  59. /// The type returned by queries against an @c any_executor.
  60. typedef mapping_t polymorphic_query_result_type;
  61. /// Default constructor.
  62. constexpr thread_t();
  63. /// Get the value associated with a property object.
  64. /**
  65. * @returns thread_t();
  66. */
  67. static constexpr mapping_t value();
  68. };
  69. /// A sub-property that indicates that execution agents are mapped on to
  70. /// new threads of execution.
  71. struct new_thread_t
  72. {
  73. /// The mapping_t::new_thread_t property applies to executors, senders, and
  74. /// schedulers.
  75. template <typename T>
  76. static constexpr bool is_applicable_property_v =
  77. is_executor_v<T> || is_sender_v<T> || is_scheduler_v<T>;
  78. /// The mapping_t::new_thread_t property can be required.
  79. static constexpr bool is_requirable = true;
  80. /// The mapping_t::new_thread_t property can be preferred.
  81. static constexpr bool is_preferable = true;
  82. /// The type returned by queries against an @c any_executor.
  83. typedef mapping_t polymorphic_query_result_type;
  84. /// Default constructor.
  85. constexpr new_thread_t();
  86. /// Get the value associated with a property object.
  87. /**
  88. * @returns new_thread_t();
  89. */
  90. static constexpr mapping_t value();
  91. };
  92. /// A sub-property that indicates that the mapping of execution agents is
  93. /// implementation-defined.
  94. struct other_t
  95. {
  96. /// The mapping_t::other_t property applies to executors, senders, and
  97. /// schedulers.
  98. template <typename T>
  99. static constexpr bool is_applicable_property_v =
  100. is_executor_v<T> || is_sender_v<T> || is_scheduler_v<T>;
  101. /// The mapping_t::other_t property can be required.
  102. static constexpr bool is_requirable = true;
  103. /// The mapping_t::other_t property can be preferred.
  104. static constexpr bool is_preferable = true;
  105. /// The type returned by queries against an @c any_executor.
  106. typedef mapping_t polymorphic_query_result_type;
  107. /// Default constructor.
  108. constexpr other_t();
  109. /// Get the value associated with a property object.
  110. /**
  111. * @returns other_t();
  112. */
  113. static constexpr mapping_t value();
  114. };
  115. /// A special value used for accessing the mapping_t::thread_t property.
  116. static constexpr thread_t thread;
  117. /// A special value used for accessing the mapping_t::new_thread_t property.
  118. static constexpr new_thread_t new_thread;
  119. /// A special value used for accessing the mapping_t::other_t property.
  120. static constexpr other_t other;
  121. /// Default constructor.
  122. constexpr mapping_t();
  123. /// Construct from a sub-property value.
  124. constexpr mapping_t(thread_t);
  125. /// Construct from a sub-property value.
  126. constexpr mapping_t(new_thread_t);
  127. /// Construct from a sub-property value.
  128. constexpr mapping_t(other_t);
  129. /// Compare property values for equality.
  130. friend constexpr bool operator==(
  131. const mapping_t& a, const mapping_t& b) noexcept;
  132. /// Compare property values for inequality.
  133. friend constexpr bool operator!=(
  134. const mapping_t& a, const mapping_t& b) noexcept;
  135. };
  136. /// A special value used for accessing the mapping_t property.
  137. constexpr mapping_t mapping;
  138. } // namespace execution
  139. #else // defined(GENERATING_DOCUMENTATION)
  140. namespace execution {
  141. namespace detail {
  142. namespace mapping {
  143. template <int I> struct thread_t;
  144. template <int I> struct new_thread_t;
  145. template <int I> struct other_t;
  146. } // namespace mapping
  147. template <int I = 0>
  148. struct mapping_t
  149. {
  150. #if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
  151. # if defined(BOOST_ASIO_NO_DEPRECATED)
  152. template <typename T>
  153. BOOST_ASIO_STATIC_CONSTEXPR(bool,
  154. is_applicable_property_v = (
  155. is_executor<T>::value));
  156. # else // defined(BOOST_ASIO_NO_DEPRECATED)
  157. template <typename T>
  158. BOOST_ASIO_STATIC_CONSTEXPR(bool,
  159. is_applicable_property_v = (
  160. is_executor<T>::value
  161. || conditional<
  162. is_executor<T>::value,
  163. false_type,
  164. is_sender<T>
  165. >::type::value
  166. || conditional<
  167. is_executor<T>::value,
  168. false_type,
  169. is_scheduler<T>
  170. >::type::value
  171. ));
  172. # endif // defined(BOOST_ASIO_NO_DEPRECATED)
  173. #endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
  174. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_requirable = false);
  175. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_preferable = false);
  176. typedef mapping_t polymorphic_query_result_type;
  177. typedef detail::mapping::thread_t<I> thread_t;
  178. typedef detail::mapping::new_thread_t<I> new_thread_t;
  179. typedef detail::mapping::other_t<I> other_t;
  180. BOOST_ASIO_CONSTEXPR mapping_t()
  181. : value_(-1)
  182. {
  183. }
  184. BOOST_ASIO_CONSTEXPR mapping_t(thread_t)
  185. : value_(0)
  186. {
  187. }
  188. BOOST_ASIO_CONSTEXPR mapping_t(new_thread_t)
  189. : value_(1)
  190. {
  191. }
  192. BOOST_ASIO_CONSTEXPR mapping_t(other_t)
  193. : value_(2)
  194. {
  195. }
  196. template <typename T>
  197. struct proxy
  198. {
  199. #if defined(BOOST_ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
  200. struct type
  201. {
  202. template <typename P>
  203. auto query(BOOST_ASIO_MOVE_ARG(P) p) const
  204. noexcept(
  205. noexcept(
  206. declval<typename conditional<true, T, P>::type>().query(
  207. BOOST_ASIO_MOVE_CAST(P)(p))
  208. )
  209. )
  210. -> decltype(
  211. declval<typename conditional<true, T, P>::type>().query(
  212. BOOST_ASIO_MOVE_CAST(P)(p))
  213. );
  214. };
  215. #else // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
  216. typedef T type;
  217. #endif // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
  218. };
  219. template <typename T>
  220. struct static_proxy
  221. {
  222. #if defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
  223. struct type
  224. {
  225. template <typename P>
  226. static constexpr auto query(BOOST_ASIO_MOVE_ARG(P) p)
  227. noexcept(
  228. noexcept(
  229. conditional<true, T, P>::type::query(BOOST_ASIO_MOVE_CAST(P)(p))
  230. )
  231. )
  232. -> decltype(
  233. conditional<true, T, P>::type::query(BOOST_ASIO_MOVE_CAST(P)(p))
  234. )
  235. {
  236. return T::query(BOOST_ASIO_MOVE_CAST(P)(p));
  237. }
  238. };
  239. #else // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
  240. typedef T type;
  241. #endif // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
  242. };
  243. template <typename T>
  244. struct query_member :
  245. traits::query_member<typename proxy<T>::type, mapping_t> {};
  246. template <typename T>
  247. struct query_static_constexpr_member :
  248. traits::query_static_constexpr_member<
  249. typename static_proxy<T>::type, mapping_t> {};
  250. #if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
  251. && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
  252. template <typename T>
  253. static BOOST_ASIO_CONSTEXPR
  254. typename query_static_constexpr_member<T>::result_type
  255. static_query()
  256. BOOST_ASIO_NOEXCEPT_IF((
  257. query_static_constexpr_member<T>::is_noexcept))
  258. {
  259. return query_static_constexpr_member<T>::value();
  260. }
  261. template <typename T>
  262. static BOOST_ASIO_CONSTEXPR
  263. typename traits::static_query<T, thread_t>::result_type
  264. static_query(
  265. typename enable_if<
  266. !query_static_constexpr_member<T>::is_valid
  267. >::type* = 0,
  268. typename enable_if<
  269. !query_member<T>::is_valid
  270. >::type* = 0,
  271. typename enable_if<
  272. traits::static_query<T, thread_t>::is_valid
  273. >::type* = 0) BOOST_ASIO_NOEXCEPT
  274. {
  275. return traits::static_query<T, thread_t>::value();
  276. }
  277. template <typename T>
  278. static BOOST_ASIO_CONSTEXPR
  279. typename traits::static_query<T, new_thread_t>::result_type
  280. static_query(
  281. typename enable_if<
  282. !query_static_constexpr_member<T>::is_valid
  283. >::type* = 0,
  284. typename enable_if<
  285. !query_member<T>::is_valid
  286. >::type* = 0,
  287. typename enable_if<
  288. !traits::static_query<T, thread_t>::is_valid
  289. >::type* = 0,
  290. typename enable_if<
  291. traits::static_query<T, new_thread_t>::is_valid
  292. >::type* = 0) BOOST_ASIO_NOEXCEPT
  293. {
  294. return traits::static_query<T, new_thread_t>::value();
  295. }
  296. template <typename T>
  297. static BOOST_ASIO_CONSTEXPR
  298. typename traits::static_query<T, other_t>::result_type
  299. static_query(
  300. typename enable_if<
  301. !query_static_constexpr_member<T>::is_valid
  302. >::type* = 0,
  303. typename enable_if<
  304. !query_member<T>::is_valid
  305. >::type* = 0,
  306. typename enable_if<
  307. !traits::static_query<T, thread_t>::is_valid
  308. >::type* = 0,
  309. typename enable_if<
  310. !traits::static_query<T, new_thread_t>::is_valid
  311. >::type* = 0,
  312. typename enable_if<
  313. traits::static_query<T, other_t>::is_valid
  314. >::type* = 0) BOOST_ASIO_NOEXCEPT
  315. {
  316. return traits::static_query<T, other_t>::value();
  317. }
  318. template <typename E, typename T = decltype(mapping_t::static_query<E>())>
  319. static BOOST_ASIO_CONSTEXPR const T static_query_v
  320. = mapping_t::static_query<E>();
  321. #endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
  322. // && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
  323. friend BOOST_ASIO_CONSTEXPR bool operator==(
  324. const mapping_t& a, const mapping_t& b)
  325. {
  326. return a.value_ == b.value_;
  327. }
  328. friend BOOST_ASIO_CONSTEXPR bool operator!=(
  329. const mapping_t& a, const mapping_t& b)
  330. {
  331. return a.value_ != b.value_;
  332. }
  333. struct convertible_from_mapping_t
  334. {
  335. BOOST_ASIO_CONSTEXPR convertible_from_mapping_t(mapping_t) {}
  336. };
  337. template <typename Executor>
  338. friend BOOST_ASIO_CONSTEXPR mapping_t query(
  339. const Executor& ex, convertible_from_mapping_t,
  340. typename enable_if<
  341. can_query<const Executor&, thread_t>::value
  342. >::type* = 0)
  343. #if !defined(__clang__) // Clang crashes if noexcept is used here.
  344. #if defined(BOOST_ASIO_MSVC) // Visual C++ wants the type to be qualified.
  345. BOOST_ASIO_NOEXCEPT_IF((
  346. is_nothrow_query<const Executor&, mapping_t<>::thread_t>::value))
  347. #else // defined(BOOST_ASIO_MSVC)
  348. BOOST_ASIO_NOEXCEPT_IF((
  349. is_nothrow_query<const Executor&, thread_t>::value))
  350. #endif // defined(BOOST_ASIO_MSVC)
  351. #endif // !defined(__clang__)
  352. {
  353. return boost::asio::query(ex, thread_t());
  354. }
  355. template <typename Executor>
  356. friend BOOST_ASIO_CONSTEXPR mapping_t query(
  357. const Executor& ex, convertible_from_mapping_t,
  358. typename enable_if<
  359. !can_query<const Executor&, thread_t>::value
  360. >::type* = 0,
  361. typename enable_if<
  362. can_query<const Executor&, new_thread_t>::value
  363. >::type* = 0)
  364. #if !defined(__clang__) // Clang crashes if noexcept is used here.
  365. #if defined(BOOST_ASIO_MSVC) // Visual C++ wants the type to be qualified.
  366. BOOST_ASIO_NOEXCEPT_IF((
  367. is_nothrow_query<const Executor&, mapping_t<>::new_thread_t>::value))
  368. #else // defined(BOOST_ASIO_MSVC)
  369. BOOST_ASIO_NOEXCEPT_IF((
  370. is_nothrow_query<const Executor&, new_thread_t>::value))
  371. #endif // defined(BOOST_ASIO_MSVC)
  372. #endif // !defined(__clang__)
  373. {
  374. return boost::asio::query(ex, new_thread_t());
  375. }
  376. template <typename Executor>
  377. friend BOOST_ASIO_CONSTEXPR mapping_t query(
  378. const Executor& ex, convertible_from_mapping_t,
  379. typename enable_if<
  380. !can_query<const Executor&, thread_t>::value
  381. >::type* = 0,
  382. typename enable_if<
  383. !can_query<const Executor&, new_thread_t>::value
  384. >::type* = 0,
  385. typename enable_if<
  386. can_query<const Executor&, other_t>::value
  387. >::type* = 0)
  388. #if !defined(__clang__) // Clang crashes if noexcept is used here.
  389. #if defined(BOOST_ASIO_MSVC) // Visual C++ wants the type to be qualified.
  390. BOOST_ASIO_NOEXCEPT_IF((
  391. is_nothrow_query<const Executor&, mapping_t<>::other_t>::value))
  392. #else // defined(BOOST_ASIO_MSVC)
  393. BOOST_ASIO_NOEXCEPT_IF((
  394. is_nothrow_query<const Executor&, other_t>::value))
  395. #endif // defined(BOOST_ASIO_MSVC)
  396. #endif // !defined(__clang__)
  397. {
  398. return boost::asio::query(ex, other_t());
  399. }
  400. BOOST_ASIO_STATIC_CONSTEXPR_DEFAULT_INIT(thread_t, thread);
  401. BOOST_ASIO_STATIC_CONSTEXPR_DEFAULT_INIT(new_thread_t, new_thread);
  402. BOOST_ASIO_STATIC_CONSTEXPR_DEFAULT_INIT(other_t, other);
  403. #if !defined(BOOST_ASIO_HAS_CONSTEXPR)
  404. static const mapping_t instance;
  405. #endif // !defined(BOOST_ASIO_HAS_CONSTEXPR)
  406. private:
  407. int value_;
  408. };
  409. #if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
  410. && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
  411. template <int I> template <typename E, typename T>
  412. const T mapping_t<I>::static_query_v;
  413. #endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
  414. // && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
  415. #if !defined(BOOST_ASIO_HAS_CONSTEXPR)
  416. template <int I>
  417. const mapping_t<I> mapping_t<I>::instance;
  418. #endif
  419. template <int I>
  420. const typename mapping_t<I>::thread_t mapping_t<I>::thread;
  421. template <int I>
  422. const typename mapping_t<I>::new_thread_t mapping_t<I>::new_thread;
  423. template <int I>
  424. const typename mapping_t<I>::other_t mapping_t<I>::other;
  425. namespace mapping {
  426. template <int I = 0>
  427. struct thread_t
  428. {
  429. #if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
  430. # if defined(BOOST_ASIO_NO_DEPRECATED)
  431. template <typename T>
  432. BOOST_ASIO_STATIC_CONSTEXPR(bool,
  433. is_applicable_property_v = (
  434. is_executor<T>::value));
  435. # else // defined(BOOST_ASIO_NO_DEPRECATED)
  436. template <typename T>
  437. BOOST_ASIO_STATIC_CONSTEXPR(bool,
  438. is_applicable_property_v = (
  439. is_executor<T>::value
  440. || conditional<
  441. is_executor<T>::value,
  442. false_type,
  443. is_sender<T>
  444. >::type::value
  445. || conditional<
  446. is_executor<T>::value,
  447. false_type,
  448. is_scheduler<T>
  449. >::type::value
  450. ));
  451. # endif // defined(BOOST_ASIO_NO_DEPRECATED)
  452. #endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
  453. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_requirable = true);
  454. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_preferable = true);
  455. typedef mapping_t<I> polymorphic_query_result_type;
  456. BOOST_ASIO_CONSTEXPR thread_t()
  457. {
  458. }
  459. template <typename T>
  460. struct query_member :
  461. traits::query_member<
  462. typename mapping_t<I>::template proxy<T>::type, thread_t> {};
  463. template <typename T>
  464. struct query_static_constexpr_member :
  465. traits::query_static_constexpr_member<
  466. typename mapping_t<I>::template static_proxy<T>::type, thread_t> {};
  467. #if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
  468. && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
  469. template <typename T>
  470. static BOOST_ASIO_CONSTEXPR
  471. typename query_static_constexpr_member<T>::result_type
  472. static_query()
  473. BOOST_ASIO_NOEXCEPT_IF((
  474. query_static_constexpr_member<T>::is_noexcept))
  475. {
  476. return query_static_constexpr_member<T>::value();
  477. }
  478. template <typename T>
  479. static BOOST_ASIO_CONSTEXPR thread_t static_query(
  480. typename enable_if<
  481. !query_static_constexpr_member<T>::is_valid
  482. >::type* = 0,
  483. typename enable_if<
  484. !query_member<T>::is_valid
  485. >::type* = 0,
  486. typename enable_if<
  487. !traits::query_free<T, thread_t>::is_valid
  488. >::type* = 0,
  489. typename enable_if<
  490. !can_query<T, new_thread_t<I> >::value
  491. >::type* = 0,
  492. typename enable_if<
  493. !can_query<T, other_t<I> >::value
  494. >::type* = 0) BOOST_ASIO_NOEXCEPT
  495. {
  496. return thread_t();
  497. }
  498. template <typename E, typename T = decltype(thread_t::static_query<E>())>
  499. static BOOST_ASIO_CONSTEXPR const T static_query_v
  500. = thread_t::static_query<E>();
  501. #endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
  502. // && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
  503. static BOOST_ASIO_CONSTEXPR mapping_t<I> value()
  504. {
  505. return thread_t();
  506. }
  507. friend BOOST_ASIO_CONSTEXPR bool operator==(
  508. const thread_t&, const thread_t&)
  509. {
  510. return true;
  511. }
  512. friend BOOST_ASIO_CONSTEXPR bool operator!=(
  513. const thread_t&, const thread_t&)
  514. {
  515. return false;
  516. }
  517. };
  518. #if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
  519. && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
  520. template <int I> template <typename E, typename T>
  521. const T thread_t<I>::static_query_v;
  522. #endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
  523. // && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
  524. template <int I = 0>
  525. struct new_thread_t
  526. {
  527. #if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
  528. # if defined(BOOST_ASIO_NO_DEPRECATED)
  529. template <typename T>
  530. BOOST_ASIO_STATIC_CONSTEXPR(bool,
  531. is_applicable_property_v = (
  532. is_executor<T>::value));
  533. # else // defined(BOOST_ASIO_NO_DEPRECATED)
  534. template <typename T>
  535. BOOST_ASIO_STATIC_CONSTEXPR(bool,
  536. is_applicable_property_v = (
  537. is_executor<T>::value
  538. || conditional<
  539. is_executor<T>::value,
  540. false_type,
  541. is_sender<T>
  542. >::type::value
  543. || conditional<
  544. is_executor<T>::value,
  545. false_type,
  546. is_scheduler<T>
  547. >::type::value
  548. ));
  549. # endif // defined(BOOST_ASIO_NO_DEPRECATED)
  550. #endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
  551. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_requirable = true);
  552. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_preferable = true);
  553. typedef mapping_t<I> polymorphic_query_result_type;
  554. BOOST_ASIO_CONSTEXPR new_thread_t()
  555. {
  556. }
  557. template <typename T>
  558. struct query_member :
  559. traits::query_member<
  560. typename mapping_t<I>::template proxy<T>::type, new_thread_t> {};
  561. template <typename T>
  562. struct query_static_constexpr_member :
  563. traits::query_static_constexpr_member<
  564. typename mapping_t<I>::template static_proxy<T>::type, new_thread_t> {};
  565. #if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
  566. && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
  567. template <typename T>
  568. static BOOST_ASIO_CONSTEXPR
  569. typename query_static_constexpr_member<T>::result_type
  570. static_query()
  571. BOOST_ASIO_NOEXCEPT_IF((
  572. query_static_constexpr_member<T>::is_noexcept))
  573. {
  574. return query_static_constexpr_member<T>::value();
  575. }
  576. template <typename E, typename T = decltype(new_thread_t::static_query<E>())>
  577. static BOOST_ASIO_CONSTEXPR const T static_query_v
  578. = new_thread_t::static_query<E>();
  579. #endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
  580. // && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
  581. static BOOST_ASIO_CONSTEXPR mapping_t<I> value()
  582. {
  583. return new_thread_t();
  584. }
  585. friend BOOST_ASIO_CONSTEXPR bool operator==(
  586. const new_thread_t&, const new_thread_t&)
  587. {
  588. return true;
  589. }
  590. friend BOOST_ASIO_CONSTEXPR bool operator!=(
  591. const new_thread_t&, const new_thread_t&)
  592. {
  593. return false;
  594. }
  595. };
  596. #if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
  597. && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
  598. template <int I> template <typename E, typename T>
  599. const T new_thread_t<I>::static_query_v;
  600. #endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
  601. // && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
  602. template <int I>
  603. struct other_t
  604. {
  605. #if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
  606. # if defined(BOOST_ASIO_NO_DEPRECATED)
  607. template <typename T>
  608. BOOST_ASIO_STATIC_CONSTEXPR(bool,
  609. is_applicable_property_v = (
  610. is_executor<T>::value));
  611. # else // defined(BOOST_ASIO_NO_DEPRECATED)
  612. template <typename T>
  613. BOOST_ASIO_STATIC_CONSTEXPR(bool,
  614. is_applicable_property_v = (
  615. is_executor<T>::value
  616. || conditional<
  617. is_executor<T>::value,
  618. false_type,
  619. is_sender<T>
  620. >::type::value
  621. || conditional<
  622. is_executor<T>::value,
  623. false_type,
  624. is_scheduler<T>
  625. >::type::value
  626. ));
  627. # endif // defined(BOOST_ASIO_NO_DEPRECATED)
  628. #endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
  629. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_requirable = true);
  630. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_preferable = true);
  631. typedef mapping_t<I> polymorphic_query_result_type;
  632. BOOST_ASIO_CONSTEXPR other_t()
  633. {
  634. }
  635. template <typename T>
  636. struct query_member :
  637. traits::query_member<
  638. typename mapping_t<I>::template proxy<T>::type, other_t> {};
  639. template <typename T>
  640. struct query_static_constexpr_member :
  641. traits::query_static_constexpr_member<
  642. typename mapping_t<I>::template static_proxy<T>::type, other_t> {};
  643. #if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
  644. && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
  645. template <typename T>
  646. static BOOST_ASIO_CONSTEXPR
  647. typename query_static_constexpr_member<T>::result_type
  648. static_query()
  649. BOOST_ASIO_NOEXCEPT_IF((
  650. query_static_constexpr_member<T>::is_noexcept))
  651. {
  652. return query_static_constexpr_member<T>::value();
  653. }
  654. template <typename E, typename T = decltype(other_t::static_query<E>())>
  655. static BOOST_ASIO_CONSTEXPR const T static_query_v
  656. = other_t::static_query<E>();
  657. #endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
  658. // && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
  659. static BOOST_ASIO_CONSTEXPR mapping_t<I> value()
  660. {
  661. return other_t();
  662. }
  663. friend BOOST_ASIO_CONSTEXPR bool operator==(
  664. const other_t&, const other_t&)
  665. {
  666. return true;
  667. }
  668. friend BOOST_ASIO_CONSTEXPR bool operator!=(
  669. const other_t&, const other_t&)
  670. {
  671. return false;
  672. }
  673. };
  674. #if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
  675. && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
  676. template <int I> template <typename E, typename T>
  677. const T other_t<I>::static_query_v;
  678. #endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
  679. // && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
  680. } // namespace mapping
  681. } // namespace detail
  682. typedef detail::mapping_t<> mapping_t;
  683. #if defined(BOOST_ASIO_HAS_CONSTEXPR) || defined(GENERATING_DOCUMENTATION)
  684. constexpr mapping_t mapping;
  685. #else // defined(BOOST_ASIO_HAS_CONSTEXPR) || defined(GENERATING_DOCUMENTATION)
  686. namespace { static const mapping_t& mapping = mapping_t::instance; }
  687. #endif
  688. } // namespace execution
  689. #if !defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
  690. template <typename T>
  691. struct is_applicable_property<T, execution::mapping_t>
  692. : integral_constant<bool,
  693. execution::is_executor<T>::value
  694. #if !defined(BOOST_ASIO_NO_DEPRECATED)
  695. || conditional<
  696. execution::is_executor<T>::value,
  697. false_type,
  698. execution::is_sender<T>
  699. >::type::value
  700. || conditional<
  701. execution::is_executor<T>::value,
  702. false_type,
  703. execution::is_scheduler<T>
  704. >::type::value
  705. #endif // !defined(BOOST_ASIO_NO_DEPRECATED)
  706. >
  707. {
  708. };
  709. template <typename T>
  710. struct is_applicable_property<T, execution::mapping_t::thread_t>
  711. : integral_constant<bool,
  712. execution::is_executor<T>::value
  713. #if !defined(BOOST_ASIO_NO_DEPRECATED)
  714. || conditional<
  715. execution::is_executor<T>::value,
  716. false_type,
  717. execution::is_sender<T>
  718. >::type::value
  719. || conditional<
  720. execution::is_executor<T>::value,
  721. false_type,
  722. execution::is_scheduler<T>
  723. >::type::value
  724. #endif // !defined(BOOST_ASIO_NO_DEPRECATED)
  725. >
  726. {
  727. };
  728. template <typename T>
  729. struct is_applicable_property<T, execution::mapping_t::new_thread_t>
  730. : integral_constant<bool,
  731. execution::is_executor<T>::value
  732. #if !defined(BOOST_ASIO_NO_DEPRECATED)
  733. || conditional<
  734. execution::is_executor<T>::value,
  735. false_type,
  736. execution::is_sender<T>
  737. >::type::value
  738. || conditional<
  739. execution::is_executor<T>::value,
  740. false_type,
  741. execution::is_scheduler<T>
  742. >::type::value
  743. #endif // !defined(BOOST_ASIO_NO_DEPRECATED)
  744. >
  745. {
  746. };
  747. template <typename T>
  748. struct is_applicable_property<T, execution::mapping_t::other_t>
  749. : integral_constant<bool,
  750. execution::is_executor<T>::value
  751. #if !defined(BOOST_ASIO_NO_DEPRECATED)
  752. || conditional<
  753. execution::is_executor<T>::value,
  754. false_type,
  755. execution::is_sender<T>
  756. >::type::value
  757. || conditional<
  758. execution::is_executor<T>::value,
  759. false_type,
  760. execution::is_scheduler<T>
  761. >::type::value
  762. #endif // !defined(BOOST_ASIO_NO_DEPRECATED)
  763. >
  764. {
  765. };
  766. #endif // !defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
  767. namespace traits {
  768. #if !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_FREE_TRAIT)
  769. template <typename T>
  770. struct query_free_default<T, execution::mapping_t,
  771. typename enable_if<
  772. can_query<T, execution::mapping_t::thread_t>::value
  773. >::type>
  774. {
  775. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
  776. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept =
  777. (is_nothrow_query<T, execution::mapping_t::thread_t>::value));
  778. typedef execution::mapping_t result_type;
  779. };
  780. template <typename T>
  781. struct query_free_default<T, execution::mapping_t,
  782. typename enable_if<
  783. !can_query<T, execution::mapping_t::thread_t>::value
  784. && can_query<T, execution::mapping_t::new_thread_t>::value
  785. >::type>
  786. {
  787. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
  788. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept =
  789. (is_nothrow_query<T, execution::mapping_t::new_thread_t>::value));
  790. typedef execution::mapping_t result_type;
  791. };
  792. template <typename T>
  793. struct query_free_default<T, execution::mapping_t,
  794. typename enable_if<
  795. !can_query<T, execution::mapping_t::thread_t>::value
  796. && !can_query<T, execution::mapping_t::new_thread_t>::value
  797. && can_query<T, execution::mapping_t::other_t>::value
  798. >::type>
  799. {
  800. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
  801. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept =
  802. (is_nothrow_query<T, execution::mapping_t::other_t>::value));
  803. typedef execution::mapping_t result_type;
  804. };
  805. #endif // !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_FREE_TRAIT)
  806. #if !defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
  807. || !defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
  808. template <typename T>
  809. struct static_query<T, execution::mapping_t,
  810. typename enable_if<
  811. execution::detail::mapping_t<0>::
  812. query_static_constexpr_member<T>::is_valid
  813. >::type>
  814. {
  815. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
  816. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
  817. typedef typename execution::detail::mapping_t<0>::
  818. query_static_constexpr_member<T>::result_type result_type;
  819. static BOOST_ASIO_CONSTEXPR result_type value()
  820. {
  821. return execution::detail::mapping_t<0>::
  822. query_static_constexpr_member<T>::value();
  823. }
  824. };
  825. template <typename T>
  826. struct static_query<T, execution::mapping_t,
  827. typename enable_if<
  828. !execution::detail::mapping_t<0>::
  829. query_static_constexpr_member<T>::is_valid
  830. && !execution::detail::mapping_t<0>::
  831. query_member<T>::is_valid
  832. && traits::static_query<T, execution::mapping_t::thread_t>::is_valid
  833. >::type>
  834. {
  835. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
  836. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
  837. typedef typename traits::static_query<T,
  838. execution::mapping_t::thread_t>::result_type result_type;
  839. static BOOST_ASIO_CONSTEXPR result_type value()
  840. {
  841. return traits::static_query<T, execution::mapping_t::thread_t>::value();
  842. }
  843. };
  844. template <typename T>
  845. struct static_query<T, execution::mapping_t,
  846. typename enable_if<
  847. !execution::detail::mapping_t<0>::
  848. query_static_constexpr_member<T>::is_valid
  849. && !execution::detail::mapping_t<0>::
  850. query_member<T>::is_valid
  851. && !traits::static_query<T, execution::mapping_t::thread_t>::is_valid
  852. && traits::static_query<T, execution::mapping_t::new_thread_t>::is_valid
  853. >::type>
  854. {
  855. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
  856. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
  857. typedef typename traits::static_query<T,
  858. execution::mapping_t::new_thread_t>::result_type result_type;
  859. static BOOST_ASIO_CONSTEXPR result_type value()
  860. {
  861. return traits::static_query<T, execution::mapping_t::new_thread_t>::value();
  862. }
  863. };
  864. template <typename T>
  865. struct static_query<T, execution::mapping_t,
  866. typename enable_if<
  867. !execution::detail::mapping_t<0>::
  868. query_static_constexpr_member<T>::is_valid
  869. && !execution::detail::mapping_t<0>::
  870. query_member<T>::is_valid
  871. && !traits::static_query<T, execution::mapping_t::thread_t>::is_valid
  872. && !traits::static_query<T, execution::mapping_t::new_thread_t>::is_valid
  873. && traits::static_query<T, execution::mapping_t::other_t>::is_valid
  874. >::type>
  875. {
  876. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
  877. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
  878. typedef typename traits::static_query<T,
  879. execution::mapping_t::other_t>::result_type result_type;
  880. static BOOST_ASIO_CONSTEXPR result_type value()
  881. {
  882. return traits::static_query<T, execution::mapping_t::other_t>::value();
  883. }
  884. };
  885. template <typename T>
  886. struct static_query<T, execution::mapping_t::thread_t,
  887. typename enable_if<
  888. execution::detail::mapping::thread_t<0>::
  889. query_static_constexpr_member<T>::is_valid
  890. >::type>
  891. {
  892. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
  893. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
  894. typedef typename execution::detail::mapping::thread_t<0>::
  895. query_static_constexpr_member<T>::result_type result_type;
  896. static BOOST_ASIO_CONSTEXPR result_type value()
  897. {
  898. return execution::detail::mapping::thread_t<0>::
  899. query_static_constexpr_member<T>::value();
  900. }
  901. };
  902. template <typename T>
  903. struct static_query<T, execution::mapping_t::thread_t,
  904. typename enable_if<
  905. !execution::detail::mapping::thread_t<0>::
  906. query_static_constexpr_member<T>::is_valid
  907. && !execution::detail::mapping::thread_t<0>::
  908. query_member<T>::is_valid
  909. && !traits::query_free<T, execution::mapping_t::thread_t>::is_valid
  910. && !can_query<T, execution::mapping_t::new_thread_t>::value
  911. && !can_query<T, execution::mapping_t::other_t>::value
  912. >::type>
  913. {
  914. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
  915. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
  916. typedef execution::mapping_t::thread_t result_type;
  917. static BOOST_ASIO_CONSTEXPR result_type value()
  918. {
  919. return result_type();
  920. }
  921. };
  922. template <typename T>
  923. struct static_query<T, execution::mapping_t::new_thread_t,
  924. typename enable_if<
  925. execution::detail::mapping::new_thread_t<0>::
  926. query_static_constexpr_member<T>::is_valid
  927. >::type>
  928. {
  929. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
  930. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
  931. typedef typename execution::detail::mapping::new_thread_t<0>::
  932. query_static_constexpr_member<T>::result_type result_type;
  933. static BOOST_ASIO_CONSTEXPR result_type value()
  934. {
  935. return execution::detail::mapping::new_thread_t<0>::
  936. query_static_constexpr_member<T>::value();
  937. }
  938. };
  939. template <typename T>
  940. struct static_query<T, execution::mapping_t::other_t,
  941. typename enable_if<
  942. execution::detail::mapping::other_t<0>::
  943. query_static_constexpr_member<T>::is_valid
  944. >::type>
  945. {
  946. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
  947. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
  948. typedef typename execution::detail::mapping::other_t<0>::
  949. query_static_constexpr_member<T>::result_type result_type;
  950. static BOOST_ASIO_CONSTEXPR result_type value()
  951. {
  952. return execution::detail::mapping::other_t<0>::
  953. query_static_constexpr_member<T>::value();
  954. }
  955. };
  956. #endif // !defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
  957. // || !defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
  958. #if !defined(BOOST_ASIO_HAS_DEDUCED_STATIC_REQUIRE_TRAIT)
  959. template <typename T>
  960. struct static_require<T, execution::mapping_t::thread_t,
  961. typename enable_if<
  962. static_query<T, execution::mapping_t::thread_t>::is_valid
  963. >::type>
  964. {
  965. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid =
  966. (is_same<typename static_query<T,
  967. execution::mapping_t::thread_t>::result_type,
  968. execution::mapping_t::thread_t>::value));
  969. };
  970. template <typename T>
  971. struct static_require<T, execution::mapping_t::new_thread_t,
  972. typename enable_if<
  973. static_query<T, execution::mapping_t::new_thread_t>::is_valid
  974. >::type>
  975. {
  976. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid =
  977. (is_same<typename static_query<T,
  978. execution::mapping_t::new_thread_t>::result_type,
  979. execution::mapping_t::new_thread_t>::value));
  980. };
  981. template <typename T>
  982. struct static_require<T, execution::mapping_t::other_t,
  983. typename enable_if<
  984. static_query<T, execution::mapping_t::other_t>::is_valid
  985. >::type>
  986. {
  987. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid =
  988. (is_same<typename static_query<T,
  989. execution::mapping_t::other_t>::result_type,
  990. execution::mapping_t::other_t>::value));
  991. };
  992. #endif // !defined(BOOST_ASIO_HAS_DEDUCED_STATIC_REQUIRE_TRAIT)
  993. } // namespace traits
  994. #endif // defined(GENERATING_DOCUMENTATION)
  995. } // namespace asio
  996. } // namespace boost
  997. #include <boost/asio/detail/pop_options.hpp>
  998. #endif // BOOST_ASIO_EXECUTION_MAPPING_HPP