inline_exception_handling.hpp 32 KB

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