basic_outcome.hpp 60 KB

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