relationship.hpp 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867
  1. //
  2. // execution/relationship.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_EXECUTION_RELATIONSHIP_HPP
  11. #define BOOST_ASIO_EXECUTION_RELATIONSHIP_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 whether submitted tasks represent continuations of
  33. /// the calling context.
  34. struct relationship_t
  35. {
  36. /// The relationship_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 relationship_t property cannot be required.
  41. static constexpr bool is_requirable = false;
  42. /// The top-level relationship_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 relationship_t polymorphic_query_result_type;
  46. /// A sub-property that indicates that the executor does not represent a
  47. /// continuation of the calling context.
  48. struct fork_t
  49. {
  50. /// The relationship_t::fork_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 relationship_t::fork_t property can be required.
  56. static constexpr bool is_requirable = true;
  57. /// The relationship_t::fork_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 relationship_t polymorphic_query_result_type;
  61. /// Default constructor.
  62. constexpr fork_t();
  63. /// Get the value associated with a property object.
  64. /**
  65. * @returns fork_t();
  66. */
  67. static constexpr relationship_t value();
  68. };
  69. /// A sub-property that indicates that the executor represents a continuation
  70. /// of the calling context.
  71. struct continuation_t
  72. {
  73. /// The relationship_t::continuation_t property applies to executors,
  74. /// senders, and 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 relationship_t::continuation_t property can be required.
  79. static constexpr bool is_requirable = true;
  80. /// The relationship_t::continuation_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 relationship_t polymorphic_query_result_type;
  84. /// Default constructor.
  85. constexpr continuation_t();
  86. /// Get the value associated with a property object.
  87. /**
  88. * @returns continuation_t();
  89. */
  90. static constexpr relationship_t value();
  91. };
  92. /// A special value used for accessing the relationship_t::fork_t property.
  93. static constexpr fork_t fork;
  94. /// A special value used for accessing the relationship_t::continuation_t
  95. /// property.
  96. static constexpr continuation_t continuation;
  97. /// Default constructor.
  98. constexpr relationship_t();
  99. /// Construct from a sub-property value.
  100. constexpr relationship_t(fork_t);
  101. /// Construct from a sub-property value.
  102. constexpr relationship_t(continuation_t);
  103. /// Compare property values for equality.
  104. friend constexpr bool operator==(
  105. const relationship_t& a, const relationship_t& b) noexcept;
  106. /// Compare property values for inequality.
  107. friend constexpr bool operator!=(
  108. const relationship_t& a, const relationship_t& b) noexcept;
  109. };
  110. /// A special value used for accessing the relationship_t property.
  111. constexpr relationship_t relationship;
  112. } // namespace execution
  113. #else // defined(GENERATING_DOCUMENTATION)
  114. namespace execution {
  115. namespace detail {
  116. namespace relationship {
  117. template <int I> struct fork_t;
  118. template <int I> struct continuation_t;
  119. } // namespace relationship
  120. template <int I = 0>
  121. struct relationship_t
  122. {
  123. #if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
  124. template <typename T>
  125. BOOST_ASIO_STATIC_CONSTEXPR(bool,
  126. is_applicable_property_v = (
  127. is_executor<T>::value
  128. || conditional<
  129. is_executor<T>::value,
  130. false_type,
  131. is_sender<T>
  132. >::type::value
  133. || conditional<
  134. is_executor<T>::value,
  135. false_type,
  136. is_scheduler<T>
  137. >::type::value));
  138. #endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
  139. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_requirable = false);
  140. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_preferable = false);
  141. typedef relationship_t polymorphic_query_result_type;
  142. typedef detail::relationship::fork_t<I> fork_t;
  143. typedef detail::relationship::continuation_t<I> continuation_t;
  144. BOOST_ASIO_CONSTEXPR relationship_t()
  145. : value_(-1)
  146. {
  147. }
  148. BOOST_ASIO_CONSTEXPR relationship_t(fork_t)
  149. : value_(0)
  150. {
  151. }
  152. BOOST_ASIO_CONSTEXPR relationship_t(continuation_t)
  153. : value_(1)
  154. {
  155. }
  156. template <typename T>
  157. struct proxy
  158. {
  159. #if defined(BOOST_ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
  160. struct type
  161. {
  162. template <typename P>
  163. auto query(BOOST_ASIO_MOVE_ARG(P) p) const
  164. noexcept(
  165. noexcept(
  166. declval<typename conditional<true, T, P>::type>().query(
  167. BOOST_ASIO_MOVE_CAST(P)(p))
  168. )
  169. )
  170. -> decltype(
  171. declval<typename conditional<true, T, P>::type>().query(
  172. BOOST_ASIO_MOVE_CAST(P)(p))
  173. );
  174. };
  175. #else // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
  176. typedef T type;
  177. #endif // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
  178. };
  179. template <typename T>
  180. struct static_proxy
  181. {
  182. #if defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
  183. struct type
  184. {
  185. template <typename P>
  186. static constexpr auto query(BOOST_ASIO_MOVE_ARG(P) p)
  187. noexcept(
  188. noexcept(
  189. conditional<true, T, P>::type::query(BOOST_ASIO_MOVE_CAST(P)(p))
  190. )
  191. )
  192. -> decltype(
  193. conditional<true, T, P>::type::query(BOOST_ASIO_MOVE_CAST(P)(p))
  194. )
  195. {
  196. return T::query(BOOST_ASIO_MOVE_CAST(P)(p));
  197. }
  198. };
  199. #else // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
  200. typedef T type;
  201. #endif // defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
  202. };
  203. template <typename T>
  204. struct query_member :
  205. traits::query_member<typename proxy<T>::type, relationship_t> {};
  206. template <typename T>
  207. struct query_static_constexpr_member :
  208. traits::query_static_constexpr_member<
  209. typename static_proxy<T>::type, relationship_t> {};
  210. #if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
  211. && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
  212. template <typename T>
  213. static BOOST_ASIO_CONSTEXPR
  214. typename query_static_constexpr_member<T>::result_type
  215. static_query()
  216. BOOST_ASIO_NOEXCEPT_IF((
  217. query_static_constexpr_member<T>::is_noexcept))
  218. {
  219. return query_static_constexpr_member<T>::value();
  220. }
  221. template <typename T>
  222. static BOOST_ASIO_CONSTEXPR
  223. typename traits::static_query<T, fork_t>::result_type
  224. static_query(
  225. typename enable_if<
  226. !query_static_constexpr_member<T>::is_valid
  227. >::type* = 0,
  228. typename enable_if<
  229. !query_member<T>::is_valid
  230. >::type* = 0,
  231. typename enable_if<
  232. traits::static_query<T, fork_t>::is_valid
  233. >::type* = 0) BOOST_ASIO_NOEXCEPT
  234. {
  235. return traits::static_query<T, fork_t>::value();
  236. }
  237. template <typename T>
  238. static BOOST_ASIO_CONSTEXPR
  239. typename traits::static_query<T, continuation_t>::result_type
  240. static_query(
  241. typename enable_if<
  242. !query_static_constexpr_member<T>::is_valid
  243. >::type* = 0,
  244. typename enable_if<
  245. !query_member<T>::is_valid
  246. >::type* = 0,
  247. typename enable_if<
  248. !traits::static_query<T, fork_t>::is_valid
  249. >::type* = 0,
  250. typename enable_if<
  251. traits::static_query<T, continuation_t>::is_valid
  252. >::type* = 0) BOOST_ASIO_NOEXCEPT
  253. {
  254. return traits::static_query<T, continuation_t>::value();
  255. }
  256. template <typename E,
  257. typename T = decltype(relationship_t::static_query<E>())>
  258. static BOOST_ASIO_CONSTEXPR const T static_query_v
  259. = relationship_t::static_query<E>();
  260. #endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
  261. // && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
  262. friend BOOST_ASIO_CONSTEXPR bool operator==(
  263. const relationship_t& a, const relationship_t& b)
  264. {
  265. return a.value_ == b.value_;
  266. }
  267. friend BOOST_ASIO_CONSTEXPR bool operator!=(
  268. const relationship_t& a, const relationship_t& b)
  269. {
  270. return a.value_ != b.value_;
  271. }
  272. struct convertible_from_relationship_t
  273. {
  274. BOOST_ASIO_CONSTEXPR convertible_from_relationship_t(relationship_t)
  275. {
  276. }
  277. };
  278. template <typename Executor>
  279. friend BOOST_ASIO_CONSTEXPR relationship_t query(
  280. const Executor& ex, convertible_from_relationship_t,
  281. typename enable_if<
  282. can_query<const Executor&, fork_t>::value
  283. >::type* = 0)
  284. #if !defined(__clang__) // Clang crashes if noexcept is used here.
  285. #if defined(BOOST_ASIO_MSVC) // Visual C++ wants the type to be qualified.
  286. BOOST_ASIO_NOEXCEPT_IF((
  287. is_nothrow_query<const Executor&, relationship_t<>::fork_t>::value))
  288. #else // defined(BOOST_ASIO_MSVC)
  289. BOOST_ASIO_NOEXCEPT_IF((
  290. is_nothrow_query<const Executor&, fork_t>::value))
  291. #endif // defined(BOOST_ASIO_MSVC)
  292. #endif // !defined(__clang__)
  293. {
  294. return boost::asio::query(ex, fork_t());
  295. }
  296. template <typename Executor>
  297. friend BOOST_ASIO_CONSTEXPR relationship_t query(
  298. const Executor& ex, convertible_from_relationship_t,
  299. typename enable_if<
  300. !can_query<const Executor&, fork_t>::value
  301. >::type* = 0,
  302. typename enable_if<
  303. can_query<const Executor&, continuation_t>::value
  304. >::type* = 0)
  305. #if !defined(__clang__) // Clang crashes if noexcept is used here.
  306. #if defined(BOOST_ASIO_MSVC) // Visual C++ wants the type to be qualified.
  307. BOOST_ASIO_NOEXCEPT_IF((
  308. is_nothrow_query<const Executor&,
  309. relationship_t<>::continuation_t>::value))
  310. #else // defined(BOOST_ASIO_MSVC)
  311. BOOST_ASIO_NOEXCEPT_IF((
  312. is_nothrow_query<const Executor&, continuation_t>::value))
  313. #endif // defined(BOOST_ASIO_MSVC)
  314. #endif // !defined(__clang__)
  315. {
  316. return boost::asio::query(ex, continuation_t());
  317. }
  318. BOOST_ASIO_STATIC_CONSTEXPR_DEFAULT_INIT(fork_t, fork);
  319. BOOST_ASIO_STATIC_CONSTEXPR_DEFAULT_INIT(continuation_t, continuation);
  320. #if !defined(BOOST_ASIO_HAS_CONSTEXPR)
  321. static const relationship_t instance;
  322. #endif // !defined(BOOST_ASIO_HAS_CONSTEXPR)
  323. private:
  324. int value_;
  325. };
  326. #if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
  327. && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
  328. template <int I> template <typename E, typename T>
  329. const T relationship_t<I>::static_query_v;
  330. #endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
  331. // && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
  332. #if !defined(BOOST_ASIO_HAS_CONSTEXPR)
  333. template <int I>
  334. const relationship_t<I> relationship_t<I>::instance;
  335. #endif
  336. template <int I>
  337. const typename relationship_t<I>::fork_t
  338. relationship_t<I>::fork;
  339. template <int I>
  340. const typename relationship_t<I>::continuation_t
  341. relationship_t<I>::continuation;
  342. namespace relationship {
  343. template <int I = 0>
  344. struct fork_t
  345. {
  346. #if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
  347. template <typename T>
  348. BOOST_ASIO_STATIC_CONSTEXPR(bool,
  349. is_applicable_property_v = (
  350. is_executor<T>::value
  351. || conditional<
  352. is_executor<T>::value,
  353. false_type,
  354. is_sender<T>
  355. >::type::value
  356. || conditional<
  357. is_executor<T>::value,
  358. false_type,
  359. is_scheduler<T>
  360. >::type::value));
  361. #endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
  362. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_requirable = true);
  363. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_preferable = true);
  364. typedef relationship_t<I> polymorphic_query_result_type;
  365. BOOST_ASIO_CONSTEXPR fork_t()
  366. {
  367. }
  368. template <typename T>
  369. struct query_member :
  370. traits::query_member<
  371. typename relationship_t<I>::template proxy<T>::type, fork_t> {};
  372. template <typename T>
  373. struct query_static_constexpr_member :
  374. traits::query_static_constexpr_member<
  375. typename relationship_t<I>::template static_proxy<T>::type, fork_t> {};
  376. #if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
  377. && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
  378. template <typename T>
  379. static BOOST_ASIO_CONSTEXPR
  380. typename query_static_constexpr_member<T>::result_type
  381. static_query()
  382. BOOST_ASIO_NOEXCEPT_IF((
  383. query_static_constexpr_member<T>::is_noexcept))
  384. {
  385. return query_static_constexpr_member<T>::value();
  386. }
  387. template <typename T>
  388. static BOOST_ASIO_CONSTEXPR fork_t static_query(
  389. typename enable_if<
  390. !query_static_constexpr_member<T>::is_valid
  391. >::type* = 0,
  392. typename enable_if<
  393. !query_member<T>::is_valid
  394. >::type* = 0,
  395. typename enable_if<
  396. !traits::query_free<T, fork_t>::is_valid
  397. >::type* = 0,
  398. typename enable_if<
  399. !can_query<T, continuation_t<I> >::value
  400. >::type* = 0) BOOST_ASIO_NOEXCEPT
  401. {
  402. return fork_t();
  403. }
  404. template <typename E, typename T = decltype(fork_t::static_query<E>())>
  405. static BOOST_ASIO_CONSTEXPR const T static_query_v
  406. = fork_t::static_query<E>();
  407. #endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
  408. // && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
  409. static BOOST_ASIO_CONSTEXPR relationship_t<I> value()
  410. {
  411. return fork_t();
  412. }
  413. friend BOOST_ASIO_CONSTEXPR bool operator==(
  414. const fork_t&, const fork_t&)
  415. {
  416. return true;
  417. }
  418. friend BOOST_ASIO_CONSTEXPR bool operator!=(
  419. const fork_t&, const fork_t&)
  420. {
  421. return false;
  422. }
  423. };
  424. #if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
  425. && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
  426. template <int I> template <typename E, typename T>
  427. const T fork_t<I>::static_query_v;
  428. #endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
  429. // && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
  430. template <int I = 0>
  431. struct continuation_t
  432. {
  433. #if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
  434. template <typename T>
  435. BOOST_ASIO_STATIC_CONSTEXPR(bool,
  436. is_applicable_property_v = (
  437. is_executor<T>::value
  438. || conditional<
  439. is_executor<T>::value,
  440. false_type,
  441. is_sender<T>
  442. >::type::value
  443. || conditional<
  444. is_executor<T>::value,
  445. false_type,
  446. is_scheduler<T>
  447. >::type::value));
  448. #endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
  449. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_requirable = true);
  450. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_preferable = true);
  451. typedef relationship_t<I> polymorphic_query_result_type;
  452. BOOST_ASIO_CONSTEXPR continuation_t()
  453. {
  454. }
  455. template <typename T>
  456. struct query_member :
  457. traits::query_member<
  458. typename relationship_t<I>::template proxy<T>::type, continuation_t> {};
  459. template <typename T>
  460. struct query_static_constexpr_member :
  461. traits::query_static_constexpr_member<
  462. typename relationship_t<I>::template static_proxy<T>::type,
  463. continuation_t> {};
  464. #if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
  465. && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
  466. template <typename T>
  467. static BOOST_ASIO_CONSTEXPR
  468. typename query_static_constexpr_member<T>::result_type
  469. static_query()
  470. BOOST_ASIO_NOEXCEPT_IF((
  471. query_static_constexpr_member<T>::is_noexcept))
  472. {
  473. return query_static_constexpr_member<T>::value();
  474. }
  475. template <typename E,
  476. typename T = decltype(continuation_t::static_query<E>())>
  477. static BOOST_ASIO_CONSTEXPR const T static_query_v
  478. = continuation_t::static_query<E>();
  479. #endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
  480. // && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
  481. static BOOST_ASIO_CONSTEXPR relationship_t<I> value()
  482. {
  483. return continuation_t();
  484. }
  485. friend BOOST_ASIO_CONSTEXPR bool operator==(
  486. const continuation_t&, const continuation_t&)
  487. {
  488. return true;
  489. }
  490. friend BOOST_ASIO_CONSTEXPR bool operator!=(
  491. const continuation_t&, const continuation_t&)
  492. {
  493. return false;
  494. }
  495. };
  496. #if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
  497. && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
  498. template <int I> template <typename E, typename T>
  499. const T continuation_t<I>::static_query_v;
  500. #endif // defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
  501. // && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
  502. } // namespace relationship
  503. } // namespace detail
  504. typedef detail::relationship_t<> relationship_t;
  505. #if defined(BOOST_ASIO_HAS_CONSTEXPR) || defined(GENERATING_DOCUMENTATION)
  506. constexpr relationship_t relationship;
  507. #else // defined(BOOST_ASIO_HAS_CONSTEXPR) || defined(GENERATING_DOCUMENTATION)
  508. namespace { static const relationship_t&
  509. relationship = relationship_t::instance; }
  510. #endif
  511. } // namespace execution
  512. #if !defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
  513. template <typename T>
  514. struct is_applicable_property<T, execution::relationship_t>
  515. : integral_constant<bool,
  516. execution::is_executor<T>::value
  517. || conditional<
  518. execution::is_executor<T>::value,
  519. false_type,
  520. execution::is_sender<T>
  521. >::type::value
  522. || conditional<
  523. execution::is_executor<T>::value,
  524. false_type,
  525. execution::is_scheduler<T>
  526. >::type::value>
  527. {
  528. };
  529. template <typename T>
  530. struct is_applicable_property<T, execution::relationship_t::fork_t>
  531. : integral_constant<bool,
  532. execution::is_executor<T>::value
  533. || conditional<
  534. execution::is_executor<T>::value,
  535. false_type,
  536. execution::is_sender<T>
  537. >::type::value
  538. || conditional<
  539. execution::is_executor<T>::value,
  540. false_type,
  541. execution::is_scheduler<T>
  542. >::type::value>
  543. {
  544. };
  545. template <typename T>
  546. struct is_applicable_property<T, execution::relationship_t::continuation_t>
  547. : integral_constant<bool,
  548. execution::is_executor<T>::value
  549. || conditional<
  550. execution::is_executor<T>::value,
  551. false_type,
  552. execution::is_sender<T>
  553. >::type::value
  554. || conditional<
  555. execution::is_executor<T>::value,
  556. false_type,
  557. execution::is_scheduler<T>
  558. >::type::value>
  559. {
  560. };
  561. #endif // !defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
  562. namespace traits {
  563. #if !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_FREE_TRAIT)
  564. template <typename T>
  565. struct query_free_default<T, execution::relationship_t,
  566. typename enable_if<
  567. can_query<T, execution::relationship_t::fork_t>::value
  568. >::type>
  569. {
  570. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
  571. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept =
  572. (is_nothrow_query<T, execution::relationship_t::fork_t>::value));
  573. typedef execution::relationship_t result_type;
  574. };
  575. template <typename T>
  576. struct query_free_default<T, execution::relationship_t,
  577. typename enable_if<
  578. !can_query<T, execution::relationship_t::fork_t>::value
  579. && can_query<T, execution::relationship_t::continuation_t>::value
  580. >::type>
  581. {
  582. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
  583. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept =
  584. (is_nothrow_query<T, execution::relationship_t::continuation_t>::value));
  585. typedef execution::relationship_t result_type;
  586. };
  587. #endif // !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_FREE_TRAIT)
  588. #if !defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
  589. || !defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
  590. template <typename T>
  591. struct static_query<T, execution::relationship_t,
  592. typename enable_if<
  593. execution::detail::relationship_t<0>::
  594. query_static_constexpr_member<T>::is_valid
  595. >::type>
  596. {
  597. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
  598. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
  599. typedef typename execution::detail::relationship_t<0>::
  600. query_static_constexpr_member<T>::result_type result_type;
  601. static BOOST_ASIO_CONSTEXPR result_type value()
  602. {
  603. return execution::detail::relationship_t<0>::
  604. query_static_constexpr_member<T>::value();
  605. }
  606. };
  607. template <typename T>
  608. struct static_query<T, execution::relationship_t,
  609. typename enable_if<
  610. !execution::detail::relationship_t<0>::
  611. query_static_constexpr_member<T>::is_valid
  612. && !execution::detail::relationship_t<0>::
  613. query_member<T>::is_valid
  614. && traits::static_query<T,
  615. execution::relationship_t::fork_t>::is_valid
  616. >::type>
  617. {
  618. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
  619. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
  620. typedef typename traits::static_query<T,
  621. execution::relationship_t::fork_t>::result_type result_type;
  622. static BOOST_ASIO_CONSTEXPR result_type value()
  623. {
  624. return traits::static_query<T,
  625. execution::relationship_t::fork_t>::value();
  626. }
  627. };
  628. template <typename T>
  629. struct static_query<T, execution::relationship_t,
  630. typename enable_if<
  631. !execution::detail::relationship_t<0>::
  632. query_static_constexpr_member<T>::is_valid
  633. && !execution::detail::relationship_t<0>::
  634. query_member<T>::is_valid
  635. && !traits::static_query<T,
  636. execution::relationship_t::fork_t>::is_valid
  637. && traits::static_query<T,
  638. execution::relationship_t::continuation_t>::is_valid
  639. >::type>
  640. {
  641. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
  642. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
  643. typedef typename traits::static_query<T,
  644. execution::relationship_t::continuation_t>::result_type result_type;
  645. static BOOST_ASIO_CONSTEXPR result_type value()
  646. {
  647. return traits::static_query<T,
  648. execution::relationship_t::continuation_t>::value();
  649. }
  650. };
  651. template <typename T>
  652. struct static_query<T, execution::relationship_t::fork_t,
  653. typename enable_if<
  654. execution::detail::relationship::fork_t<0>::
  655. query_static_constexpr_member<T>::is_valid
  656. >::type>
  657. {
  658. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
  659. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
  660. typedef typename execution::detail::relationship::fork_t<0>::
  661. query_static_constexpr_member<T>::result_type result_type;
  662. static BOOST_ASIO_CONSTEXPR result_type value()
  663. {
  664. return execution::detail::relationship::fork_t<0>::
  665. query_static_constexpr_member<T>::value();
  666. }
  667. };
  668. template <typename T>
  669. struct static_query<T, execution::relationship_t::fork_t,
  670. typename enable_if<
  671. !execution::detail::relationship::fork_t<0>::
  672. query_static_constexpr_member<T>::is_valid
  673. && !execution::detail::relationship::fork_t<0>::
  674. query_member<T>::is_valid
  675. && !traits::query_free<T,
  676. execution::relationship_t::fork_t>::is_valid
  677. && !can_query<T, execution::relationship_t::continuation_t>::value
  678. >::type>
  679. {
  680. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
  681. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
  682. typedef execution::relationship_t::fork_t result_type;
  683. static BOOST_ASIO_CONSTEXPR result_type value()
  684. {
  685. return result_type();
  686. }
  687. };
  688. template <typename T>
  689. struct static_query<T, execution::relationship_t::continuation_t,
  690. typename enable_if<
  691. execution::detail::relationship::continuation_t<0>::
  692. query_static_constexpr_member<T>::is_valid
  693. >::type>
  694. {
  695. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
  696. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
  697. typedef typename execution::detail::relationship::continuation_t<0>::
  698. query_static_constexpr_member<T>::result_type result_type;
  699. static BOOST_ASIO_CONSTEXPR result_type value()
  700. {
  701. return execution::detail::relationship::continuation_t<0>::
  702. query_static_constexpr_member<T>::value();
  703. }
  704. };
  705. #endif // !defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT)
  706. // || !defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
  707. #if !defined(BOOST_ASIO_HAS_DEDUCED_STATIC_REQUIRE_TRAIT)
  708. template <typename T>
  709. struct static_require<T, execution::relationship_t::fork_t,
  710. typename enable_if<
  711. static_query<T, execution::relationship_t::fork_t>::is_valid
  712. >::type>
  713. {
  714. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid =
  715. (is_same<typename static_query<T,
  716. execution::relationship_t::fork_t>::result_type,
  717. execution::relationship_t::fork_t>::value));
  718. };
  719. template <typename T>
  720. struct static_require<T, execution::relationship_t::continuation_t,
  721. typename enable_if<
  722. static_query<T, execution::relationship_t::continuation_t>::is_valid
  723. >::type>
  724. {
  725. BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid =
  726. (is_same<typename static_query<T,
  727. execution::relationship_t::continuation_t>::result_type,
  728. execution::relationship_t::continuation_t>::value));
  729. };
  730. #endif // !defined(BOOST_ASIO_HAS_DEDUCED_STATIC_REQUIRE_TRAIT)
  731. } // namespace traits
  732. #endif // defined(GENERATING_DOCUMENTATION)
  733. } // namespace asio
  734. } // namespace boost
  735. #include <boost/asio/detail/pop_options.hpp>
  736. #endif // BOOST_ASIO_EXECUTION_RELATIONSHIP_HPP