basic_outcome.hpp 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167
  1. /* A less simple result type
  2. (C) 2017-2024 Niall Douglas <http://www.nedproductions.biz/> (20 commits)
  3. File Created: June 2017
  4. Boost Software License - Version 1.0 - August 17th, 2003
  5. Permission is hereby granted, free of charge, to any person or organization
  6. obtaining a copy of the software and accompanying documentation covered by
  7. this license (the "Software") to use, reproduce, display, distribute,
  8. execute, and transmit the Software, and to prepare derivative works of the
  9. Software, and to permit third-parties to whom the Software is furnished to
  10. do so, all subject to the following:
  11. The copyright notices in the Software and this entire statement, including
  12. the above license grant, this restriction and the following disclaimer,
  13. must be included in all copies of the Software, in whole or in part, and
  14. all derivative works of the Software, unless such copies or derivative
  15. works are solely in the form of machine-executable object code generated by
  16. a source language processor.
  17. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
  20. SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
  21. FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
  22. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  23. DEALINGS IN THE SOFTWARE.
  24. */
  25. #ifndef BOOST_OUTCOME_BASIC_OUTCOME_HPP
  26. #define BOOST_OUTCOME_BASIC_OUTCOME_HPP
  27. #include "config.hpp"
  28. #include "basic_result.hpp"
  29. #include "detail/basic_outcome_exception_observers.hpp"
  30. #include "detail/basic_outcome_failure_observers.hpp"
  31. #ifdef __clang__
  32. #pragma clang diagnostic push
  33. #pragma clang diagnostic ignored "-Wdocumentation" // Standardese markup confuses clang
  34. #endif
  35. BOOST_OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
  36. template <class R, class S, class P, class NoValuePolicy> //
  37. class basic_outcome;
  38. namespace detail
  39. {
  40. // May be reused by basic_outcome subclasses to save load on the compiler
  41. template <class value_type, class error_type, class exception_type> struct outcome_predicates
  42. {
  43. using result = result_predicates<value_type, error_type>;
  44. // Predicate for the implicit constructors to be available
  45. static constexpr bool implicit_constructors_enabled = //
  46. result::implicit_constructors_enabled //
  47. && !detail::is_implicitly_constructible<value_type, exception_type> //
  48. && !detail::is_implicitly_constructible<error_type, exception_type> //
  49. && !detail::is_implicitly_constructible<exception_type, value_type> //
  50. && !detail::is_implicitly_constructible<exception_type, error_type>;
  51. // Predicate for the value converting constructor to be available.
  52. template <class T>
  53. static constexpr bool enable_value_converting_constructor = //
  54. implicit_constructors_enabled //
  55. &&result::template enable_value_converting_constructor<T> //
  56. && !detail::is_implicitly_constructible<exception_type, T>; // deliberately less tolerant of ambiguity than result's edition
  57. // Predicate for the error converting constructor to be available.
  58. template <class T>
  59. static constexpr bool enable_error_converting_constructor = //
  60. implicit_constructors_enabled //
  61. &&result::template enable_error_converting_constructor<T> //
  62. && !detail::is_implicitly_constructible<exception_type, T>; // deliberately less tolerant of ambiguity than result's edition
  63. // Predicate for the error condition converting constructor to be available.
  64. template <class ErrorCondEnum>
  65. static constexpr bool enable_error_condition_converting_constructor = result::template enable_error_condition_converting_constructor<ErrorCondEnum> //
  66. && !detail::is_implicitly_constructible<exception_type, ErrorCondEnum>;
  67. // Predicate for the exception converting constructor to be available.
  68. template <class T>
  69. static constexpr bool enable_exception_converting_constructor = //
  70. implicit_constructors_enabled //
  71. && !is_in_place_type_t<std::decay_t<T>>::value // not in place construction
  72. && !detail::is_implicitly_constructible<value_type, T> && !detail::is_implicitly_constructible<error_type, T> &&
  73. detail::is_implicitly_constructible<exception_type, T>;
  74. // Predicate for the error + exception converting constructor to be available.
  75. template <class T, class U>
  76. static constexpr bool enable_error_exception_converting_constructor = //
  77. implicit_constructors_enabled //
  78. && !is_in_place_type_t<std::decay_t<T>>::value // not in place construction
  79. && !detail::is_implicitly_constructible<value_type, T> && detail::is_implicitly_constructible<error_type, T> //
  80. && !detail::is_implicitly_constructible<value_type, U> && detail::is_implicitly_constructible<exception_type, U>;
  81. // Predicate for the converting copy constructor from a compatible outcome to be available.
  82. template <class T, class U, class V, class W>
  83. static constexpr bool enable_compatible_conversion = //
  84. (std::is_void<T>::value ||
  85. detail::is_explicitly_constructible<value_type, typename basic_outcome<T, U, V, W>::value_type>) // if our value types are constructible
  86. &&(std::is_void<U>::value ||
  87. detail::is_explicitly_constructible<error_type, typename basic_outcome<T, U, V, W>::error_type>) // if our error types are constructible
  88. &&(std::is_void<V>::value ||
  89. detail::is_explicitly_constructible<exception_type, typename basic_outcome<T, U, V, W>::exception_type>) // if our exception types are constructible
  90. ;
  91. // Predicate for the converting constructor from a make_error_code() of the input to be available.
  92. template <class T, class U, class V, class W>
  93. static constexpr bool enable_make_error_code_compatible_conversion = //
  94. trait::is_error_code_available<std::decay_t<error_type>>::value // if error type has an error code
  95. && !enable_compatible_conversion<T, U, V, W> // and the normal compatible conversion is not available
  96. && (std::is_void<T>::value ||
  97. detail::is_explicitly_constructible<value_type, typename basic_outcome<T, U, V, W>::value_type>) // and if our value types are constructible
  98. &&detail::is_explicitly_constructible<error_type,
  99. typename trait::is_error_code_available<U>::type> // and our error type is constructible from a make_error_code()
  100. && (std::is_void<V>::value ||
  101. detail::is_explicitly_constructible<exception_type, typename basic_outcome<T, U, V, W>::exception_type>); // and our exception types are constructible
  102. // Predicate for the implicit converting inplace constructor from a compatible input to be available.
  103. struct disable_inplace_value_error_exception_constructor;
  104. template <class... Args>
  105. using choose_inplace_value_error_exception_constructor = std::conditional_t< //
  106. ((static_cast<int>(detail::is_constructible<value_type, Args...>) + static_cast<int>(detail::is_constructible<error_type, Args...>) +
  107. static_cast<int>(detail::is_constructible<exception_type, Args...>)) > 1), //
  108. disable_inplace_value_error_exception_constructor, //
  109. std::conditional_t< //
  110. detail::is_constructible<value_type, Args...>, //
  111. value_type, //
  112. std::conditional_t< //
  113. detail::is_constructible<error_type, Args...>, //
  114. error_type, //
  115. std::conditional_t< //
  116. detail::is_constructible<exception_type, Args...>, //
  117. exception_type, //
  118. disable_inplace_value_error_exception_constructor>>>>;
  119. template <class... Args>
  120. static constexpr bool enable_inplace_value_error_exception_constructor = //
  121. implicit_constructors_enabled &&
  122. !std::is_same<choose_inplace_value_error_exception_constructor<Args...>, disable_inplace_value_error_exception_constructor>::value;
  123. };
  124. // Select whether to use basic_outcome_failure_observers or not
  125. template <class Base, class R, class S, class P, class NoValuePolicy>
  126. using select_basic_outcome_failure_observers = //
  127. std::conditional_t<trait::is_error_code_available<S>::value && trait::is_exception_ptr_available<P>::value,
  128. basic_outcome_failure_observers<Base, R, S, P, NoValuePolicy>, Base>;
  129. template <class T, class U, class V> constexpr inline const V &extract_exception_from_failure(const failure_type<U, V> &v) { return v.exception(); }
  130. template <class T, class U, class V> constexpr inline V &&extract_exception_from_failure(failure_type<U, V> &&v)
  131. {
  132. return static_cast<failure_type<U, V> &&>(v).exception();
  133. }
  134. template <class T, class U> constexpr inline const U &extract_exception_from_failure(const failure_type<U, void> &v) { return v.error(); }
  135. template <class T, class U> constexpr inline U &&extract_exception_from_failure(failure_type<U, void> &&v)
  136. {
  137. return static_cast<failure_type<U, void> &&>(v).error();
  138. }
  139. template <class T> struct is_basic_outcome
  140. {
  141. static constexpr bool value = false;
  142. };
  143. template <class R, class S, class T, class N> struct is_basic_outcome<basic_outcome<R, S, T, N>>
  144. {
  145. static constexpr bool value = true;
  146. };
  147. } // namespace detail
  148. /*! AWAITING HUGO JSON CONVERSION TOOL
  149. type alias template <class T> is_basic_outcome. Potential doc page: `is_basic_outcome<T>`
  150. */
  151. template <class T> using is_basic_outcome = detail::is_basic_outcome<std::decay_t<T>>;
  152. /*! AWAITING HUGO JSON CONVERSION TOOL
  153. SIGNATURE NOT RECOGNISED
  154. */
  155. template <class T> static constexpr bool is_basic_outcome_v = detail::is_basic_outcome<std::decay_t<T>>::value;
  156. namespace concepts
  157. {
  158. #if defined(__cpp_concepts)
  159. /* The `basic_outcome` concept.
  160. \requires That `U` matches a `basic_outcome`.
  161. */
  162. template <class U>
  163. concept BOOST_OUTCOME_GCC6_CONCEPT_BOOL basic_outcome =
  164. BOOST_OUTCOME_V2_NAMESPACE::is_basic_outcome<U>::value ||
  165. (requires(U v) {
  166. BOOST_OUTCOME_V2_NAMESPACE::basic_outcome<typename U::value_type, typename U::error_type, typename U::exception_type, typename U::no_value_policy_type>(v);
  167. } && //
  168. detail::convertible<
  169. U, BOOST_OUTCOME_V2_NAMESPACE::basic_outcome<typename U::value_type, typename U::error_type, typename U::exception_type, typename U::no_value_policy_type>> && //
  170. detail::base_of<
  171. BOOST_OUTCOME_V2_NAMESPACE::basic_outcome<typename U::value_type, typename U::error_type, typename U::exception_type, typename U::no_value_policy_type>, U>);
  172. #else
  173. namespace detail
  174. {
  175. inline no_match match_basic_outcome(...);
  176. template <class R, class S, class P, class NVP, class T, //
  177. typename = typename T::value_type, //
  178. typename = typename T::error_type, //
  179. typename = typename T::exception_type, //
  180. typename = typename T::no_value_policy_type, //
  181. typename std::enable_if_t<std::is_convertible<T, BOOST_OUTCOME_V2_NAMESPACE::basic_outcome<R, S, P, NVP>>::value && //
  182. std::is_base_of<BOOST_OUTCOME_V2_NAMESPACE::basic_outcome<R, S, P, NVP>, T>::value,
  183. bool> = true>
  184. inline BOOST_OUTCOME_V2_NAMESPACE::basic_outcome<R, S, P, NVP> match_basic_outcome(BOOST_OUTCOME_V2_NAMESPACE::basic_outcome<R, S, P, NVP> &&, T &&);
  185. template <class U>
  186. static constexpr bool basic_outcome =
  187. BOOST_OUTCOME_V2_NAMESPACE::is_basic_outcome<U>::value ||
  188. !std::is_same<no_match, decltype(match_basic_outcome(std::declval<BOOST_OUTCOME_V2_NAMESPACE::detail::devoid<U>>(),
  189. std::declval<BOOST_OUTCOME_V2_NAMESPACE::detail::devoid<U>>()))>::value;
  190. } // namespace detail
  191. /* The `basic_outcome` concept.
  192. \requires That `U` matches a `basic_outcome`.
  193. */
  194. template <class U> static constexpr bool basic_outcome = detail::basic_outcome<U>;
  195. #endif
  196. } // namespace concepts
  197. namespace hooks
  198. {
  199. /*! AWAITING HUGO JSON CONVERSION TOOL
  200. SIGNATURE NOT RECOGNISED
  201. */
  202. template <class R, class S, class P, class NoValuePolicy, class U>
  203. constexpr inline void override_outcome_exception(basic_outcome<R, S, P, NoValuePolicy> *o, U &&v) noexcept;
  204. } // namespace hooks
  205. /*! AWAITING HUGO JSON CONVERSION TOOL
  206. type definition template <class R, class S, class P, class NoValuePolicy> basic_outcome. Potential doc page: `basic_outcome<T, EC, EP, NoValuePolicy>`
  207. */
  208. template <class R, class S, class P, class NoValuePolicy> //
  209. class BOOST_OUTCOME_NODISCARD basic_outcome
  210. #if defined(BOOST_OUTCOME_DOXYGEN_IS_IN_THE_HOUSE) || defined(BOOST_OUTCOME_STANDARDESE_IS_IN_THE_HOUSE)
  211. : public detail::basic_outcome_failure_observers<detail::basic_result_final<R, S, P, NoValuePolicy>, R, S, P, NoValuePolicy>,
  212. public detail::basic_outcome_exception_observers<detail::basic_result_final<R, S, NoValuePolicy>, R, S, P, NoValuePolicy>,
  213. public detail::basic_result_final<R, S, NoValuePolicy>
  214. #else
  215. : public detail::select_basic_outcome_failure_observers<
  216. detail::basic_outcome_exception_observers<detail::basic_result_final<R, S, NoValuePolicy>, R, S, P, NoValuePolicy>, R, S, P, NoValuePolicy>
  217. #endif
  218. {
  219. static_assert(trait::type_can_be_used_in_basic_result<P>, "The exception_type cannot be used");
  220. static_assert(std::is_void<P>::value || std::is_default_constructible<P>::value, "exception_type must be void or default constructible");
  221. using base = detail::select_basic_outcome_failure_observers<
  222. detail::basic_outcome_exception_observers<detail::basic_result_final<R, S, NoValuePolicy>, R, S, P, NoValuePolicy>, R, S, P, NoValuePolicy>;
  223. friend struct policy::base;
  224. template <class T, class U, class V, class W> //
  225. friend class basic_outcome;
  226. template <class T, class U, class V, class W, class X>
  227. friend constexpr inline void hooks::override_outcome_exception(basic_outcome<T, U, V, W> *o, X &&v) noexcept; // NOLINT
  228. struct implicit_constructors_disabled_tag
  229. {
  230. };
  231. struct value_converting_constructor_tag
  232. {
  233. };
  234. struct error_converting_constructor_tag
  235. {
  236. };
  237. struct error_condition_converting_constructor_tag
  238. {
  239. };
  240. struct exception_converting_constructor_tag
  241. {
  242. };
  243. struct error_exception_converting_constructor_tag
  244. {
  245. };
  246. struct explicit_valueorerror_converting_constructor_tag
  247. {
  248. };
  249. struct explicit_compatible_copy_conversion_tag
  250. {
  251. };
  252. struct explicit_compatible_move_conversion_tag
  253. {
  254. };
  255. struct explicit_make_error_code_compatible_copy_conversion_tag
  256. {
  257. };
  258. struct explicit_make_error_code_compatible_move_conversion_tag
  259. {
  260. };
  261. struct error_failure_tag
  262. {
  263. };
  264. struct exception_failure_tag
  265. {
  266. };
  267. struct disable_in_place_value_type
  268. {
  269. };
  270. struct disable_in_place_error_type
  271. {
  272. };
  273. struct disable_in_place_exception_type
  274. {
  275. };
  276. public:
  277. using value_type = R;
  278. using error_type = S;
  279. using exception_type = P;
  280. using no_value_policy_type = NoValuePolicy;
  281. template <class T, class U = S, class V = P, class W = NoValuePolicy> using rebind = basic_outcome<T, U, V, W>;
  282. protected:
  283. // Requirement predicates for outcome.
  284. struct predicate
  285. {
  286. using base = detail::outcome_predicates<value_type, error_type, exception_type>;
  287. // Predicate for any constructors to be available at all
  288. static constexpr bool constructors_enabled =
  289. (!std::is_same<std::decay_t<value_type>, std::decay_t<error_type>>::value || (std::is_void<value_type>::value && std::is_void<error_type>::value)) //
  290. && (!std::is_same<std::decay_t<value_type>, std::decay_t<exception_type>>::value ||
  291. (std::is_void<value_type>::value && std::is_void<exception_type>::value)) //
  292. && (!std::is_same<std::decay_t<error_type>, std::decay_t<exception_type>>::value ||
  293. (std::is_void<error_type>::value && std::is_void<exception_type>::value)) //
  294. ;
  295. // Predicate for implicit constructors to be available at all
  296. static constexpr bool implicit_constructors_enabled = constructors_enabled && base::implicit_constructors_enabled;
  297. // Predicate for the value converting constructor to be available.
  298. template <class T>
  299. static constexpr bool enable_value_converting_constructor = //
  300. constructors_enabled //
  301. && !std::is_same<std::decay_t<T>, basic_outcome>::value // not my type
  302. && base::template enable_value_converting_constructor<T>;
  303. // Predicate for the error converting constructor to be available.
  304. template <class T>
  305. static constexpr bool enable_error_converting_constructor = //
  306. constructors_enabled //
  307. && !std::is_same<std::decay_t<T>, basic_outcome>::value // not my type
  308. && base::template enable_error_converting_constructor<T>;
  309. // Predicate for the error condition converting constructor to be available.
  310. template <class ErrorCondEnum>
  311. static constexpr bool enable_error_condition_converting_constructor = //
  312. constructors_enabled //
  313. && !std::is_same<std::decay_t<ErrorCondEnum>, basic_outcome>::value // not my type
  314. && base::template enable_error_condition_converting_constructor<ErrorCondEnum>;
  315. // Predicate for the exception converting constructor to be available.
  316. template <class T>
  317. static constexpr bool enable_exception_converting_constructor = //
  318. constructors_enabled //
  319. && !std::is_same<std::decay_t<T>, basic_outcome>::value // not my type
  320. && base::template enable_exception_converting_constructor<T>;
  321. // Predicate for the error + exception converting constructor to be available.
  322. template <class T, class U>
  323. static constexpr bool enable_error_exception_converting_constructor = //
  324. constructors_enabled //
  325. && !std::is_same<std::decay_t<T>, basic_outcome>::value // not my type
  326. && base::template enable_error_exception_converting_constructor<T, U>;
  327. // Predicate for the converting constructor from a compatible input to be available.
  328. template <class T, class U, class V, class W>
  329. static constexpr bool enable_compatible_conversion = //
  330. constructors_enabled //
  331. && !std::is_same<basic_outcome<T, U, V, W>, basic_outcome>::value // not my type
  332. && base::template enable_compatible_conversion<T, U, V, W>;
  333. // Predicate for the converting constructor from a make_error_code() of the input to be available.
  334. template <class T, class U, class V, class W>
  335. static constexpr bool enable_make_error_code_compatible_conversion = //
  336. constructors_enabled //
  337. && !std::is_same<basic_outcome<T, U, V, W>, basic_outcome>::value // not my type
  338. && base::template enable_make_error_code_compatible_conversion<T, U, V, W>;
  339. // Predicate for the inplace construction of value to be available.
  340. template <class... Args>
  341. static constexpr bool enable_inplace_value_constructor = //
  342. constructors_enabled //
  343. && (std::is_void<value_type>::value //
  344. || detail::is_constructible<value_type, Args...>);
  345. // Predicate for the inplace construction of error to be available.
  346. template <class... Args>
  347. static constexpr bool enable_inplace_error_constructor = //
  348. constructors_enabled //
  349. && (std::is_void<error_type>::value //
  350. || detail::is_constructible<error_type, Args...>);
  351. // Predicate for the inplace construction of exception to be available.
  352. template <class... Args>
  353. static constexpr bool enable_inplace_exception_constructor = //
  354. constructors_enabled //
  355. && (std::is_void<exception_type>::value //
  356. || detail::is_constructible<exception_type, Args...>);
  357. // Predicate for the implicit converting inplace constructor to be available.
  358. template <class... Args>
  359. static constexpr bool enable_inplace_value_error_exception_constructor = //
  360. constructors_enabled //
  361. &&base::template enable_inplace_value_error_exception_constructor<Args...>;
  362. template <class... Args>
  363. using choose_inplace_value_error_exception_constructor = typename base::template choose_inplace_value_error_exception_constructor<Args...>;
  364. };
  365. public:
  366. using value_type_if_enabled =
  367. std::conditional_t<std::is_same<value_type, error_type>::value || std::is_same<value_type, exception_type>::value, disable_in_place_value_type, value_type>;
  368. using error_type_if_enabled =
  369. std::conditional_t<std::is_same<error_type, value_type>::value || std::is_same<error_type, exception_type>::value, disable_in_place_error_type, error_type>;
  370. using exception_type_if_enabled = std::conditional_t<std::is_same<exception_type, value_type>::value || std::is_same<exception_type, error_type>::value,
  371. disable_in_place_exception_type, exception_type>;
  372. protected:
  373. detail::devoid<exception_type> _ptr;
  374. public:
  375. /*! AWAITING HUGO JSON CONVERSION TOOL
  376. SIGNATURE NOT RECOGNISED
  377. */
  378. BOOST_OUTCOME_TEMPLATE(class Arg, class... Args)
  379. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED((!predicate::constructors_enabled && sizeof...(Args) >= 0)))
  380. basic_outcome(Arg && /*unused*/, Args &&... /*unused*/) = delete; // NOLINT basic_outcome<> with any of the same type is NOT SUPPORTED, see docs!
  381. /*! AWAITING HUGO JSON CONVERSION TOOL
  382. SIGNATURE NOT RECOGNISED
  383. */
  384. BOOST_OUTCOME_TEMPLATE(class T)
  385. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED((predicate::constructors_enabled && !predicate::implicit_constructors_enabled //
  386. && (detail::is_implicitly_constructible<value_type, T> || detail::is_implicitly_constructible<error_type, T> ||
  387. detail::is_implicitly_constructible<exception_type, T>) )))
  388. basic_outcome(T && /*unused*/, implicit_constructors_disabled_tag /*unused*/ = implicit_constructors_disabled_tag()) =
  389. delete; // NOLINT Implicit constructors disabled, use explicit in_place_type<T>, success() or failure(). see docs!
  390. /*! AWAITING HUGO JSON CONVERSION TOOL
  391. SIGNATURE NOT RECOGNISED
  392. */
  393. BOOST_OUTCOME_TEMPLATE(class T)
  394. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_value_converting_constructor<T>))
  395. constexpr basic_outcome(T &&t, value_converting_constructor_tag /*unused*/ = value_converting_constructor_tag()) noexcept(
  396. detail::is_nothrow_constructible<value_type, T>) // NOLINT
  397. : base{in_place_type<typename base::_value_type>, static_cast<T &&>(t)}
  398. , _ptr()
  399. {
  400. no_value_policy_type::on_outcome_construction(this, static_cast<T &&>(t));
  401. }
  402. /*! AWAITING HUGO JSON CONVERSION TOOL
  403. SIGNATURE NOT RECOGNISED
  404. */
  405. BOOST_OUTCOME_TEMPLATE(class T)
  406. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_error_converting_constructor<T>))
  407. constexpr basic_outcome(T &&t, error_converting_constructor_tag /*unused*/ = error_converting_constructor_tag()) noexcept(
  408. detail::is_nothrow_constructible<error_type, T>) // NOLINT
  409. : base{in_place_type<typename base::_error_type>, static_cast<T &&>(t)}
  410. , _ptr()
  411. {
  412. no_value_policy_type::on_outcome_construction(this, static_cast<T &&>(t));
  413. }
  414. /*! AWAITING HUGO JSON CONVERSION TOOL
  415. SIGNATURE NOT RECOGNISED
  416. */
  417. BOOST_OUTCOME_TEMPLATE(class ErrorCondEnum)
  418. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TEXPR(error_type(make_error_code(ErrorCondEnum()))), //
  419. BOOST_OUTCOME_TPRED(predicate::template enable_error_condition_converting_constructor<ErrorCondEnum>))
  420. constexpr basic_outcome(ErrorCondEnum &&t, error_condition_converting_constructor_tag /*unused*/ = error_condition_converting_constructor_tag()) noexcept(
  421. noexcept(error_type(make_error_code(static_cast<ErrorCondEnum &&>(t))))) // NOLINT
  422. : base{in_place_type<typename base::_error_type>, make_error_code(t)}
  423. {
  424. no_value_policy_type::on_outcome_construction(this, static_cast<ErrorCondEnum &&>(t));
  425. }
  426. /*! AWAITING HUGO JSON CONVERSION TOOL
  427. SIGNATURE NOT RECOGNISED
  428. */
  429. BOOST_OUTCOME_TEMPLATE(class T)
  430. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_exception_converting_constructor<T>))
  431. constexpr basic_outcome(T &&t, exception_converting_constructor_tag /*unused*/ = exception_converting_constructor_tag()) noexcept(
  432. detail::is_nothrow_constructible<exception_type, T>) // NOLINT
  433. : base()
  434. , _ptr(static_cast<T &&>(t))
  435. {
  436. this->_state._status.set_have_exception(true);
  437. no_value_policy_type::on_outcome_construction(this, static_cast<T &&>(t));
  438. }
  439. /*! AWAITING HUGO JSON CONVERSION TOOL
  440. SIGNATURE NOT RECOGNISED
  441. */
  442. BOOST_OUTCOME_TEMPLATE(class T, class U)
  443. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_error_exception_converting_constructor<T, U>))
  444. constexpr basic_outcome(T &&a, U &&b, error_exception_converting_constructor_tag /*unused*/ = error_exception_converting_constructor_tag()) noexcept(
  445. detail::is_nothrow_constructible<error_type, T> &&detail::is_nothrow_constructible<exception_type, U>) // NOLINT
  446. : base{in_place_type<typename base::_error_type>, static_cast<T &&>(a)}
  447. , _ptr(static_cast<U &&>(b))
  448. {
  449. this->_state._status.set_have_exception(true);
  450. no_value_policy_type::on_outcome_construction(this, static_cast<T &&>(a), static_cast<U &&>(b));
  451. }
  452. /*! AWAITING HUGO JSON CONVERSION TOOL
  453. SIGNATURE NOT RECOGNISED
  454. */
  455. BOOST_OUTCOME_TEMPLATE(class T)
  456. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(convert::value_or_error<basic_outcome, std::decay_t<T>>::enable_result_inputs || !concepts::basic_result<T>), //
  457. BOOST_OUTCOME_TPRED(convert::value_or_error<basic_outcome, std::decay_t<T>>::enable_outcome_inputs || !concepts::basic_outcome<T>), //
  458. BOOST_OUTCOME_TEXPR(convert::value_or_error<basic_outcome, std::decay_t<T>>{}(std::declval<T>())))
  459. constexpr explicit basic_outcome(T &&o,
  460. explicit_valueorerror_converting_constructor_tag /*unused*/ = explicit_valueorerror_converting_constructor_tag()) // NOLINT
  461. : basic_outcome{convert::value_or_error<basic_outcome, std::decay_t<T>>{}(static_cast<T &&>(o))}
  462. {
  463. }
  464. /*! AWAITING HUGO JSON CONVERSION TOOL
  465. SIGNATURE NOT RECOGNISED
  466. */
  467. BOOST_OUTCOME_TEMPLATE(class T, class U, class V, class W)
  468. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_compatible_conversion<T, U, V, W>))
  469. constexpr explicit basic_outcome(
  470. const basic_outcome<T, U, V, W> &o,
  471. explicit_compatible_copy_conversion_tag /*unused*/ =
  472. explicit_compatible_copy_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&detail::is_nothrow_constructible<error_type, U>
  473. &&detail::is_nothrow_constructible<exception_type, V>)
  474. : base{typename base::compatible_conversion_tag(), o}
  475. , _ptr(o._ptr)
  476. {
  477. no_value_policy_type::on_outcome_copy_construction(this, o);
  478. }
  479. /*! AWAITING HUGO JSON CONVERSION TOOL
  480. SIGNATURE NOT RECOGNISED
  481. */
  482. BOOST_OUTCOME_TEMPLATE(class T, class U, class V, class W)
  483. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_compatible_conversion<T, U, V, W>))
  484. constexpr explicit basic_outcome(
  485. basic_outcome<T, U, V, W> &&o,
  486. explicit_compatible_move_conversion_tag /*unused*/ =
  487. explicit_compatible_move_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&detail::is_nothrow_constructible<error_type, U>
  488. &&detail::is_nothrow_constructible<exception_type, V>)
  489. : base{typename base::compatible_conversion_tag(), static_cast<basic_outcome<T, U, V, W> &&>(o)}
  490. , _ptr(static_cast<typename basic_outcome<T, U, V, W>::exception_type &&>(o._ptr))
  491. {
  492. no_value_policy_type::on_outcome_move_construction(this, static_cast<basic_outcome<T, U, V, W> &&>(o));
  493. }
  494. /*! AWAITING HUGO JSON CONVERSION TOOL
  495. SIGNATURE NOT RECOGNISED
  496. */
  497. BOOST_OUTCOME_TEMPLATE(class T, class U, class V)
  498. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(detail::result_predicates<value_type, error_type>::template enable_compatible_conversion<T, U, V>))
  499. constexpr explicit basic_outcome(
  500. const basic_result<T, U, V> &o,
  501. explicit_compatible_copy_conversion_tag /*unused*/ =
  502. explicit_compatible_copy_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&detail::is_nothrow_constructible<error_type, U>
  503. &&detail::is_nothrow_constructible<exception_type>)
  504. : base{typename base::compatible_conversion_tag(), o}
  505. , _ptr()
  506. {
  507. no_value_policy_type::on_outcome_copy_construction(this, o);
  508. }
  509. /*! AWAITING HUGO JSON CONVERSION TOOL
  510. SIGNATURE NOT RECOGNISED
  511. */
  512. BOOST_OUTCOME_TEMPLATE(class T, class U, class V)
  513. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(detail::result_predicates<value_type, error_type>::template enable_compatible_conversion<T, U, V>))
  514. constexpr explicit basic_outcome(
  515. basic_result<T, U, V> &&o,
  516. explicit_compatible_move_conversion_tag /*unused*/ =
  517. explicit_compatible_move_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&detail::is_nothrow_constructible<error_type, U>
  518. &&detail::is_nothrow_constructible<exception_type>)
  519. : base{typename base::compatible_conversion_tag(), static_cast<basic_result<T, U, V> &&>(o)}
  520. , _ptr()
  521. {
  522. no_value_policy_type::on_outcome_move_construction(this, static_cast<basic_result<T, U, V> &&>(o));
  523. }
  524. /*! AWAITING HUGO JSON CONVERSION TOOL
  525. SIGNATURE NOT RECOGNISED
  526. */
  527. BOOST_OUTCOME_TEMPLATE(class T, class U, class V)
  528. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(detail::result_predicates<value_type, error_type>::template enable_make_error_code_compatible_conversion<T, U, V>))
  529. constexpr explicit basic_outcome(const basic_result<T, U, V> &o,
  530. explicit_make_error_code_compatible_copy_conversion_tag /*unused*/ =
  531. explicit_make_error_code_compatible_copy_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T>
  532. &&noexcept(make_error_code(std::declval<U>())) &&
  533. detail::is_nothrow_constructible<exception_type>)
  534. : base{typename base::make_error_code_compatible_conversion_tag(), o}
  535. , _ptr()
  536. {
  537. no_value_policy_type::on_outcome_copy_construction(this, o);
  538. }
  539. /*! AWAITING HUGO JSON CONVERSION TOOL
  540. SIGNATURE NOT RECOGNISED
  541. */
  542. BOOST_OUTCOME_TEMPLATE(class T, class U, class V)
  543. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(detail::result_predicates<value_type, error_type>::template enable_make_error_code_compatible_conversion<T, U, V>))
  544. constexpr explicit basic_outcome(basic_result<T, U, V> &&o,
  545. explicit_make_error_code_compatible_move_conversion_tag /*unused*/ =
  546. explicit_make_error_code_compatible_move_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T>
  547. &&noexcept(make_error_code(std::declval<U>())) &&
  548. detail::is_nothrow_constructible<exception_type>)
  549. : base{typename base::make_error_code_compatible_conversion_tag(), static_cast<basic_result<T, U, V> &&>(o)}
  550. , _ptr()
  551. {
  552. no_value_policy_type::on_outcome_move_construction(this, static_cast<basic_result<T, U, V> &&>(o));
  553. }
  554. /*! AWAITING HUGO JSON CONVERSION TOOL
  555. SIGNATURE NOT RECOGNISED
  556. */
  557. BOOST_OUTCOME_TEMPLATE(class... Args)
  558. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_inplace_value_constructor<Args...>))
  559. constexpr explicit basic_outcome(in_place_type_t<value_type_if_enabled> _, Args &&... args) noexcept(detail::is_nothrow_constructible<value_type, Args...>)
  560. : base{_, static_cast<Args &&>(args)...}
  561. , _ptr()
  562. {
  563. no_value_policy_type::on_outcome_in_place_construction(this, in_place_type<value_type>, static_cast<Args &&>(args)...);
  564. }
  565. /*! AWAITING HUGO JSON CONVERSION TOOL
  566. SIGNATURE NOT RECOGNISED
  567. */
  568. BOOST_OUTCOME_TEMPLATE(class U, class... Args)
  569. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_inplace_value_constructor<std::initializer_list<U>, Args...>))
  570. constexpr explicit basic_outcome(in_place_type_t<value_type_if_enabled> _, std::initializer_list<U> il,
  571. Args &&... args) noexcept(detail::is_nothrow_constructible<value_type, std::initializer_list<U>, Args...>)
  572. : base{_, il, static_cast<Args &&>(args)...}
  573. , _ptr()
  574. {
  575. no_value_policy_type::on_outcome_in_place_construction(this, in_place_type<value_type>, il, static_cast<Args &&>(args)...);
  576. }
  577. /*! AWAITING HUGO JSON CONVERSION TOOL
  578. SIGNATURE NOT RECOGNISED
  579. */
  580. BOOST_OUTCOME_TEMPLATE(class... Args)
  581. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_inplace_error_constructor<Args...>))
  582. constexpr explicit basic_outcome(in_place_type_t<error_type_if_enabled> _, Args &&... args) noexcept(detail::is_nothrow_constructible<error_type, Args...>)
  583. : base{_, static_cast<Args &&>(args)...}
  584. , _ptr()
  585. {
  586. no_value_policy_type::on_outcome_in_place_construction(this, in_place_type<error_type>, static_cast<Args &&>(args)...);
  587. }
  588. /*! AWAITING HUGO JSON CONVERSION TOOL
  589. SIGNATURE NOT RECOGNISED
  590. */
  591. BOOST_OUTCOME_TEMPLATE(class U, class... Args)
  592. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_inplace_error_constructor<std::initializer_list<U>, Args...>))
  593. constexpr explicit basic_outcome(in_place_type_t<error_type_if_enabled> _, std::initializer_list<U> il,
  594. Args &&... args) noexcept(detail::is_nothrow_constructible<error_type, std::initializer_list<U>, Args...>)
  595. : base{_, il, static_cast<Args &&>(args)...}
  596. , _ptr()
  597. {
  598. no_value_policy_type::on_outcome_in_place_construction(this, in_place_type<error_type>, il, static_cast<Args &&>(args)...);
  599. }
  600. /*! AWAITING HUGO JSON CONVERSION TOOL
  601. SIGNATURE NOT RECOGNISED
  602. */
  603. BOOST_OUTCOME_TEMPLATE(class... Args)
  604. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_inplace_exception_constructor<Args...>))
  605. constexpr explicit basic_outcome(in_place_type_t<exception_type_if_enabled> /*unused*/,
  606. Args &&... args) noexcept(detail::is_nothrow_constructible<exception_type, Args...>)
  607. : base()
  608. , _ptr(static_cast<Args &&>(args)...)
  609. {
  610. this->_state._status.set_have_exception(true);
  611. no_value_policy_type::on_outcome_in_place_construction(this, in_place_type<exception_type>, static_cast<Args &&>(args)...);
  612. }
  613. /*! AWAITING HUGO JSON CONVERSION TOOL
  614. SIGNATURE NOT RECOGNISED
  615. */
  616. BOOST_OUTCOME_TEMPLATE(class U, class... Args)
  617. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_inplace_exception_constructor<std::initializer_list<U>, Args...>))
  618. constexpr explicit basic_outcome(in_place_type_t<exception_type_if_enabled> /*unused*/, std::initializer_list<U> il,
  619. Args &&... args) noexcept(detail::is_nothrow_constructible<exception_type, std::initializer_list<U>, Args...>)
  620. : base()
  621. , _ptr(il, static_cast<Args &&>(args)...)
  622. {
  623. this->_state._status.set_have_exception(true);
  624. no_value_policy_type::on_outcome_in_place_construction(this, in_place_type<exception_type>, il, static_cast<Args &&>(args)...);
  625. }
  626. /*! AWAITING HUGO JSON CONVERSION TOOL
  627. SIGNATURE NOT RECOGNISED
  628. */
  629. BOOST_OUTCOME_TEMPLATE(class A1, class A2, class... Args)
  630. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_inplace_value_error_exception_constructor<A1, A2, Args...>))
  631. constexpr basic_outcome(A1 &&a1, A2 &&a2, Args &&... args) noexcept(
  632. noexcept(typename predicate::template choose_inplace_value_error_exception_constructor<A1, A2, Args...>(std::declval<A1>(), std::declval<A2>(),
  633. std::declval<Args>()...)))
  634. : basic_outcome(in_place_type<typename predicate::template choose_inplace_value_error_exception_constructor<A1, A2, Args...>>, static_cast<A1 &&>(a1),
  635. static_cast<A2 &&>(a2), static_cast<Args &&>(args)...)
  636. {
  637. }
  638. /*! AWAITING HUGO JSON CONVERSION TOOL
  639. SIGNATURE NOT RECOGNISED
  640. */
  641. constexpr basic_outcome(const success_type<void> &o) noexcept(std::is_nothrow_default_constructible<value_type>::value) // NOLINT
  642. : base{in_place_type<typename base::_value_type>}
  643. {
  644. hooks::set_spare_storage(this, o.spare_storage());
  645. no_value_policy_type::on_outcome_copy_construction(this, o);
  646. }
  647. /*! AWAITING HUGO JSON CONVERSION TOOL
  648. SIGNATURE NOT RECOGNISED
  649. */
  650. BOOST_OUTCOME_TEMPLATE(class T)
  651. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_compatible_conversion<T, void, void, void>))
  652. constexpr basic_outcome(const success_type<T> &o) noexcept(detail::is_nothrow_constructible<value_type, T>) // NOLINT
  653. : base{in_place_type<typename base::_value_type>, detail::extract_value_from_success<value_type>(o)}
  654. {
  655. hooks::set_spare_storage(this, o.spare_storage());
  656. no_value_policy_type::on_outcome_copy_construction(this, o);
  657. }
  658. /*! AWAITING HUGO JSON CONVERSION TOOL
  659. SIGNATURE NOT RECOGNISED
  660. */
  661. BOOST_OUTCOME_TEMPLATE(class T)
  662. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_compatible_conversion<T, void, void, void>))
  663. constexpr basic_outcome(success_type<T> &&o) noexcept(detail::is_nothrow_constructible<value_type, T>) // NOLINT
  664. : base{in_place_type<typename base::_value_type>, detail::extract_value_from_success<value_type>(static_cast<success_type<T> &&>(o))}
  665. {
  666. hooks::set_spare_storage(this, o.spare_storage());
  667. no_value_policy_type::on_outcome_move_construction(this, static_cast<success_type<T> &&>(o));
  668. }
  669. /*! AWAITING HUGO JSON CONVERSION TOOL
  670. SIGNATURE NOT RECOGNISED
  671. */
  672. BOOST_OUTCOME_TEMPLATE(class T)
  673. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_compatible_conversion<void, T, void, void>))
  674. constexpr basic_outcome(const failure_type<T> &o,
  675. error_failure_tag /*unused*/ = error_failure_tag()) noexcept(detail::is_nothrow_constructible<error_type, T>) // NOLINT
  676. : base{in_place_type<typename base::_error_type>, detail::extract_error_from_failure<error_type>(o)}
  677. , _ptr()
  678. {
  679. hooks::set_spare_storage(this, o.spare_storage());
  680. no_value_policy_type::on_outcome_copy_construction(this, o);
  681. }
  682. /*! AWAITING HUGO JSON CONVERSION TOOL
  683. SIGNATURE NOT RECOGNISED
  684. */
  685. BOOST_OUTCOME_TEMPLATE(class T)
  686. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_compatible_conversion<void, void, T, void>))
  687. constexpr basic_outcome(const failure_type<T> &o,
  688. exception_failure_tag /*unused*/ = exception_failure_tag()) noexcept(detail::is_nothrow_constructible<exception_type, T>) // NOLINT
  689. : base()
  690. , _ptr(detail::extract_exception_from_failure<exception_type>(o))
  691. {
  692. this->_state._status.set_have_exception(true);
  693. hooks::set_spare_storage(this, o.spare_storage());
  694. no_value_policy_type::on_outcome_copy_construction(this, o);
  695. }
  696. /*! AWAITING HUGO JSON CONVERSION TOOL
  697. SIGNATURE NOT RECOGNISED
  698. */
  699. BOOST_OUTCOME_TEMPLATE(class T)
  700. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_make_error_code_compatible_conversion<void, T, void, void>))
  701. constexpr basic_outcome(const failure_type<T> &o,
  702. explicit_make_error_code_compatible_copy_conversion_tag /*unused*/ =
  703. explicit_make_error_code_compatible_copy_conversion_tag()) noexcept(noexcept(make_error_code(std::declval<T>()))) // NOLINT
  704. : base{in_place_type<typename base::_error_type>, make_error_code(detail::extract_error_from_failure<error_type>(o))}
  705. , _ptr()
  706. {
  707. hooks::set_spare_storage(this, o.spare_storage());
  708. no_value_policy_type::on_outcome_copy_construction(this, o);
  709. }
  710. /*! AWAITING HUGO JSON CONVERSION TOOL
  711. SIGNATURE NOT RECOGNISED
  712. */
  713. BOOST_OUTCOME_TEMPLATE(class T, class U)
  714. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(!std::is_void<U>::value && predicate::template enable_compatible_conversion<void, T, U, void>))
  715. constexpr basic_outcome(const failure_type<T, U> &o, explicit_compatible_copy_conversion_tag /*unused*/ = explicit_compatible_copy_conversion_tag()) noexcept(
  716. detail::is_nothrow_constructible<error_type, T> &&detail::is_nothrow_constructible<exception_type, U>) // NOLINT
  717. : base{in_place_type<typename base::_error_type>, detail::extract_error_from_failure<error_type>(o)}
  718. , _ptr(detail::extract_exception_from_failure<exception_type>(o))
  719. {
  720. if(!o.has_error())
  721. {
  722. this->_state._status.set_have_error(false);
  723. }
  724. if(o.has_exception())
  725. {
  726. this->_state._status.set_have_exception(true);
  727. }
  728. hooks::set_spare_storage(this, o.spare_storage());
  729. no_value_policy_type::on_outcome_copy_construction(this, o);
  730. }
  731. /*! AWAITING HUGO JSON CONVERSION TOOL
  732. SIGNATURE NOT RECOGNISED
  733. */
  734. BOOST_OUTCOME_TEMPLATE(class T)
  735. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_compatible_conversion<void, T, void, void>))
  736. constexpr basic_outcome(failure_type<T> &&o,
  737. error_failure_tag /*unused*/ = error_failure_tag()) noexcept(detail::is_nothrow_constructible<error_type, T>) // NOLINT
  738. : base{in_place_type<typename base::_error_type>, detail::extract_error_from_failure<error_type>(static_cast<failure_type<T> &&>(o))}
  739. , _ptr()
  740. {
  741. hooks::set_spare_storage(this, o.spare_storage());
  742. no_value_policy_type::on_outcome_copy_construction(this, o);
  743. }
  744. /*! AWAITING HUGO JSON CONVERSION TOOL
  745. SIGNATURE NOT RECOGNISED
  746. */
  747. BOOST_OUTCOME_TEMPLATE(class T)
  748. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_compatible_conversion<void, void, T, void>))
  749. constexpr basic_outcome(failure_type<T> &&o,
  750. exception_failure_tag /*unused*/ = exception_failure_tag()) noexcept(detail::is_nothrow_constructible<exception_type, T>) // NOLINT
  751. : base()
  752. , _ptr(detail::extract_exception_from_failure<exception_type>(static_cast<failure_type<T> &&>(o)))
  753. {
  754. this->_state._status.set_have_exception(true);
  755. hooks::set_spare_storage(this, o.spare_storage());
  756. no_value_policy_type::on_outcome_copy_construction(this, o);
  757. }
  758. /*! AWAITING HUGO JSON CONVERSION TOOL
  759. SIGNATURE NOT RECOGNISED
  760. */
  761. BOOST_OUTCOME_TEMPLATE(class T)
  762. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_make_error_code_compatible_conversion<void, T, void, void>))
  763. constexpr basic_outcome(failure_type<T> &&o,
  764. explicit_make_error_code_compatible_move_conversion_tag /*unused*/ =
  765. explicit_make_error_code_compatible_move_conversion_tag()) noexcept(noexcept(make_error_code(std::declval<T>()))) // NOLINT
  766. : base{in_place_type<typename base::_error_type>, make_error_code(detail::extract_error_from_failure<error_type>(static_cast<failure_type<T> &&>(o)))}
  767. , _ptr()
  768. {
  769. hooks::set_spare_storage(this, o.spare_storage());
  770. no_value_policy_type::on_outcome_copy_construction(this, o);
  771. }
  772. /*! AWAITING HUGO JSON CONVERSION TOOL
  773. SIGNATURE NOT RECOGNISED
  774. */
  775. BOOST_OUTCOME_TEMPLATE(class T, class U)
  776. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(!std::is_void<U>::value && predicate::template enable_compatible_conversion<void, T, U, void>))
  777. constexpr basic_outcome(failure_type<T, U> &&o, explicit_compatible_move_conversion_tag /*unused*/ = explicit_compatible_move_conversion_tag()) noexcept(
  778. detail::is_nothrow_constructible<error_type, T> &&detail::is_nothrow_constructible<exception_type, U>) // NOLINT
  779. : base{in_place_type<typename base::_error_type>, detail::extract_error_from_failure<error_type>(static_cast<failure_type<T, U> &&>(o))}
  780. , _ptr(detail::extract_exception_from_failure<exception_type>(static_cast<failure_type<T, U> &&>(o)))
  781. {
  782. if(!o.has_error())
  783. {
  784. this->_state._status.set_have_error(false);
  785. }
  786. if(o.has_exception())
  787. {
  788. this->_state._status.set_have_exception(true);
  789. }
  790. hooks::set_spare_storage(this, o.spare_storage());
  791. no_value_policy_type::on_outcome_move_construction(this, static_cast<failure_type<T, U> &&>(o));
  792. }
  793. /*! AWAITING HUGO JSON CONVERSION TOOL
  794. SIGNATURE NOT RECOGNISED
  795. */
  796. using base::operator==;
  797. using base::operator!=;
  798. /*! AWAITING HUGO JSON CONVERSION TOOL
  799. SIGNATURE NOT RECOGNISED
  800. */
  801. BOOST_OUTCOME_TEMPLATE(class T, class U, class V, class W)
  802. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TEXPR(std::declval<detail::devoid<value_type>>() == std::declval<detail::devoid<T>>()), //
  803. BOOST_OUTCOME_TEXPR(std::declval<detail::devoid<error_type>>() == std::declval<detail::devoid<U>>()), //
  804. BOOST_OUTCOME_TEXPR(std::declval<detail::devoid<exception_type>>() == std::declval<detail::devoid<V>>()))
  805. constexpr bool operator==(const basic_outcome<T, U, V, W> &o) const noexcept( //
  806. noexcept(std::declval<detail::devoid<value_type>>() == std::declval<detail::devoid<T>>()) //
  807. &&noexcept(std::declval<detail::devoid<error_type>>() == std::declval<detail::devoid<U>>()) //
  808. &&noexcept(std::declval<detail::devoid<exception_type>>() == std::declval<detail::devoid<V>>()))
  809. {
  810. if(this->_state._status.have_value() && o._state._status.have_value())
  811. {
  812. return this->_state._value == o._state._value; // NOLINT
  813. }
  814. if(this->_state._status.have_error() && o._state._status.have_error() //
  815. && this->_state._status.have_exception() && o._state._status.have_exception())
  816. {
  817. return this->_state._error == o._state._error && this->_ptr == o._ptr;
  818. }
  819. if(this->_state._status.have_error() && o._state._status.have_error())
  820. {
  821. return this->_state._error == o._state._error;
  822. }
  823. if(this->_state._status.have_exception() && o._state._status.have_exception())
  824. {
  825. return this->_ptr == o._ptr;
  826. }
  827. return false;
  828. }
  829. /*! AWAITING HUGO JSON CONVERSION TOOL
  830. SIGNATURE NOT RECOGNISED
  831. */
  832. BOOST_OUTCOME_TEMPLATE(class T, class U)
  833. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TEXPR(std::declval<error_type>() == std::declval<T>()), //
  834. BOOST_OUTCOME_TEXPR(std::declval<exception_type>() == std::declval<U>()))
  835. constexpr bool operator==(const failure_type<T, U> &o) const noexcept( //
  836. noexcept(std::declval<error_type>() == std::declval<T>()) &&noexcept(std::declval<exception_type>() == std::declval<U>()))
  837. {
  838. if(this->_state._status.have_error() && o._state._status.have_error() //
  839. && this->_state._status.have_exception() && o._state._status.have_exception())
  840. {
  841. return this->_state._error == o.error() && this->_ptr == o.exception();
  842. }
  843. if(this->_state._status.have_error() && o._state._status.have_error())
  844. {
  845. return this->_state._error == o.error();
  846. }
  847. if(this->_state._status.have_exception() && o._state._status.have_exception())
  848. {
  849. return this->_ptr == o.exception();
  850. }
  851. return false;
  852. }
  853. /*! AWAITING HUGO JSON CONVERSION TOOL
  854. SIGNATURE NOT RECOGNISED
  855. */
  856. BOOST_OUTCOME_TEMPLATE(class T, class U, class V, class W)
  857. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TEXPR(std::declval<detail::devoid<value_type>>() != std::declval<detail::devoid<T>>()), //
  858. BOOST_OUTCOME_TEXPR(std::declval<detail::devoid<error_type>>() != std::declval<detail::devoid<U>>()), //
  859. BOOST_OUTCOME_TEXPR(std::declval<detail::devoid<exception_type>>() != std::declval<detail::devoid<V>>()))
  860. constexpr bool operator!=(const basic_outcome<T, U, V, W> &o) const noexcept( //
  861. noexcept(std::declval<detail::devoid<value_type>>() != std::declval<detail::devoid<T>>()) //
  862. &&noexcept(std::declval<detail::devoid<error_type>>() != std::declval<detail::devoid<U>>()) //
  863. &&noexcept(std::declval<detail::devoid<exception_type>>() != std::declval<detail::devoid<V>>()))
  864. {
  865. if(this->_state._status.have_value() && o._state._status.have_value())
  866. {
  867. return this->_state._value != o._state._value; // NOLINT
  868. }
  869. if(this->_state._status.have_error() && o._state._status.have_error() //
  870. && this->_state._status.have_exception() && o._state._status.have_exception())
  871. {
  872. return this->_state._error != o._state._error || this->_ptr != o._ptr;
  873. }
  874. if(this->_state._status.have_error() && o._state._status.have_error())
  875. {
  876. return this->_state._error != o._state._error;
  877. }
  878. if(this->_state._status.have_exception() && o._state._status.have_exception())
  879. {
  880. return this->_ptr != o._ptr;
  881. }
  882. return true;
  883. }
  884. /*! AWAITING HUGO JSON CONVERSION TOOL
  885. SIGNATURE NOT RECOGNISED
  886. */
  887. BOOST_OUTCOME_TEMPLATE(class T, class U)
  888. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TEXPR(std::declval<error_type>() != std::declval<T>()), //
  889. BOOST_OUTCOME_TEXPR(std::declval<exception_type>() != std::declval<U>()))
  890. constexpr bool operator!=(const failure_type<T, U> &o) const noexcept( //
  891. noexcept(std::declval<error_type>() == std::declval<T>()) &&noexcept(std::declval<exception_type>() == std::declval<U>()))
  892. {
  893. if(this->_state._status.have_error() && o._state._status.have_error() //
  894. && this->_state._status.have_exception() && o._state._status.have_exception())
  895. {
  896. return this->_state._error != o.error() || this->_ptr != o.exception();
  897. }
  898. if(this->_state._status.have_error() && o._state._status.have_error())
  899. {
  900. return this->_state._error != o.error();
  901. }
  902. if(this->_state._status.have_exception() && o._state._status.have_exception())
  903. {
  904. return this->_ptr != o.exception();
  905. }
  906. return true;
  907. }
  908. /*! AWAITING HUGO JSON CONVERSION TOOL
  909. SIGNATURE NOT RECOGNISED
  910. */
  911. constexpr void swap(basic_outcome &o) noexcept((std::is_void<value_type>::value || detail::is_nothrow_swappable<value_type>::value) //
  912. && (std::is_void<error_type>::value || detail::is_nothrow_swappable<error_type>::value) //
  913. && (std::is_void<exception_type>::value || detail::is_nothrow_swappable<exception_type>::value))
  914. {
  915. #ifndef BOOST_NO_EXCEPTIONS
  916. constexpr bool value_throws = !std::is_void<value_type>::value && !detail::is_nothrow_swappable<value_type>::value;
  917. constexpr bool error_throws = !std::is_void<error_type>::value && !detail::is_nothrow_swappable<error_type>::value;
  918. constexpr bool exception_throws = !std::is_void<exception_type>::value && !detail::is_nothrow_swappable<exception_type>::value;
  919. #ifdef _MSC_VER
  920. #pragma warning(push)
  921. #pragma warning(disable : 4127) // conditional expression is constant
  922. #endif
  923. if(!exception_throws && !value_throws && !error_throws)
  924. {
  925. // Simples
  926. this->_state.swap(o._state);
  927. using std::swap;
  928. swap(this->_ptr, o._ptr);
  929. return;
  930. }
  931. struct _
  932. {
  933. basic_outcome &a, &b;
  934. bool exceptioned{false};
  935. bool all_good{false};
  936. ~_()
  937. {
  938. if(!this->all_good)
  939. {
  940. // We lost one of the values
  941. this->a._state._status.set_have_lost_consistency(true);
  942. this->b._state._status.set_have_lost_consistency(true);
  943. return;
  944. }
  945. if(this->exceptioned)
  946. {
  947. // The value + error swap threw an exception. Try to swap back _ptr
  948. try
  949. {
  950. strong_swap(this->all_good, this->a._ptr, this->b._ptr);
  951. }
  952. catch(...)
  953. {
  954. // We lost one of the values
  955. this->a._state._status.set_have_lost_consistency(true);
  956. this->b._state._status.set_have_lost_consistency(true);
  957. // throw away second exception
  958. }
  959. // Prevent has_value() == has_error() or has_value() == has_exception()
  960. auto check = [](basic_outcome *t) {
  961. if(t->has_value() && (t->has_error() || t->has_exception()))
  962. {
  963. t->_state._status.set_have_error(false).set_have_exception(false);
  964. t->_state._status.set_have_lost_consistency(true);
  965. }
  966. if(!t->has_value() && !(t->has_error() || t->has_exception()))
  967. {
  968. // Choose error, for no particular reason
  969. t->_state._status.set_have_error(true).set_have_lost_consistency(true);
  970. }
  971. };
  972. check(&this->a);
  973. check(&this->b);
  974. }
  975. }
  976. } _{*this, o};
  977. strong_swap(_.all_good, this->_ptr, o._ptr);
  978. _.exceptioned = true;
  979. this->_state.swap(o._state);
  980. _.exceptioned = false;
  981. #ifdef _MSC_VER
  982. #pragma warning(pop)
  983. #endif
  984. #else
  985. this->_state.swap(o._state);
  986. using std::swap;
  987. swap(this->_ptr, o._ptr);
  988. #endif
  989. }
  990. /*! AWAITING HUGO JSON CONVERSION TOOL
  991. SIGNATURE NOT RECOGNISED
  992. */
  993. failure_type<error_type, exception_type> as_failure() const &
  994. {
  995. if(this->has_error() && this->has_exception())
  996. {
  997. return failure_type<error_type, exception_type>(this->assume_error(), this->assume_exception(), hooks::spare_storage(this));
  998. }
  999. if(this->has_exception())
  1000. {
  1001. return failure_type<error_type, exception_type>(in_place_type<exception_type>, this->assume_exception(), hooks::spare_storage(this));
  1002. }
  1003. return failure_type<error_type, exception_type>(in_place_type<error_type>, this->assume_error(), hooks::spare_storage(this));
  1004. }
  1005. /*! AWAITING HUGO JSON CONVERSION TOOL
  1006. SIGNATURE NOT RECOGNISED
  1007. */
  1008. failure_type<error_type, exception_type> as_failure() &&
  1009. {
  1010. this->_state._status.set_have_moved_from(true);
  1011. if(this->has_error() && this->has_exception())
  1012. {
  1013. return failure_type<error_type, exception_type>(static_cast<S &&>(this->assume_error()), static_cast<P &&>(this->assume_exception()),
  1014. hooks::spare_storage(this));
  1015. }
  1016. if(this->has_exception())
  1017. {
  1018. return failure_type<error_type, exception_type>(in_place_type<exception_type>, static_cast<P &&>(this->assume_exception()), hooks::spare_storage(this));
  1019. }
  1020. return failure_type<error_type, exception_type>(in_place_type<error_type>, static_cast<S &&>(this->assume_error()), hooks::spare_storage(this));
  1021. }
  1022. #ifdef __APPLE__
  1023. failure_type<error_type, exception_type> _xcode_workaround_as_failure() &&;
  1024. #endif
  1025. };
  1026. // C++ 20 operator== rewriting should take care of this for us, indeed
  1027. // if we don't disable it, we cause Concept recursion to infinity!
  1028. #if __cplusplus < 202000L && !_HAS_CXX20
  1029. /*! AWAITING HUGO JSON CONVERSION TOOL
  1030. SIGNATURE NOT RECOGNISED
  1031. */
  1032. BOOST_OUTCOME_TEMPLATE(class T, class U, class V, //
  1033. class R, class S, class P, class N)
  1034. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TEXPR(std::declval<basic_outcome<R, S, P, N>>() == std::declval<basic_result<T, U, V>>()))
  1035. constexpr inline bool operator==(const basic_result<T, U, V> &a, const basic_outcome<R, S, P, N> &b) noexcept( //
  1036. noexcept(std::declval<basic_outcome<R, S, P, N>>() == std::declval<basic_result<T, U, V>>()))
  1037. {
  1038. return b == a;
  1039. }
  1040. #endif
  1041. /*! AWAITING HUGO JSON CONVERSION TOOL
  1042. SIGNATURE NOT RECOGNISED
  1043. */
  1044. BOOST_OUTCOME_TEMPLATE(class T, class U, class V, //
  1045. class R, class S, class P, class N)
  1046. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TEXPR(std::declval<basic_outcome<R, S, P, N>>() != std::declval<basic_result<T, U, V>>()))
  1047. constexpr inline bool operator!=(const basic_result<T, U, V> &a, const basic_outcome<R, S, P, N> &b) noexcept( //
  1048. noexcept(std::declval<basic_outcome<R, S, P, N>>() != std::declval<basic_result<T, U, V>>()))
  1049. {
  1050. return b != a;
  1051. }
  1052. /*! AWAITING HUGO JSON CONVERSION TOOL
  1053. SIGNATURE NOT RECOGNISED
  1054. */
  1055. template <class R, class S, class P, class N> inline void swap(basic_outcome<R, S, P, N> &a, basic_outcome<R, S, P, N> &b) noexcept(noexcept(a.swap(b)))
  1056. {
  1057. a.swap(b);
  1058. }
  1059. namespace hooks
  1060. {
  1061. /*! AWAITING HUGO JSON CONVERSION TOOL
  1062. SIGNATURE NOT RECOGNISED
  1063. */
  1064. template <class R, class S, class P, class NoValuePolicy, class U>
  1065. constexpr inline void override_outcome_exception(basic_outcome<R, S, P, NoValuePolicy> *o, U &&v) noexcept
  1066. {
  1067. o->_ptr = static_cast<U &&>(v); // NOLINT
  1068. o->_state._status.set_have_exception(true);
  1069. }
  1070. } // namespace hooks
  1071. BOOST_OUTCOME_V2_NAMESPACE_END
  1072. #ifdef __clang__
  1073. #pragma clang diagnostic pop
  1074. #endif
  1075. #include "detail/basic_outcome_exception_observers_impl.hpp"
  1076. #if !defined(NDEBUG)
  1077. BOOST_OUTCOME_V2_NAMESPACE_BEGIN
  1078. // Check is trivial in all ways except default constructibility and standard layout
  1079. // static_assert(std::is_trivial<basic_outcome<int, long, double, policy::all_narrow>>::value, "outcome<int> is not trivial!");
  1080. // static_assert(std::is_trivially_default_constructible<basic_outcome<int, long, double, policy::all_narrow>>::value, "outcome<int> is not trivially default
  1081. // constructible!");
  1082. static_assert(std::is_trivially_copyable<basic_outcome<int, long, double, policy::all_narrow>>::value, "outcome<int> is not trivially copyable!");
  1083. static_assert(std::is_trivially_assignable<basic_outcome<int, long, double, policy::all_narrow>, basic_outcome<int, long, double, policy::all_narrow>>::value,
  1084. "outcome<int> is not trivially assignable!");
  1085. static_assert(std::is_trivially_destructible<basic_outcome<int, long, double, policy::all_narrow>>::value, "outcome<int> is not trivially destructible!");
  1086. static_assert(std::is_trivially_copy_constructible<basic_outcome<int, long, double, policy::all_narrow>>::value,
  1087. "outcome<int> is not trivially copy constructible!");
  1088. static_assert(std::is_trivially_move_constructible<basic_outcome<int, long, double, policy::all_narrow>>::value,
  1089. "outcome<int> is not trivially move constructible!");
  1090. static_assert(std::is_trivially_copy_assignable<basic_outcome<int, long, double, policy::all_narrow>>::value, "outcome<int> is not trivially copy assignable!");
  1091. static_assert(std::is_trivially_move_assignable<basic_outcome<int, long, double, policy::all_narrow>>::value, "outcome<int> is not trivially move assignable!");
  1092. // Can't be standard layout as non-static member data is defined in more than one inherited class
  1093. // static_assert(std::is_standard_layout<basic_outcome<int, long, double, policy::all_narrow>>::value, "outcome<int> is not a standard layout type!");
  1094. BOOST_OUTCOME_V2_NAMESPACE_END
  1095. #endif
  1096. #endif