inline_exception_handling.hpp 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065
  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