basic_outcome.hpp 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019
  1. /* A less simple result type
  2. (C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (59 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. BOOST_OUTCOME_REQUIRES(trait::type_can_be_used_in_basic_result<P> && (std::is_void<P>::value || std::is_default_constructible<P>::value)) //
  38. class basic_outcome;
  39. namespace detail
  40. {
  41. // May be reused by basic_outcome subclasses to save load on the compiler
  42. template <class value_type, class error_type, class exception_type> struct outcome_predicates
  43. {
  44. using result = result_predicates<value_type, error_type>;
  45. // Predicate for the implicit constructors to be available
  46. static constexpr bool implicit_constructors_enabled = //
  47. result::implicit_constructors_enabled //
  48. && !detail::is_implicitly_constructible<value_type, exception_type> //
  49. && !detail::is_implicitly_constructible<error_type, exception_type> //
  50. && !detail::is_implicitly_constructible<exception_type, value_type> //
  51. && !detail::is_implicitly_constructible<exception_type, error_type>;
  52. // Predicate for the value converting constructor to be available.
  53. template <class T>
  54. static constexpr bool enable_value_converting_constructor = //
  55. implicit_constructors_enabled //
  56. &&result::template enable_value_converting_constructor<T> //
  57. && !detail::is_implicitly_constructible<exception_type, T>; // deliberately less tolerant of ambiguity than result's edition
  58. // Predicate for the error converting constructor to be available.
  59. template <class T>
  60. static constexpr bool enable_error_converting_constructor = //
  61. implicit_constructors_enabled //
  62. &&result::template enable_error_converting_constructor<T> //
  63. && !detail::is_implicitly_constructible<exception_type, T>; // deliberately less tolerant of ambiguity than result's edition
  64. // Predicate for the error condition converting constructor to be available.
  65. template <class ErrorCondEnum>
  66. static constexpr bool enable_error_condition_converting_constructor = result::template enable_error_condition_converting_constructor<ErrorCondEnum> //
  67. && !detail::is_implicitly_constructible<exception_type, ErrorCondEnum>;
  68. // Predicate for the exception converting constructor to be available.
  69. template <class T>
  70. static constexpr bool enable_exception_converting_constructor = //
  71. implicit_constructors_enabled //
  72. && !is_in_place_type_t<std::decay_t<T>>::value // not in place construction
  73. && !detail::is_implicitly_constructible<value_type, T> && !detail::is_implicitly_constructible<error_type, T> && 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 || detail::is_explicitly_constructible<value_type, typename basic_outcome<T, U, V, W>::value_type>) // if our value types are constructible
  85. &&(std::is_void<U>::value || detail::is_explicitly_constructible<error_type, typename basic_outcome<T, U, V, W>::error_type>) // if our error types are constructible
  86. &&(std::is_void<V>::value || detail::is_explicitly_constructible<exception_type, typename basic_outcome<T, U, V, W>::exception_type>) // if our exception types are constructible
  87. ;
  88. // Predicate for the implicit converting inplace constructor from a compatible input to be available.
  89. struct disable_inplace_value_error_exception_constructor;
  90. template <class... Args>
  91. using choose_inplace_value_error_exception_constructor = std::conditional_t< //
  92. ((static_cast<int>(std::is_constructible<value_type, Args...>::value) + static_cast<int>(std::is_constructible<error_type, Args...>::value) + static_cast<int>(std::is_constructible<exception_type, Args...>::value)) > 1), //
  93. disable_inplace_value_error_exception_constructor, //
  94. std::conditional_t< //
  95. std::is_constructible<value_type, Args...>::value, //
  96. value_type, //
  97. std::conditional_t< //
  98. std::is_constructible<error_type, Args...>::value, //
  99. error_type, //
  100. std::conditional_t< //
  101. std::is_constructible<exception_type, Args...>::value, //
  102. exception_type, //
  103. disable_inplace_value_error_exception_constructor>>>>;
  104. template <class... Args>
  105. static constexpr bool enable_inplace_value_error_exception_constructor = //
  106. implicit_constructors_enabled && !std::is_same<choose_inplace_value_error_exception_constructor<Args...>, disable_inplace_value_error_exception_constructor>::value;
  107. };
  108. // Select whether to use basic_outcome_failure_observers or not
  109. template <class Base, class R, class S, class P, class NoValuePolicy>
  110. using select_basic_outcome_failure_observers = //
  111. std::conditional_t<trait::is_error_code_available<S>::value && trait::is_exception_ptr_available<P>::value, basic_outcome_failure_observers<Base, R, S, P, NoValuePolicy>, Base>;
  112. template <class T, class U, class V> constexpr inline const V &extract_exception_from_failure(const failure_type<U, V> &v) { return v.exception(); }
  113. template <class T, class U, class V> constexpr inline V &&extract_exception_from_failure(failure_type<U, V> &&v) { return static_cast<failure_type<U, V> &&>(v).exception(); }
  114. template <class T, class U> constexpr inline const U &extract_exception_from_failure(const failure_type<U, void> &v) { return v.error(); }
  115. template <class T, class U> constexpr inline U &&extract_exception_from_failure(failure_type<U, void> &&v) { return static_cast<failure_type<U, void> &&>(v).error(); }
  116. template <class T> struct is_basic_outcome
  117. {
  118. static constexpr bool value = false;
  119. };
  120. template <class R, class S, class T, class N> struct is_basic_outcome<basic_outcome<R, S, T, N>>
  121. {
  122. static constexpr bool value = true;
  123. };
  124. } // namespace detail
  125. /*! AWAITING HUGO JSON CONVERSION TOOL
  126. type alias template <class T> is_basic_outcome. Potential doc page: `is_basic_outcome<T>`
  127. */
  128. template <class T> using is_basic_outcome = detail::is_basic_outcome<std::decay_t<T>>;
  129. /*! AWAITING HUGO JSON CONVERSION TOOL
  130. SIGNATURE NOT RECOGNISED
  131. */
  132. template <class T> static constexpr bool is_basic_outcome_v = detail::is_basic_outcome<std::decay_t<T>>::value;
  133. namespace hooks
  134. {
  135. /*! AWAITING HUGO JSON CONVERSION TOOL
  136. SIGNATURE NOT RECOGNISED
  137. */
  138. template <class T, class... U> constexpr inline void hook_outcome_construction(T * /*unused*/, U &&... /*unused*/) noexcept {}
  139. /*! AWAITING HUGO JSON CONVERSION TOOL
  140. SIGNATURE NOT RECOGNISED
  141. */
  142. template <class T, class U> constexpr inline void hook_outcome_copy_construction(T * /*unused*/, U && /*unused*/) noexcept {}
  143. /*! AWAITING HUGO JSON CONVERSION TOOL
  144. SIGNATURE NOT RECOGNISED
  145. */
  146. template <class T, class U> constexpr inline void hook_outcome_move_construction(T * /*unused*/, U && /*unused*/) noexcept {}
  147. /*! AWAITING HUGO JSON CONVERSION TOOL
  148. SIGNATURE NOT RECOGNISED
  149. */
  150. template <class T, class U, class... Args> constexpr inline void hook_outcome_in_place_construction(T * /*unused*/, in_place_type_t<U> /*unused*/, Args &&... /*unused*/) noexcept {}
  151. /*! AWAITING HUGO JSON CONVERSION TOOL
  152. SIGNATURE NOT RECOGNISED
  153. */
  154. template <class R, class S, class P, class NoValuePolicy, class U> constexpr inline void override_outcome_exception(basic_outcome<R, S, P, NoValuePolicy> *o, U &&v) noexcept;
  155. } // namespace hooks
  156. /*! AWAITING HUGO JSON CONVERSION TOOL
  157. type definition template <class R, class S, class P, class NoValuePolicy> basic_outcome. Potential doc page: `basic_outcome<T, EC, EP, NoValuePolicy>`
  158. */
  159. template <class R, class S, class P, class NoValuePolicy> //
  160. BOOST_OUTCOME_REQUIRES(trait::type_can_be_used_in_basic_result<P> && (std::is_void<P>::value || std::is_default_constructible<P>::value)) //
  161. class BOOST_OUTCOME_NODISCARD basic_outcome
  162. #if defined(BOOST_OUTCOME_DOXYGEN_IS_IN_THE_HOUSE) || defined(BOOST_OUTCOME_STANDARDESE_IS_IN_THE_HOUSE)
  163. : public detail::basic_outcome_failure_observers<detail::basic_result_final<R, S, P, NoValuePolicy>, R, S, P, NoValuePolicy>,
  164. public detail::basic_outcome_exception_observers<detail::basic_result_final<R, S, NoValuePolicy>, R, S, P, NoValuePolicy>,
  165. public detail::basic_result_final<R, S, NoValuePolicy>
  166. #else
  167. : public detail::select_basic_outcome_failure_observers<detail::basic_outcome_exception_observers<detail::basic_result_final<R, S, NoValuePolicy>, R, S, P, NoValuePolicy>, R, S, P, NoValuePolicy>
  168. #endif
  169. {
  170. static_assert(trait::type_can_be_used_in_basic_result<P>, "The exception_type cannot be used");
  171. static_assert(std::is_void<P>::value || std::is_default_constructible<P>::value, "exception_type must be void or default constructible");
  172. using base = detail::select_basic_outcome_failure_observers<detail::basic_outcome_exception_observers<detail::basic_result_final<R, S, NoValuePolicy>, R, S, P, NoValuePolicy>, R, S, P, NoValuePolicy>;
  173. friend struct policy::base;
  174. template <class T, class U, class V, class W> friend class basic_outcome;
  175. template <class T, class U, class V, class W, class X> friend constexpr inline void hooks::override_outcome_exception(basic_outcome<T, U, V, W> *o, X &&v) noexcept; // NOLINT
  176. struct implicit_constructors_disabled_tag
  177. {
  178. };
  179. struct value_converting_constructor_tag
  180. {
  181. };
  182. struct error_converting_constructor_tag
  183. {
  184. };
  185. struct error_condition_converting_constructor_tag
  186. {
  187. };
  188. struct exception_converting_constructor_tag
  189. {
  190. };
  191. struct error_exception_converting_constructor_tag
  192. {
  193. };
  194. struct explicit_valueorerror_converting_constructor_tag
  195. {
  196. };
  197. struct error_failure_tag
  198. {
  199. };
  200. struct exception_failure_tag
  201. {
  202. };
  203. struct disable_in_place_value_type
  204. {
  205. };
  206. struct disable_in_place_error_type
  207. {
  208. };
  209. struct disable_in_place_exception_type
  210. {
  211. };
  212. public:
  213. using value_type = R;
  214. using error_type = S;
  215. using exception_type = P;
  216. template <class T, class U = S, class V = P, class W = NoValuePolicy> using rebind = basic_outcome<T, U, V, W>;
  217. protected:
  218. // Requirement predicates for outcome.
  219. struct predicate
  220. {
  221. using base = detail::outcome_predicates<value_type, error_type, exception_type>;
  222. // Predicate for any constructors to be available at all
  223. static constexpr bool constructors_enabled = (!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)) //
  224. && (!std::is_same<std::decay_t<value_type>, std::decay_t<exception_type>>::value || (std::is_void<value_type>::value && std::is_void<exception_type>::value)) //
  225. && (!std::is_same<std::decay_t<error_type>, std::decay_t<exception_type>>::value || (std::is_void<error_type>::value && std::is_void<exception_type>::value)) //
  226. ;
  227. // Predicate for implicit constructors to be available at all
  228. static constexpr bool implicit_constructors_enabled = constructors_enabled && base::implicit_constructors_enabled;
  229. // Predicate for the value converting constructor to be available.
  230. template <class T>
  231. static constexpr bool enable_value_converting_constructor = //
  232. constructors_enabled //
  233. && !std::is_same<std::decay_t<T>, basic_outcome>::value // not my type
  234. && base::template enable_value_converting_constructor<T>;
  235. // Predicate for the error converting constructor to be available.
  236. template <class T>
  237. static constexpr bool enable_error_converting_constructor = //
  238. constructors_enabled //
  239. && !std::is_same<std::decay_t<T>, basic_outcome>::value // not my type
  240. && base::template enable_error_converting_constructor<T>;
  241. // Predicate for the error condition converting constructor to be available.
  242. template <class ErrorCondEnum>
  243. static constexpr bool enable_error_condition_converting_constructor = //
  244. constructors_enabled //
  245. && !std::is_same<std::decay_t<ErrorCondEnum>, basic_outcome>::value // not my type
  246. && base::template enable_error_condition_converting_constructor<ErrorCondEnum>;
  247. // Predicate for the exception converting constructor to be available.
  248. template <class T>
  249. static constexpr bool enable_exception_converting_constructor = //
  250. constructors_enabled //
  251. && !std::is_same<std::decay_t<T>, basic_outcome>::value // not my type
  252. && base::template enable_exception_converting_constructor<T>;
  253. // Predicate for the error + exception converting constructor to be available.
  254. template <class T, class U>
  255. static constexpr bool enable_error_exception_converting_constructor = //
  256. constructors_enabled //
  257. && !std::is_same<std::decay_t<T>, basic_outcome>::value // not my type
  258. && base::template enable_error_exception_converting_constructor<T, U>;
  259. // Predicate for the converting constructor from a compatible input to be available.
  260. template <class T, class U, class V, class W>
  261. static constexpr bool enable_compatible_conversion = //
  262. constructors_enabled //
  263. && !std::is_same<basic_outcome<T, U, V, W>, basic_outcome>::value // not my type
  264. && base::template enable_compatible_conversion<T, U, V, W>;
  265. // Predicate for the inplace construction of value to be available.
  266. template <class... Args>
  267. static constexpr bool enable_inplace_value_constructor = //
  268. constructors_enabled //
  269. && (std::is_void<value_type>::value //
  270. || std::is_constructible<value_type, Args...>::value);
  271. // Predicate for the inplace construction of error to be available.
  272. template <class... Args>
  273. static constexpr bool enable_inplace_error_constructor = //
  274. constructors_enabled //
  275. && (std::is_void<error_type>::value //
  276. || std::is_constructible<error_type, Args...>::value);
  277. // Predicate for the inplace construction of exception to be available.
  278. template <class... Args>
  279. static constexpr bool enable_inplace_exception_constructor = //
  280. constructors_enabled //
  281. && (std::is_void<exception_type>::value //
  282. || std::is_constructible<exception_type, Args...>::value);
  283. // Predicate for the implicit converting inplace constructor to be available.
  284. template <class... Args>
  285. static constexpr bool enable_inplace_value_error_exception_constructor = //
  286. constructors_enabled //
  287. &&base::template enable_inplace_value_error_exception_constructor<Args...>;
  288. template <class... Args> using choose_inplace_value_error_exception_constructor = typename base::template choose_inplace_value_error_exception_constructor<Args...>;
  289. };
  290. public:
  291. using value_type_if_enabled = 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>;
  292. using error_type_if_enabled = 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>;
  293. using exception_type_if_enabled = std::conditional_t<std::is_same<exception_type, value_type>::value || std::is_same<exception_type, error_type>::value, disable_in_place_exception_type, exception_type>;
  294. protected:
  295. detail::devoid<exception_type> _ptr;
  296. public:
  297. /*! AWAITING HUGO JSON CONVERSION TOOL
  298. SIGNATURE NOT RECOGNISED
  299. */
  300. BOOST_OUTCOME_TEMPLATE(class Arg, class... Args)
  301. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED((!predicate::constructors_enabled && sizeof...(Args) >= 0)))
  302. basic_outcome(Arg && /*unused*/, Args &&... /*unused*/) = delete; // NOLINT basic_outcome<> with any of the same type is NOT SUPPORTED, see docs!
  303. /*! AWAITING HUGO JSON CONVERSION TOOL
  304. SIGNATURE NOT RECOGNISED
  305. */
  306. BOOST_OUTCOME_TEMPLATE(class T)
  307. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED((predicate::constructors_enabled && !predicate::implicit_constructors_enabled //
  308. && (detail::is_implicitly_constructible<value_type, T> || detail::is_implicitly_constructible<error_type, T> || detail::is_implicitly_constructible<exception_type, T>) )))
  309. basic_outcome(T && /*unused*/, implicit_constructors_disabled_tag /*unused*/ = implicit_constructors_disabled_tag()) = delete; // NOLINT Implicit constructors disabled, use explicit in_place_type<T>, success() or failure(). see docs!
  310. /*! AWAITING HUGO JSON CONVERSION TOOL
  311. SIGNATURE NOT RECOGNISED
  312. */
  313. BOOST_OUTCOME_TEMPLATE(class T)
  314. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_value_converting_constructor<T>))
  315. constexpr basic_outcome(T &&t, value_converting_constructor_tag /*unused*/ = value_converting_constructor_tag()) noexcept(std::is_nothrow_constructible<value_type, T>::value) // NOLINT
  316. : base{in_place_type<typename base::_value_type>, static_cast<T &&>(t)},
  317. _ptr()
  318. {
  319. using namespace hooks;
  320. hook_outcome_construction(this, static_cast<T &&>(t));
  321. }
  322. /*! AWAITING HUGO JSON CONVERSION TOOL
  323. SIGNATURE NOT RECOGNISED
  324. */
  325. BOOST_OUTCOME_TEMPLATE(class T)
  326. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_error_converting_constructor<T>))
  327. constexpr basic_outcome(T &&t, error_converting_constructor_tag /*unused*/ = error_converting_constructor_tag()) noexcept(std::is_nothrow_constructible<error_type, T>::value) // NOLINT
  328. : base{in_place_type<typename base::_error_type>, static_cast<T &&>(t)},
  329. _ptr()
  330. {
  331. using namespace hooks;
  332. hook_outcome_construction(this, static_cast<T &&>(t));
  333. }
  334. /*! AWAITING HUGO JSON CONVERSION TOOL
  335. SIGNATURE NOT RECOGNISED
  336. */
  337. BOOST_OUTCOME_TEMPLATE(class ErrorCondEnum)
  338. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TEXPR(error_type(make_error_code(ErrorCondEnum()))), //
  339. BOOST_OUTCOME_TPRED(predicate::template enable_error_condition_converting_constructor<ErrorCondEnum>))
  340. constexpr basic_outcome(ErrorCondEnum &&t, error_condition_converting_constructor_tag /*unused*/ = error_condition_converting_constructor_tag()) noexcept(noexcept(error_type(make_error_code(static_cast<ErrorCondEnum &&>(t))))) // NOLINT
  341. : base{in_place_type<typename base::_error_type>, make_error_code(t)}
  342. {
  343. using namespace hooks;
  344. hook_outcome_construction(this, static_cast<ErrorCondEnum &&>(t));
  345. }
  346. /*! AWAITING HUGO JSON CONVERSION TOOL
  347. SIGNATURE NOT RECOGNISED
  348. */
  349. BOOST_OUTCOME_TEMPLATE(class T)
  350. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_exception_converting_constructor<T>))
  351. constexpr basic_outcome(T &&t, exception_converting_constructor_tag /*unused*/ = exception_converting_constructor_tag()) noexcept(std::is_nothrow_constructible<exception_type, T>::value) // NOLINT
  352. : base(),
  353. _ptr(static_cast<T &&>(t))
  354. {
  355. using namespace hooks;
  356. this->_state._status |= detail::status_have_exception;
  357. hook_outcome_construction(this, static_cast<T &&>(t));
  358. }
  359. /*! AWAITING HUGO JSON CONVERSION TOOL
  360. SIGNATURE NOT RECOGNISED
  361. */
  362. BOOST_OUTCOME_TEMPLATE(class T, class U)
  363. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_error_exception_converting_constructor<T, U>))
  364. constexpr basic_outcome(T &&a, U &&b, error_exception_converting_constructor_tag /*unused*/ = error_exception_converting_constructor_tag()) noexcept(std::is_nothrow_constructible<error_type, T>::value &&std::is_nothrow_constructible<exception_type, U>::value) // NOLINT
  365. : base{in_place_type<typename base::_error_type>, static_cast<T &&>(a)},
  366. _ptr(static_cast<U &&>(b))
  367. {
  368. using namespace hooks;
  369. this->_state._status |= detail::status_have_exception;
  370. hook_outcome_construction(this, static_cast<T &&>(a), static_cast<U &&>(b));
  371. }
  372. /*! AWAITING HUGO JSON CONVERSION TOOL
  373. SIGNATURE NOT RECOGNISED
  374. */
  375. BOOST_OUTCOME_TEMPLATE(class T)
  376. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(convert::value_or_error<basic_outcome, std::decay_t<T>>::enable_result_inputs || !is_basic_result_v<T>), //
  377. BOOST_OUTCOME_TPRED(convert::value_or_error<basic_outcome, std::decay_t<T>>::enable_outcome_inputs || !is_basic_outcome_v<T>), //
  378. BOOST_OUTCOME_TEXPR(convert::value_or_error<basic_outcome, std::decay_t<T>>{}(std::declval<T>())))
  379. constexpr explicit basic_outcome(T &&o, explicit_valueorerror_converting_constructor_tag /*unused*/ = explicit_valueorerror_converting_constructor_tag()) // NOLINT
  380. : basic_outcome{convert::value_or_error<basic_outcome, std::decay_t<T>>{}(static_cast<T &&>(o))}
  381. {
  382. }
  383. /*! AWAITING HUGO JSON CONVERSION TOOL
  384. SIGNATURE NOT RECOGNISED
  385. */
  386. BOOST_OUTCOME_TEMPLATE(class T, class U, class V, class W)
  387. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_compatible_conversion<T, U, V, W>))
  388. constexpr explicit basic_outcome(const basic_outcome<T, U, V, W> &o) noexcept(std::is_nothrow_constructible<value_type, T>::value &&std::is_nothrow_constructible<error_type, U>::value &&std::is_nothrow_constructible<exception_type, V>::value)
  389. : base{typename base::compatible_conversion_tag(), o}
  390. , _ptr(o._ptr)
  391. {
  392. using namespace hooks;
  393. hook_outcome_copy_construction(this, o);
  394. }
  395. /*! AWAITING HUGO JSON CONVERSION TOOL
  396. SIGNATURE NOT RECOGNISED
  397. */
  398. BOOST_OUTCOME_TEMPLATE(class T, class U, class V, class W)
  399. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_compatible_conversion<T, U, V, W>))
  400. constexpr explicit basic_outcome(basic_outcome<T, U, V, W> &&o) noexcept(std::is_nothrow_constructible<value_type, T>::value &&std::is_nothrow_constructible<error_type, U>::value &&std::is_nothrow_constructible<exception_type, V>::value)
  401. : base{typename base::compatible_conversion_tag(), static_cast<basic_outcome<T, U, V, W> &&>(o)}
  402. , _ptr(static_cast<typename basic_outcome<T, U, V, W>::exception_type &&>(o._ptr))
  403. {
  404. using namespace hooks;
  405. hook_outcome_move_construction(this, static_cast<basic_outcome<T, U, V, W> &&>(o));
  406. }
  407. /*! AWAITING HUGO JSON CONVERSION TOOL
  408. SIGNATURE NOT RECOGNISED
  409. */
  410. BOOST_OUTCOME_TEMPLATE(class T, class U, class V)
  411. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(detail::result_predicates<value_type, error_type>::template enable_compatible_conversion<T, U, V>))
  412. constexpr explicit basic_outcome(const basic_result<T, U, V> &o) noexcept(std::is_nothrow_constructible<value_type, T>::value &&std::is_nothrow_constructible<error_type, U>::value &&std::is_nothrow_constructible<exception_type>::value)
  413. : base{typename base::compatible_conversion_tag(), o}
  414. , _ptr()
  415. {
  416. using namespace hooks;
  417. hook_outcome_copy_construction(this, o);
  418. }
  419. /*! AWAITING HUGO JSON CONVERSION TOOL
  420. SIGNATURE NOT RECOGNISED
  421. */
  422. BOOST_OUTCOME_TEMPLATE(class T, class U, class V)
  423. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(detail::result_predicates<value_type, error_type>::template enable_compatible_conversion<T, U, V>))
  424. constexpr explicit basic_outcome(basic_result<T, U, V> &&o) noexcept(std::is_nothrow_constructible<value_type, T>::value &&std::is_nothrow_constructible<error_type, U>::value &&std::is_nothrow_constructible<exception_type>::value)
  425. : base{typename base::compatible_conversion_tag(), static_cast<basic_result<T, U, V> &&>(o)}
  426. , _ptr()
  427. {
  428. using namespace hooks;
  429. hook_outcome_move_construction(this, static_cast<basic_result<T, U, V> &&>(o));
  430. }
  431. /*! AWAITING HUGO JSON CONVERSION TOOL
  432. SIGNATURE NOT RECOGNISED
  433. */
  434. BOOST_OUTCOME_TEMPLATE(class... Args)
  435. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_inplace_value_constructor<Args...>))
  436. constexpr explicit basic_outcome(in_place_type_t<value_type_if_enabled> _, Args &&... args) noexcept(std::is_nothrow_constructible<value_type, Args...>::value)
  437. : base{_, static_cast<Args &&>(args)...}
  438. , _ptr()
  439. {
  440. using namespace hooks;
  441. hook_outcome_in_place_construction(this, in_place_type<value_type>, static_cast<Args &&>(args)...);
  442. }
  443. /*! AWAITING HUGO JSON CONVERSION TOOL
  444. SIGNATURE NOT RECOGNISED
  445. */
  446. BOOST_OUTCOME_TEMPLATE(class U, class... Args)
  447. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_inplace_value_constructor<std::initializer_list<U>, Args...>))
  448. constexpr explicit basic_outcome(in_place_type_t<value_type_if_enabled> _, std::initializer_list<U> il, Args &&... args) noexcept(std::is_nothrow_constructible<value_type, std::initializer_list<U>, Args...>::value)
  449. : base{_, il, static_cast<Args &&>(args)...}
  450. , _ptr()
  451. {
  452. using namespace hooks;
  453. hook_outcome_in_place_construction(this, in_place_type<value_type>, il, static_cast<Args &&>(args)...);
  454. }
  455. /*! AWAITING HUGO JSON CONVERSION TOOL
  456. SIGNATURE NOT RECOGNISED
  457. */
  458. BOOST_OUTCOME_TEMPLATE(class... Args)
  459. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_inplace_error_constructor<Args...>))
  460. constexpr explicit basic_outcome(in_place_type_t<error_type_if_enabled> _, Args &&... args) noexcept(std::is_nothrow_constructible<error_type, Args...>::value)
  461. : base{_, static_cast<Args &&>(args)...}
  462. , _ptr()
  463. {
  464. using namespace hooks;
  465. hook_outcome_in_place_construction(this, in_place_type<error_type>, static_cast<Args &&>(args)...);
  466. }
  467. /*! AWAITING HUGO JSON CONVERSION TOOL
  468. SIGNATURE NOT RECOGNISED
  469. */
  470. BOOST_OUTCOME_TEMPLATE(class U, class... Args)
  471. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_inplace_error_constructor<std::initializer_list<U>, Args...>))
  472. constexpr explicit basic_outcome(in_place_type_t<error_type_if_enabled> _, std::initializer_list<U> il, Args &&... args) noexcept(std::is_nothrow_constructible<error_type, std::initializer_list<U>, Args...>::value)
  473. : base{_, il, static_cast<Args &&>(args)...}
  474. , _ptr()
  475. {
  476. using namespace hooks;
  477. hook_outcome_in_place_construction(this, in_place_type<error_type>, il, static_cast<Args &&>(args)...);
  478. }
  479. /*! AWAITING HUGO JSON CONVERSION TOOL
  480. SIGNATURE NOT RECOGNISED
  481. */
  482. BOOST_OUTCOME_TEMPLATE(class... Args)
  483. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_inplace_exception_constructor<Args...>))
  484. constexpr explicit basic_outcome(in_place_type_t<exception_type_if_enabled> /*unused*/, Args &&... args) noexcept(std::is_nothrow_constructible<exception_type, Args...>::value)
  485. : base()
  486. , _ptr(static_cast<Args &&>(args)...)
  487. {
  488. using namespace hooks;
  489. this->_state._status |= detail::status_have_exception;
  490. hook_outcome_in_place_construction(this, in_place_type<exception_type>, static_cast<Args &&>(args)...);
  491. }
  492. /*! AWAITING HUGO JSON CONVERSION TOOL
  493. SIGNATURE NOT RECOGNISED
  494. */
  495. BOOST_OUTCOME_TEMPLATE(class U, class... Args)
  496. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_inplace_exception_constructor<std::initializer_list<U>, Args...>))
  497. constexpr explicit basic_outcome(in_place_type_t<exception_type_if_enabled> /*unused*/, std::initializer_list<U> il, Args &&... args) noexcept(std::is_nothrow_constructible<exception_type, std::initializer_list<U>, Args...>::value)
  498. : base()
  499. , _ptr(il, static_cast<Args &&>(args)...)
  500. {
  501. using namespace hooks;
  502. this->_state._status |= detail::status_have_exception;
  503. hook_outcome_in_place_construction(this, in_place_type<exception_type>, il, static_cast<Args &&>(args)...);
  504. }
  505. /*! AWAITING HUGO JSON CONVERSION TOOL
  506. SIGNATURE NOT RECOGNISED
  507. */
  508. BOOST_OUTCOME_TEMPLATE(class A1, class A2, class... Args)
  509. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_inplace_value_error_exception_constructor<A1, A2, Args...>))
  510. constexpr basic_outcome(A1 &&a1, A2 &&a2, Args &&... args) noexcept(noexcept(typename predicate::template choose_inplace_value_error_exception_constructor<A1, A2, Args...>(std::declval<A1>(), std::declval<A2>(), std::declval<Args>()...)))
  511. : basic_outcome(in_place_type<typename predicate::template choose_inplace_value_error_exception_constructor<A1, A2, Args...>>, static_cast<A1 &&>(a1), static_cast<A2 &&>(a2), static_cast<Args &&>(args)...)
  512. {
  513. }
  514. /*! AWAITING HUGO JSON CONVERSION TOOL
  515. SIGNATURE NOT RECOGNISED
  516. */
  517. constexpr basic_outcome(const success_type<void> &o) noexcept(std::is_nothrow_default_constructible<value_type>::value) // NOLINT
  518. : base{in_place_type<typename base::_value_type>}
  519. {
  520. using namespace hooks;
  521. hook_outcome_copy_construction(this, o);
  522. }
  523. /*! AWAITING HUGO JSON CONVERSION TOOL
  524. SIGNATURE NOT RECOGNISED
  525. */
  526. BOOST_OUTCOME_TEMPLATE(class T)
  527. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_compatible_conversion<T, void, void, void>))
  528. constexpr basic_outcome(const success_type<T> &o) noexcept(std::is_nothrow_constructible<value_type, T>::value) // NOLINT
  529. : base{in_place_type<typename base::_value_type>, detail::extract_value_from_success<value_type>(o)}
  530. {
  531. using namespace hooks;
  532. hook_outcome_copy_construction(this, o);
  533. }
  534. /*! AWAITING HUGO JSON CONVERSION TOOL
  535. SIGNATURE NOT RECOGNISED
  536. */
  537. BOOST_OUTCOME_TEMPLATE(class T)
  538. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_compatible_conversion<T, void, void, void>))
  539. constexpr basic_outcome(success_type<T> &&o) noexcept(std::is_nothrow_constructible<value_type, T>::value) // NOLINT
  540. : base{in_place_type<typename base::_value_type>, detail::extract_value_from_success<value_type>(static_cast<success_type<T> &&>(o))}
  541. {
  542. using namespace hooks;
  543. hook_outcome_move_construction(this, static_cast<success_type<T> &&>(o));
  544. }
  545. /*! AWAITING HUGO JSON CONVERSION TOOL
  546. SIGNATURE NOT RECOGNISED
  547. */
  548. BOOST_OUTCOME_TEMPLATE(class T)
  549. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_compatible_conversion<void, T, void, void>))
  550. constexpr basic_outcome(const failure_type<T> &o, error_failure_tag /*unused*/ = error_failure_tag()) noexcept(std::is_nothrow_constructible<error_type, T>::value) // NOLINT
  551. : base{in_place_type<typename base::_error_type>, detail::extract_error_from_failure<error_type>(o)},
  552. _ptr()
  553. {
  554. using namespace hooks;
  555. hook_outcome_copy_construction(this, o);
  556. }
  557. /*! AWAITING HUGO JSON CONVERSION TOOL
  558. SIGNATURE NOT RECOGNISED
  559. */
  560. BOOST_OUTCOME_TEMPLATE(class T)
  561. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_compatible_conversion<void, void, T, void>))
  562. constexpr basic_outcome(const failure_type<T> &o, exception_failure_tag /*unused*/ = exception_failure_tag()) noexcept(std::is_nothrow_constructible<exception_type, T>::value) // NOLINT
  563. : base(),
  564. _ptr(detail::extract_exception_from_failure<exception_type>(o))
  565. {
  566. this->_state._status |= detail::status_have_exception;
  567. using namespace hooks;
  568. hook_outcome_copy_construction(this, o);
  569. }
  570. /*! AWAITING HUGO JSON CONVERSION TOOL
  571. SIGNATURE NOT RECOGNISED
  572. */
  573. BOOST_OUTCOME_TEMPLATE(class T, class U)
  574. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(!std::is_void<U>::value && predicate::template enable_compatible_conversion<void, T, U, void>))
  575. constexpr basic_outcome(const failure_type<T, U> &o) noexcept(std::is_nothrow_constructible<error_type, T>::value &&std::is_nothrow_constructible<exception_type, U>::value) // NOLINT
  576. : base{in_place_type<typename base::_error_type>, detail::extract_error_from_failure<error_type>(o)},
  577. _ptr(detail::extract_exception_from_failure<exception_type>(o))
  578. {
  579. if(!o.has_error())
  580. {
  581. this->_state._status &= ~detail::status_have_error;
  582. }
  583. if(o.has_exception())
  584. {
  585. this->_state._status |= detail::status_have_exception;
  586. }
  587. using namespace hooks;
  588. hook_outcome_copy_construction(this, o);
  589. }
  590. /*! AWAITING HUGO JSON CONVERSION TOOL
  591. SIGNATURE NOT RECOGNISED
  592. */
  593. BOOST_OUTCOME_TEMPLATE(class T)
  594. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_compatible_conversion<void, T, void, void>))
  595. constexpr basic_outcome(failure_type<T> &&o, error_failure_tag /*unused*/ = error_failure_tag()) noexcept(std::is_nothrow_constructible<error_type, T>::value) // NOLINT
  596. : base{in_place_type<typename base::_error_type>, detail::extract_error_from_failure<error_type>(static_cast<failure_type<T> &&>(o))},
  597. _ptr()
  598. {
  599. using namespace hooks;
  600. hook_outcome_copy_construction(this, o);
  601. }
  602. /*! AWAITING HUGO JSON CONVERSION TOOL
  603. SIGNATURE NOT RECOGNISED
  604. */
  605. BOOST_OUTCOME_TEMPLATE(class T)
  606. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_compatible_conversion<void, void, T, void>))
  607. constexpr basic_outcome(failure_type<T> &&o, exception_failure_tag /*unused*/ = exception_failure_tag()) noexcept(std::is_nothrow_constructible<exception_type, T>::value) // NOLINT
  608. : base(),
  609. _ptr(detail::extract_exception_from_failure<exception_type>(static_cast<failure_type<T> &&>(o)))
  610. {
  611. this->_state._status |= detail::status_have_exception;
  612. using namespace hooks;
  613. hook_outcome_copy_construction(this, o);
  614. }
  615. /*! AWAITING HUGO JSON CONVERSION TOOL
  616. SIGNATURE NOT RECOGNISED
  617. */
  618. BOOST_OUTCOME_TEMPLATE(class T, class U)
  619. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(!std::is_void<U>::value && predicate::template enable_compatible_conversion<void, T, U, void>))
  620. constexpr basic_outcome(failure_type<T, U> &&o) noexcept(std::is_nothrow_constructible<error_type, T>::value &&std::is_nothrow_constructible<exception_type, U>::value) // NOLINT
  621. : base{in_place_type<typename base::_error_type>, detail::extract_error_from_failure<error_type>(static_cast<failure_type<T, U> &&>(o))},
  622. _ptr(detail::extract_exception_from_failure<exception_type>(static_cast<failure_type<T, U> &&>(o)))
  623. {
  624. if(!o.has_error())
  625. {
  626. this->_state._status &= ~detail::status_have_error;
  627. }
  628. if(o.has_exception())
  629. {
  630. this->_state._status |= detail::status_have_exception;
  631. }
  632. using namespace hooks;
  633. hook_outcome_move_construction(this, static_cast<failure_type<T, U> &&>(o));
  634. }
  635. /*! AWAITING HUGO JSON CONVERSION TOOL
  636. SIGNATURE NOT RECOGNISED
  637. */
  638. using base::operator==;
  639. using base::operator!=;
  640. /*! AWAITING HUGO JSON CONVERSION TOOL
  641. SIGNATURE NOT RECOGNISED
  642. */
  643. BOOST_OUTCOME_TEMPLATE(class T, class U, class V, class W)
  644. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TEXPR(std::declval<detail::devoid<value_type>>() == std::declval<detail::devoid<T>>()), //
  645. BOOST_OUTCOME_TEXPR(std::declval<detail::devoid<error_type>>() == std::declval<detail::devoid<U>>()), //
  646. BOOST_OUTCOME_TEXPR(std::declval<detail::devoid<exception_type>>() == std::declval<detail::devoid<V>>()))
  647. constexpr bool operator==(const basic_outcome<T, U, V, W> &o) const noexcept( //
  648. noexcept(std::declval<detail::devoid<value_type>>() == std::declval<detail::devoid<T>>()) //
  649. && noexcept(std::declval<detail::devoid<error_type>>() == std::declval<detail::devoid<U>>()) //
  650. && noexcept(std::declval<detail::devoid<exception_type>>() == std::declval<detail::devoid<V>>()))
  651. {
  652. if((this->_state._status & detail::status_have_value) != 0 && (o._state._status & detail::status_have_value) != 0)
  653. {
  654. return this->_state._value == o._state._value; // NOLINT
  655. }
  656. if((this->_state._status & detail::status_have_error) != 0 && (o._state._status & detail::status_have_error) != 0 //
  657. && (this->_state._status & detail::status_have_exception) != 0 && (o._state._status & detail::status_have_exception) != 0)
  658. {
  659. return this->_error == o._error && this->_ptr == o._ptr;
  660. }
  661. if((this->_state._status & detail::status_have_error) != 0 && (o._state._status & detail::status_have_error) != 0)
  662. {
  663. return this->_error == o._error;
  664. }
  665. if((this->_state._status & detail::status_have_exception) != 0 && (o._state._status & detail::status_have_exception) != 0)
  666. {
  667. return this->_ptr == o._ptr;
  668. }
  669. return false;
  670. }
  671. /*! AWAITING HUGO JSON CONVERSION TOOL
  672. SIGNATURE NOT RECOGNISED
  673. */
  674. BOOST_OUTCOME_TEMPLATE(class T, class U)
  675. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TEXPR(std::declval<error_type>() == std::declval<T>()), //
  676. BOOST_OUTCOME_TEXPR(std::declval<exception_type>() == std::declval<U>()))
  677. constexpr bool operator==(const failure_type<T, U> &o) const noexcept( //
  678. noexcept(std::declval<error_type>() == std::declval<T>()) && noexcept(std::declval<exception_type>() == std::declval<U>()))
  679. {
  680. if((this->_state._status & detail::status_have_error) != 0 && (o._state._status & detail::status_have_error) != 0 //
  681. && (this->_state._status & detail::status_have_exception) != 0 && (o._state._status & detail::status_have_exception) != 0)
  682. {
  683. return this->_error == o.error() && this->_ptr == o.exception();
  684. }
  685. if((this->_state._status & detail::status_have_error) != 0 && (o._state._status & detail::status_have_error) != 0)
  686. {
  687. return this->_error == o.error();
  688. }
  689. if((this->_state._status & detail::status_have_exception) != 0 && (o._state._status & detail::status_have_exception) != 0)
  690. {
  691. return this->_ptr == o.exception();
  692. }
  693. return false;
  694. }
  695. /*! AWAITING HUGO JSON CONVERSION TOOL
  696. SIGNATURE NOT RECOGNISED
  697. */
  698. BOOST_OUTCOME_TEMPLATE(class T, class U, class V, class W)
  699. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TEXPR(std::declval<detail::devoid<value_type>>() != std::declval<detail::devoid<T>>()), //
  700. BOOST_OUTCOME_TEXPR(std::declval<detail::devoid<error_type>>() != std::declval<detail::devoid<U>>()), //
  701. BOOST_OUTCOME_TEXPR(std::declval<detail::devoid<exception_type>>() != std::declval<detail::devoid<V>>()))
  702. constexpr bool operator!=(const basic_outcome<T, U, V, W> &o) const noexcept( //
  703. noexcept(std::declval<detail::devoid<value_type>>() != std::declval<detail::devoid<T>>()) //
  704. && noexcept(std::declval<detail::devoid<error_type>>() != std::declval<detail::devoid<U>>()) //
  705. && noexcept(std::declval<detail::devoid<exception_type>>() != std::declval<detail::devoid<V>>()))
  706. {
  707. if((this->_state._status & detail::status_have_value) != 0 && (o._state._status & detail::status_have_value) != 0)
  708. {
  709. return this->_state._value != o._state._value; // NOLINT
  710. }
  711. if((this->_state._status & detail::status_have_error) != 0 && (o._state._status & detail::status_have_error) != 0 //
  712. && (this->_state._status & detail::status_have_exception) != 0 && (o._state._status & detail::status_have_exception) != 0)
  713. {
  714. return this->_error != o._error || this->_ptr != o._ptr;
  715. }
  716. if((this->_state._status & detail::status_have_error) != 0 && (o._state._status & detail::status_have_error) != 0)
  717. {
  718. return this->_error != o._error;
  719. }
  720. if((this->_state._status & detail::status_have_exception) != 0 && (o._state._status & detail::status_have_exception) != 0)
  721. {
  722. return this->_ptr != o._ptr;
  723. }
  724. return true;
  725. }
  726. /*! AWAITING HUGO JSON CONVERSION TOOL
  727. SIGNATURE NOT RECOGNISED
  728. */
  729. BOOST_OUTCOME_TEMPLATE(class T, class U)
  730. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TEXPR(std::declval<error_type>() != std::declval<T>()), //
  731. BOOST_OUTCOME_TEXPR(std::declval<exception_type>() != std::declval<U>()))
  732. constexpr bool operator!=(const failure_type<T, U> &o) const noexcept( //
  733. noexcept(std::declval<error_type>() == std::declval<T>()) && noexcept(std::declval<exception_type>() == std::declval<U>()))
  734. {
  735. if((this->_state._status & detail::status_have_error) != 0 && (o._state._status & detail::status_have_error) != 0 //
  736. && (this->_state._status & detail::status_have_exception) != 0 && (o._state._status & detail::status_have_exception) != 0)
  737. {
  738. return this->_error != o.error() || this->_ptr != o.exception();
  739. }
  740. if((this->_state._status & detail::status_have_error) != 0 && (o._state._status & detail::status_have_error) != 0)
  741. {
  742. return this->_error != o.error();
  743. }
  744. if((this->_state._status & detail::status_have_exception) != 0 && (o._state._status & detail::status_have_exception) != 0)
  745. {
  746. return this->_ptr != o.exception();
  747. }
  748. return true;
  749. }
  750. /*! AWAITING HUGO JSON CONVERSION TOOL
  751. SIGNATURE NOT RECOGNISED
  752. */
  753. void swap(basic_outcome &o) noexcept(detail::is_nothrow_swappable<value_type>::value &&std::is_nothrow_move_constructible<value_type>::value //
  754. &&detail::is_nothrow_swappable<error_type>::value &&std::is_nothrow_move_constructible<error_type>::value //
  755. &&detail::is_nothrow_swappable<exception_type>::value &&std::is_nothrow_move_constructible<exception_type>::value)
  756. {
  757. using std::swap;
  758. #ifndef BOOST_NO_EXCEPTIONS
  759. constexpr bool value_throws = !noexcept(this->_state.swap(o._state));
  760. constexpr bool error_throws = !noexcept(swap(this->_error, o._error));
  761. constexpr bool exception_throws = !noexcept(swap(this->_ptr, o._ptr));
  762. #ifdef _MSC_VER
  763. #pragma warning(push)
  764. #pragma warning(disable : 4127) // conditional expression is constant
  765. #endif
  766. // Do throwing swap first
  767. if((value_throws && !error_throws && !exception_throws) || (!value_throws && !error_throws && !exception_throws))
  768. {
  769. this->_state.swap(o._state);
  770. swap(this->_error, o._error);
  771. swap(this->_ptr, o._ptr);
  772. }
  773. else if(!value_throws && !error_throws && exception_throws)
  774. {
  775. swap(this->_ptr, o._ptr);
  776. this->_state.swap(o._state);
  777. swap(this->_error, o._error);
  778. }
  779. else if(!value_throws && error_throws && !exception_throws)
  780. {
  781. swap(this->_error, o._error);
  782. this->_state.swap(o._state);
  783. swap(this->_ptr, o._ptr);
  784. }
  785. else
  786. {
  787. // Two or more can throw
  788. this->_state.swap(o._state);
  789. bool exception_threw = false;
  790. try
  791. {
  792. swap(this->_error, o._error);
  793. exception_threw = true;
  794. swap(this->_ptr, o._ptr);
  795. }
  796. catch(...)
  797. {
  798. // Try to put it back
  799. bool error_is_mine = !exception_threw;
  800. try
  801. {
  802. if(exception_threw)
  803. {
  804. swap(this->_error, o._error);
  805. error_is_mine = true;
  806. }
  807. this->_state.swap(o._state);
  808. // If that succeeded, continue by rethrowing the exception
  809. }
  810. catch(...)
  811. {
  812. if(error_is_mine)
  813. {
  814. try
  815. {
  816. swap(this->_error, o._error);
  817. error_is_mine = false;
  818. }
  819. catch(...)
  820. {
  821. }
  822. }
  823. // Prevent has_value() == has_error() or has_value() == has_exception()
  824. auto check = [](basic_outcome *t, bool set_error) {
  825. if(t->has_value() && (t->has_error() || t->has_exception()))
  826. {
  827. // We know the value swapped and is now set, so clear error and exception
  828. t->_state._status &= ~(detail::status_have_error | detail::status_have_exception);
  829. }
  830. if(!t->has_value() && !(t->has_error() || t->has_exception()))
  831. {
  832. // We know the value swapped and is now unset, so either set exception or error
  833. if(set_error)
  834. {
  835. t->_state._status |= detail::status_have_error;
  836. }
  837. else
  838. {
  839. t->_state._status |= detail::status_have_exception;
  840. }
  841. }
  842. };
  843. // If my value is unset and error is not mine, set error
  844. check(this, !error_is_mine);
  845. // If other's value is unset and error is not mine, set error
  846. check(&o, !error_is_mine);
  847. }
  848. throw;
  849. }
  850. }
  851. #ifdef _MSC_VER
  852. #pragma warning(pop)
  853. #endif
  854. #else
  855. this->_state.swap(o._state);
  856. swap(this->_error, o._error);
  857. swap(this->_ptr, o._ptr);
  858. #endif
  859. }
  860. /*! AWAITING HUGO JSON CONVERSION TOOL
  861. SIGNATURE NOT RECOGNISED
  862. */
  863. failure_type<error_type, exception_type> as_failure() const &
  864. {
  865. if(this->has_error() && this->has_exception())
  866. {
  867. return failure_type<error_type, exception_type>(this->assume_error(), this->assume_exception());
  868. }
  869. if(this->has_exception())
  870. {
  871. return failure_type<error_type, exception_type>(in_place_type<exception_type>, this->assume_exception());
  872. }
  873. return failure_type<error_type, exception_type>(in_place_type<error_type>, this->assume_error());
  874. }
  875. /*! AWAITING HUGO JSON CONVERSION TOOL
  876. SIGNATURE NOT RECOGNISED
  877. */
  878. failure_type<error_type, exception_type> as_failure() &&
  879. {
  880. if(this->has_error() && this->has_exception())
  881. {
  882. return failure_type<error_type, exception_type>(static_cast<S &&>(this->assume_error()), static_cast<P &&>(this->assume_exception()));
  883. }
  884. if(this->has_exception())
  885. {
  886. return failure_type<error_type, exception_type>(in_place_type<exception_type>, static_cast<P &&>(this->assume_exception()));
  887. }
  888. return failure_type<error_type, exception_type>(in_place_type<error_type>, static_cast<S &&>(this->assume_error()));
  889. }
  890. };
  891. /*! AWAITING HUGO JSON CONVERSION TOOL
  892. SIGNATURE NOT RECOGNISED
  893. */
  894. BOOST_OUTCOME_TEMPLATE(class T, class U, class V, //
  895. class R, class S, class P, class N)
  896. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TEXPR(std::declval<basic_outcome<R, S, P, N>>() == std::declval<basic_result<T, U, V>>()))
  897. constexpr inline bool operator==(const basic_result<T, U, V> &a, const basic_outcome<R, S, P, N> &b) noexcept( //
  898. noexcept(std::declval<basic_outcome<R, S, P, N>>() == std::declval<basic_result<T, U, V>>()))
  899. {
  900. return b == a;
  901. }
  902. /*! AWAITING HUGO JSON CONVERSION TOOL
  903. SIGNATURE NOT RECOGNISED
  904. */
  905. BOOST_OUTCOME_TEMPLATE(class T, class U, class V, //
  906. class R, class S, class P, class N)
  907. BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TEXPR(std::declval<basic_outcome<R, S, P, N>>() != std::declval<basic_result<T, U, V>>()))
  908. constexpr inline bool operator!=(const basic_result<T, U, V> &a, const basic_outcome<R, S, P, N> &b) noexcept( //
  909. noexcept(std::declval<basic_outcome<R, S, P, N>>() != std::declval<basic_result<T, U, V>>()))
  910. {
  911. return b != a;
  912. }
  913. /*! AWAITING HUGO JSON CONVERSION TOOL
  914. SIGNATURE NOT RECOGNISED
  915. */
  916. 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)))
  917. {
  918. a.swap(b);
  919. }
  920. namespace hooks
  921. {
  922. /*! AWAITING HUGO JSON CONVERSION TOOL
  923. SIGNATURE NOT RECOGNISED
  924. */
  925. template <class R, class S, class P, class NoValuePolicy, class U> constexpr inline void override_outcome_exception(basic_outcome<R, S, P, NoValuePolicy> *o, U &&v) noexcept
  926. {
  927. o->_ptr = static_cast<U &&>(v); // NOLINT
  928. o->_state._status |= detail::status_have_exception;
  929. }
  930. } // namespace hooks
  931. BOOST_OUTCOME_V2_NAMESPACE_END
  932. #ifdef __clang__
  933. #pragma clang diagnostic pop
  934. #endif
  935. #include "detail/basic_outcome_exception_observers_impl.hpp"
  936. #if !defined(NDEBUG)
  937. BOOST_OUTCOME_V2_NAMESPACE_BEGIN
  938. // Check is trivial in all ways except default constructibility and standard layout
  939. // static_assert(std::is_trivial<basic_outcome<int, long, double, policy::all_narrow>>::value, "outcome<int> is not trivial!");
  940. // static_assert(std::is_trivially_default_constructible<basic_outcome<int, long, double, policy::all_narrow>>::value, "outcome<int> is not trivially default constructible!");
  941. static_assert(std::is_trivially_copyable<basic_outcome<int, long, double, policy::all_narrow>>::value, "outcome<int> is not trivially copyable!");
  942. static_assert(std::is_trivially_assignable<basic_outcome<int, long, double, policy::all_narrow>, basic_outcome<int, long, double, policy::all_narrow>>::value, "outcome<int> is not trivially assignable!");
  943. static_assert(std::is_trivially_destructible<basic_outcome<int, long, double, policy::all_narrow>>::value, "outcome<int> is not trivially destructible!");
  944. static_assert(std::is_trivially_copy_constructible<basic_outcome<int, long, double, policy::all_narrow>>::value, "outcome<int> is not trivially copy constructible!");
  945. static_assert(std::is_trivially_move_constructible<basic_outcome<int, long, double, policy::all_narrow>>::value, "outcome<int> is not trivially move constructible!");
  946. static_assert(std::is_trivially_copy_assignable<basic_outcome<int, long, double, policy::all_narrow>>::value, "outcome<int> is not trivially copy assignable!");
  947. static_assert(std::is_trivially_move_assignable<basic_outcome<int, long, double, policy::all_narrow>>::value, "outcome<int> is not trivially move assignable!");
  948. // Can't be standard layout as non-static member data is defined in more than one inherited class
  949. // static_assert(std::is_standard_layout<basic_outcome<int, long, double, policy::all_narrow>>::value, "outcome<int> is not a standard layout type!");
  950. BOOST_OUTCOME_V2_NAMESPACE_END
  951. #endif
  952. #endif