File indexing completed on 2025-12-16 09:59:13
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 #ifndef BOOST_OUTCOME_BASIC_RESULT_HPP
0032 #define BOOST_OUTCOME_BASIC_RESULT_HPP
0033
0034 #include "config.hpp"
0035 #include "convert.hpp"
0036 #include "detail/basic_result_final.hpp"
0037 #include "outcome_gdb.h"
0038
0039 #include "policy/all_narrow.hpp"
0040 #include "policy/terminate.hpp"
0041
0042 #ifdef __clang__
0043 #pragma clang diagnostic push
0044 #pragma clang diagnostic ignored "-Wdocumentation"
0045 #endif
0046
0047 #if defined(_MSC_VER) && !defined(__clang__)
0048 #pragma warning(push)
0049 #pragma warning(disable: 6287)
0050 #endif
0051
0052 BOOST_OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
0053
0054 template <class R, class S, class NoValuePolicy>
0055 class basic_result;
0056
0057 namespace detail
0058 {
0059
0060 template <class value_type, class error_type> struct result_predicates
0061 {
0062
0063 static constexpr bool implicit_constructors_enabled =
0064 !(trait::is_error_type<std::decay_t<value_type>>::value &&
0065 trait::is_error_type<std::decay_t<error_type>>::value)
0066 && ((!detail::is_implicitly_constructible<value_type, error_type> &&
0067 !detail::is_implicitly_constructible<error_type, value_type>)
0068 || (trait::is_error_type<std::decay_t<error_type>>::value
0069 && !detail::is_implicitly_constructible<error_type, value_type>
0070 && std::is_integral<value_type>::value));
0071
0072
0073 template <class T>
0074 static constexpr bool enable_value_converting_constructor =
0075 implicit_constructors_enabled
0076 && !is_in_place_type_t<std::decay_t<T>>::value
0077 && !trait::is_error_type_enum<error_type, std::decay_t<T>>::value
0078 && ((detail::is_implicitly_constructible<value_type, T> && !detail::is_implicitly_constructible<error_type, T>)
0079 || (std::is_same<value_type, std::decay_t<T>>::value
0080 && detail::is_implicitly_constructible<value_type, T>) );
0081
0082
0083
0084 template <class T>
0085 static constexpr bool enable_error_converting_constructor =
0086 implicit_constructors_enabled
0087 && !is_in_place_type_t<std::decay_t<T>>::value
0088 && !trait::is_error_type_enum<error_type, std::decay_t<T>>::value
0089 && ((!detail::is_implicitly_constructible<value_type, T> && detail::is_implicitly_constructible<error_type, T>)
0090 || (std::is_same<error_type, std::decay_t<T>>::value
0091 && detail::is_implicitly_constructible<error_type, T>) );
0092
0093
0094 template <class ErrorCondEnum>
0095 static constexpr bool enable_error_condition_converting_constructor =
0096 !is_in_place_type_t<std::decay_t<ErrorCondEnum>>::value
0097 && trait::is_error_type_enum<error_type, std::decay_t<ErrorCondEnum>>::value
0098 ;
0099
0100
0101
0102
0103
0104 template <class T, class U, class V>
0105 static constexpr bool enable_compatible_conversion =
0106 (std::is_void<T>::value ||
0107 detail::is_explicitly_constructible<value_type, typename basic_result<T, U, V>::value_type>)
0108 &&(std::is_void<U>::value ||
0109 detail::is_explicitly_constructible<error_type, typename basic_result<T, U, V>::error_type>)
0110 ;
0111
0112
0113 template <class T, class U, class V>
0114 static constexpr bool enable_make_error_code_compatible_conversion =
0115 trait::is_error_code_available<std::decay_t<error_type>>::value
0116 && !enable_compatible_conversion<T, U, V>
0117 && (std::is_void<T>::value ||
0118 detail::is_explicitly_constructible<value_type, typename basic_result<T, U, V>::value_type>)
0119 &&detail::is_explicitly_constructible<error_type,
0120 typename trait::is_error_code_available<U>::type>;
0121
0122
0123 template <class T, class U, class V>
0124 static constexpr bool enable_make_exception_ptr_compatible_conversion =
0125 trait::is_exception_ptr_available<std::decay_t<error_type>>::value
0126 && !enable_compatible_conversion<T, U, V>
0127 && (std::is_void<T>::value ||
0128 detail::is_explicitly_constructible<value_type, typename basic_result<T, U, V>::value_type>)
0129 &&detail::is_explicitly_constructible<error_type, typename trait::is_exception_ptr_available<U>::type>;
0130
0131
0132
0133 struct disable_inplace_value_error_constructor;
0134 template <class... Args>
0135 using choose_inplace_value_error_constructor = std::conditional_t<
0136 detail::is_constructible<value_type, Args...> && detail::is_constructible<error_type, Args...>,
0137 disable_inplace_value_error_constructor,
0138 std::conditional_t<
0139 detail::is_constructible<value_type, Args...>,
0140 value_type,
0141 std::conditional_t<
0142 detail::is_constructible<error_type, Args...>,
0143 error_type,
0144 disable_inplace_value_error_constructor>>>;
0145 template <class... Args>
0146 static constexpr bool enable_inplace_value_error_constructor =
0147 implicit_constructors_enabled
0148 && !std::is_same<choose_inplace_value_error_constructor<Args...>, disable_inplace_value_error_constructor>::value;
0149 };
0150
0151 template <class T, class U> constexpr inline const U &extract_value_from_success(const success_type<U> &v)
0152 {
0153 return v.value();
0154 }
0155 template <class T, class U> constexpr inline U &&extract_value_from_success(success_type<U> &&v)
0156 {
0157 return static_cast<success_type<U> &&>(v).value();
0158 }
0159 template <class T> constexpr inline T extract_value_from_success(const success_type<void> & )
0160 {
0161 return T{};
0162 }
0163
0164 template <class T, class U, class V> constexpr inline const U &extract_error_from_failure(const failure_type<U, V> &v)
0165 {
0166 return v.error();
0167 }
0168 template <class T, class U, class V> constexpr inline U &&extract_error_from_failure(failure_type<U, V> &&v)
0169 {
0170 return static_cast<failure_type<U, V> &&>(v).error();
0171 }
0172 template <class T, class V> constexpr inline T extract_error_from_failure(const failure_type<void, V> & )
0173 {
0174 return T{};
0175 }
0176
0177 template <class T> struct is_basic_result
0178 {
0179 static constexpr bool value = false;
0180 };
0181 template <class R, class S, class T> struct is_basic_result<basic_result<R, S, T>>
0182 {
0183 static constexpr bool value = true;
0184 };
0185 }
0186
0187
0188
0189
0190 template <class T> using is_basic_result = detail::is_basic_result<std::decay_t<T>>;
0191
0192
0193
0194 template <class T> static constexpr bool is_basic_result_v = detail::is_basic_result<std::decay_t<T>>::value;
0195
0196 namespace concepts
0197 {
0198 #if defined(__cpp_concepts)
0199
0200
0201
0202 template <class U>
0203 concept BOOST_OUTCOME_GCC6_CONCEPT_BOOL basic_result =
0204 BOOST_OUTCOME_V2_NAMESPACE::is_basic_result<U>::value ||
0205 (requires(U v) { BOOST_OUTCOME_V2_NAMESPACE::basic_result<typename U::value_type, typename U::error_type, typename U::no_value_policy_type>(v); } &&
0206 detail::convertible<U, BOOST_OUTCOME_V2_NAMESPACE::basic_result<typename U::value_type, typename U::error_type, typename U::no_value_policy_type>> &&
0207 detail::base_of<BOOST_OUTCOME_V2_NAMESPACE::basic_result<typename U::value_type, typename U::error_type, typename U::no_value_policy_type>, U>);
0208 #else
0209 namespace detail
0210 {
0211 inline no_match match_basic_result(...);
0212 template <class R, class S, class NVP, class T,
0213 typename = typename T::value_type,
0214 typename = typename T::error_type,
0215 typename = typename T::no_value_policy_type,
0216 typename std::enable_if_t<std::is_convertible<T, BOOST_OUTCOME_V2_NAMESPACE::basic_result<R, S, NVP>>::value &&
0217 std::is_base_of<BOOST_OUTCOME_V2_NAMESPACE::basic_result<R, S, NVP>, T>::value,
0218 bool> = true>
0219 inline BOOST_OUTCOME_V2_NAMESPACE::basic_result<R, S, NVP> match_basic_result(BOOST_OUTCOME_V2_NAMESPACE::basic_result<R, S, NVP> &&, T &&);
0220
0221 template <class U>
0222 static constexpr bool basic_result = BOOST_OUTCOME_V2_NAMESPACE::is_basic_result<U>::value ||
0223 !std::is_same<no_match, decltype(match_basic_result(std::declval<BOOST_OUTCOME_V2_NAMESPACE::detail::devoid<U>>(),
0224 std::declval<BOOST_OUTCOME_V2_NAMESPACE::detail::devoid<U>>()))>::value;
0225 }
0226
0227
0228
0229 template <class U> static constexpr bool basic_result = detail::basic_result<U>;
0230 #endif
0231 }
0232
0233
0234
0235
0236 namespace hooks
0237 {
0238
0239
0240
0241 template <class R, class S, class NoValuePolicy> constexpr inline uint16_t spare_storage(const detail::basic_result_storage<R, S, NoValuePolicy> *r) noexcept
0242 {
0243 return r->_state._status.spare_storage_value;
0244 }
0245
0246
0247
0248 template <class R, class S, class NoValuePolicy>
0249 constexpr inline void set_spare_storage(detail::basic_result_storage<R, S, NoValuePolicy> *r, uint16_t v) noexcept
0250 {
0251 r->_state._status.spare_storage_value = v;
0252 }
0253 }
0254
0255
0256
0257
0258 template <class R, class S, class NoValuePolicy>
0259 class BOOST_OUTCOME_NODISCARD basic_result : public detail::basic_result_final<R, S, NoValuePolicy>
0260 {
0261 static_assert(trait::type_can_be_used_in_basic_result<R>, "The type R cannot be used in a basic_result");
0262 static_assert(trait::type_can_be_used_in_basic_result<S>, "The type S cannot be used in a basic_result");
0263
0264 using base = detail::basic_result_final<R, S, NoValuePolicy>;
0265
0266 struct implicit_constructors_disabled_tag
0267 {
0268 };
0269 struct value_converting_constructor_tag
0270 {
0271 };
0272 struct error_converting_constructor_tag
0273 {
0274 };
0275 struct error_condition_converting_constructor_tag
0276 {
0277 };
0278 struct explicit_valueornone_converting_constructor_tag
0279 {
0280 };
0281 struct explicit_valueorerror_converting_constructor_tag
0282 {
0283 };
0284 struct explicit_compatible_copy_conversion_tag
0285 {
0286 };
0287 struct explicit_compatible_move_conversion_tag
0288 {
0289 };
0290 struct explicit_make_error_code_compatible_copy_conversion_tag
0291 {
0292 };
0293 struct explicit_make_error_code_compatible_move_conversion_tag
0294 {
0295 };
0296 struct explicit_make_exception_ptr_compatible_copy_conversion_tag
0297 {
0298 };
0299 struct explicit_make_exception_ptr_compatible_move_conversion_tag
0300 {
0301 };
0302
0303 public:
0304 using value_type = R;
0305 using error_type = S;
0306 using no_value_policy_type = NoValuePolicy;
0307
0308 using value_type_if_enabled = typename base::_value_type;
0309 using error_type_if_enabled = typename base::_error_type;
0310
0311 template <class T, class U = S, class V = NoValuePolicy> using rebind = basic_result<T, U, V>;
0312
0313 protected:
0314
0315 struct predicate
0316 {
0317 using base = detail::result_predicates<value_type, error_type>;
0318
0319
0320 static constexpr bool constructors_enabled = !std::is_same<std::decay_t<value_type>, std::decay_t<error_type>>::value;
0321
0322
0323 static constexpr bool implicit_constructors_enabled = constructors_enabled && base::implicit_constructors_enabled;
0324
0325
0326 template <class T>
0327 static constexpr bool enable_value_converting_constructor =
0328 constructors_enabled
0329 && !std::is_same<std::decay_t<T>, basic_result>::value
0330 && base::template enable_value_converting_constructor<T>;
0331
0332
0333 template <class T>
0334 static constexpr bool enable_error_converting_constructor =
0335 constructors_enabled
0336 && !std::is_same<std::decay_t<T>, basic_result>::value
0337 && base::template enable_error_converting_constructor<T>;
0338
0339
0340 template <class ErrorCondEnum>
0341 static constexpr bool enable_error_condition_converting_constructor =
0342 constructors_enabled
0343 && !std::is_same<std::decay_t<ErrorCondEnum>, basic_result>::value
0344 && base::template enable_error_condition_converting_constructor<ErrorCondEnum>;
0345
0346
0347 template <class T, class U, class V>
0348 static constexpr bool enable_compatible_conversion =
0349 constructors_enabled
0350 && !std::is_same<basic_result<T, U, V>, basic_result>::value
0351 && base::template enable_compatible_conversion<T, U, V>;
0352
0353
0354 template <class T, class U, class V>
0355 static constexpr bool enable_make_error_code_compatible_conversion =
0356 constructors_enabled
0357 && !std::is_same<basic_result<T, U, V>, basic_result>::value
0358 && base::template enable_make_error_code_compatible_conversion<T, U, V>;
0359
0360
0361 template <class T, class U, class V>
0362 static constexpr bool enable_make_exception_ptr_compatible_conversion =
0363 constructors_enabled
0364 && !std::is_same<basic_result<T, U, V>, basic_result>::value
0365 && base::template enable_make_exception_ptr_compatible_conversion<T, U, V>;
0366
0367
0368 template <class... Args>
0369 static constexpr bool enable_inplace_value_constructor =
0370 constructors_enabled
0371 && (std::is_void<value_type>::value
0372 || detail::is_constructible<value_type, Args...>);
0373
0374
0375 template <class... Args>
0376 static constexpr bool enable_inplace_error_constructor =
0377 constructors_enabled
0378 && (std::is_void<error_type>::value
0379 || detail::is_constructible<error_type, Args...>);
0380
0381
0382 template <class... Args>
0383 static constexpr bool enable_inplace_value_error_constructor =
0384 constructors_enabled
0385 && base::template enable_inplace_value_error_constructor<Args...>;
0386 template <class... Args> using choose_inplace_value_error_constructor = typename base::template choose_inplace_value_error_constructor<Args...>;
0387 };
0388
0389 public:
0390
0391
0392
0393 basic_result() = delete;
0394
0395
0396
0397 basic_result(basic_result && ) = default;
0398
0399
0400
0401 basic_result(const basic_result & ) = default;
0402
0403
0404
0405 basic_result &operator=(basic_result && ) = default;
0406
0407
0408
0409 basic_result &operator=(const basic_result & ) = default;
0410 ~basic_result() = default;
0411
0412
0413
0414
0415 BOOST_OUTCOME_TEMPLATE(class Arg, class... Args)
0416 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(!predicate::constructors_enabled && (sizeof...(Args) >= 0)))
0417 basic_result(Arg && , Args &&...) = delete;
0418
0419
0420
0421
0422 BOOST_OUTCOME_TEMPLATE(class T)
0423 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED((predicate::constructors_enabled && !predicate::implicit_constructors_enabled
0424 && (detail::is_implicitly_constructible<value_type, T> || detail::is_implicitly_constructible<error_type, T>) )))
0425 basic_result(T && , implicit_constructors_disabled_tag = implicit_constructors_disabled_tag()) =
0426 delete;
0427
0428
0429
0430
0431 BOOST_OUTCOME_TEMPLATE(class T)
0432 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_value_converting_constructor<T>))
0433 constexpr basic_result(T &&t, value_converting_constructor_tag = value_converting_constructor_tag()) noexcept(
0434 detail::is_nothrow_constructible<value_type, T>)
0435 : base{in_place_type<typename base::value_type>, static_cast<T &&>(t)}
0436 {
0437 no_value_policy_type::on_result_construction(this, static_cast<T &&>(t));
0438 }
0439
0440
0441
0442 BOOST_OUTCOME_TEMPLATE(class T)
0443 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_error_converting_constructor<T>))
0444 constexpr basic_result(T &&t, error_converting_constructor_tag = error_converting_constructor_tag()) noexcept(
0445 detail::is_nothrow_constructible<error_type, T>)
0446 : base{in_place_type<typename base::error_type>, static_cast<T &&>(t)}
0447 {
0448 no_value_policy_type::on_result_construction(this, static_cast<T &&>(t));
0449 }
0450
0451
0452
0453 BOOST_OUTCOME_TEMPLATE(class ErrorCondEnum)
0454 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TEXPR(error_type(make_error_code(ErrorCondEnum()))),
0455 BOOST_OUTCOME_TPRED(predicate::template enable_error_condition_converting_constructor<ErrorCondEnum>))
0456 constexpr basic_result(ErrorCondEnum &&t, error_condition_converting_constructor_tag = error_condition_converting_constructor_tag()) noexcept(
0457 noexcept(error_type(make_error_code(static_cast<ErrorCondEnum &&>(t)))))
0458 : base{in_place_type<typename base::error_type>, make_error_code(t)}
0459 {
0460 no_value_policy_type::on_result_construction(this, static_cast<ErrorCondEnum &&>(t));
0461 }
0462
0463
0464
0465
0466 BOOST_OUTCOME_TEMPLATE(class T)
0467 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(convert::value_or_error<basic_result, std::decay_t<T>>::enable_result_inputs || !concepts::basic_result<T>),
0468 BOOST_OUTCOME_TEXPR(convert::value_or_error<basic_result, std::decay_t<T>>{}(std::declval<T>())))
0469 constexpr explicit basic_result(T &&o,
0470 explicit_valueorerror_converting_constructor_tag = explicit_valueorerror_converting_constructor_tag())
0471 : basic_result{convert::value_or_error<basic_result, std::decay_t<T>>{}(static_cast<T &&>(o))}
0472 {
0473 }
0474
0475
0476
0477 BOOST_OUTCOME_TEMPLATE(class T, class U, class V)
0478 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_compatible_conversion<T, U, V>))
0479 constexpr explicit basic_result(
0480 const basic_result<T, U, V> &o,
0481 explicit_compatible_copy_conversion_tag = explicit_compatible_copy_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
0482 detail::is_nothrow_constructible<error_type, U>)
0483 : base{typename base::compatible_conversion_tag(), o}
0484 {
0485 no_value_policy_type::on_result_copy_construction(this, o);
0486 }
0487
0488
0489
0490 BOOST_OUTCOME_TEMPLATE(class T, class U, class V)
0491 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_compatible_conversion<T, U, V>))
0492 constexpr explicit basic_result(
0493 basic_result<T, U, V> &&o,
0494 explicit_compatible_move_conversion_tag = explicit_compatible_move_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
0495 detail::is_nothrow_constructible<error_type, U>)
0496 : base{typename base::compatible_conversion_tag(), static_cast<basic_result<T, U, V> &&>(o)}
0497 {
0498 no_value_policy_type::on_result_move_construction(this, static_cast<basic_result<T, U, V> &&>(o));
0499 }
0500
0501
0502
0503 BOOST_OUTCOME_TEMPLATE(class T, class U, class V)
0504 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_make_error_code_compatible_conversion<T, U, V>))
0505 constexpr explicit basic_result(const basic_result<T, U, V> &o,
0506 explicit_make_error_code_compatible_copy_conversion_tag =
0507 explicit_make_error_code_compatible_copy_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
0508 noexcept(make_error_code(std::declval<U>())))
0509 : base{typename base::make_error_code_compatible_conversion_tag(), o}
0510 {
0511 no_value_policy_type::on_result_copy_construction(this, o);
0512 }
0513
0514
0515
0516 BOOST_OUTCOME_TEMPLATE(class T, class U, class V)
0517 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_make_error_code_compatible_conversion<T, U, V>))
0518 constexpr explicit basic_result(basic_result<T, U, V> &&o,
0519 explicit_make_error_code_compatible_move_conversion_tag =
0520 explicit_make_error_code_compatible_move_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
0521 noexcept(make_error_code(std::declval<U>())))
0522 : base{typename base::make_error_code_compatible_conversion_tag(), static_cast<basic_result<T, U, V> &&>(o)}
0523 {
0524 no_value_policy_type::on_result_move_construction(this, static_cast<basic_result<T, U, V> &&>(o));
0525 }
0526
0527
0528
0529 BOOST_OUTCOME_TEMPLATE(class T, class U, class V)
0530 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_make_exception_ptr_compatible_conversion<T, U, V>))
0531 constexpr explicit basic_result(const basic_result<T, U, V> &o,
0532 explicit_make_exception_ptr_compatible_copy_conversion_tag =
0533 explicit_make_exception_ptr_compatible_copy_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
0534 noexcept(make_exception_ptr(std::declval<U>())))
0535 : base{typename base::make_exception_ptr_compatible_conversion_tag(), o}
0536 {
0537 no_value_policy_type::on_result_copy_construction(this, o);
0538 }
0539
0540
0541
0542 BOOST_OUTCOME_TEMPLATE(class T, class U, class V)
0543 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_make_exception_ptr_compatible_conversion<T, U, V>))
0544 constexpr explicit basic_result(basic_result<T, U, V> &&o,
0545 explicit_make_exception_ptr_compatible_move_conversion_tag =
0546 explicit_make_exception_ptr_compatible_move_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&
0547 noexcept(make_exception_ptr(std::declval<U>())))
0548 : base{typename base::make_exception_ptr_compatible_conversion_tag(), static_cast<basic_result<T, U, V> &&>(o)}
0549 {
0550 no_value_policy_type::on_result_move_construction(this, static_cast<basic_result<T, U, V> &&>(o));
0551 }
0552
0553
0554
0555
0556 BOOST_OUTCOME_TEMPLATE(class... Args)
0557 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_inplace_value_constructor<Args...>))
0558 constexpr explicit basic_result(in_place_type_t<value_type_if_enabled> _, Args &&...args) noexcept(detail::is_nothrow_constructible<value_type, Args...>)
0559 : base{_, static_cast<Args &&>(args)...}
0560 {
0561 no_value_policy_type::on_result_in_place_construction(this, in_place_type<value_type>, static_cast<Args &&>(args)...);
0562 }
0563
0564
0565
0566 BOOST_OUTCOME_TEMPLATE(class U, class... Args)
0567 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_inplace_value_constructor<std::initializer_list<U>, Args...>))
0568 constexpr explicit basic_result(in_place_type_t<value_type_if_enabled> _, std::initializer_list<U> il,
0569 Args &&...args) noexcept(detail::is_nothrow_constructible<value_type, std::initializer_list<U>, Args...>)
0570 : base{_, il, static_cast<Args &&>(args)...}
0571 {
0572 no_value_policy_type::on_result_in_place_construction(this, in_place_type<value_type>, il, static_cast<Args &&>(args)...);
0573 }
0574
0575
0576
0577 BOOST_OUTCOME_TEMPLATE(class... Args)
0578 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_inplace_error_constructor<Args...>))
0579 constexpr explicit basic_result(in_place_type_t<error_type_if_enabled> _, Args &&...args) noexcept(detail::is_nothrow_constructible<error_type, Args...>)
0580 : base{_, static_cast<Args &&>(args)...}
0581 {
0582 no_value_policy_type::on_result_in_place_construction(this, in_place_type<error_type>, static_cast<Args &&>(args)...);
0583 }
0584
0585
0586
0587 BOOST_OUTCOME_TEMPLATE(class U, class... Args)
0588 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_inplace_error_constructor<std::initializer_list<U>, Args...>))
0589 constexpr explicit basic_result(in_place_type_t<error_type_if_enabled> _, std::initializer_list<U> il,
0590 Args &&...args) noexcept(detail::is_nothrow_constructible<error_type, std::initializer_list<U>, Args...>)
0591 : base{_, il, static_cast<Args &&>(args)...}
0592 {
0593 no_value_policy_type::on_result_in_place_construction(this, in_place_type<error_type>, il, static_cast<Args &&>(args)...);
0594 }
0595
0596
0597
0598 BOOST_OUTCOME_TEMPLATE(class A1, class A2, class... Args)
0599 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_inplace_value_error_constructor<A1, A2, Args...>))
0600 constexpr basic_result(A1 &&a1, A2 &&a2, Args &&...args) noexcept(noexcept(
0601 typename predicate::template choose_inplace_value_error_constructor<A1, A2, Args...>(std::declval<A1>(), std::declval<A2>(), std::declval<Args>()...)))
0602 : basic_result(in_place_type<typename predicate::template choose_inplace_value_error_constructor<A1, A2, Args...>>, static_cast<A1 &&>(a1),
0603 static_cast<A2 &&>(a2), static_cast<Args &&>(args)...)
0604 {
0605 }
0606
0607
0608
0609
0610 constexpr basic_result(const success_type<void> &o) noexcept(std::is_nothrow_default_constructible<value_type>::value)
0611 : base{in_place_type<value_type_if_enabled>}
0612 {
0613 hooks::set_spare_storage(this, o.spare_storage());
0614 no_value_policy_type::on_result_copy_construction(this, o);
0615 }
0616
0617
0618
0619 BOOST_OUTCOME_TEMPLATE(class T)
0620 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_compatible_conversion<T, void, void>))
0621 constexpr basic_result(const success_type<T> &o) noexcept(detail::is_nothrow_constructible<value_type, T>)
0622 : base{in_place_type<value_type_if_enabled>, detail::extract_value_from_success<value_type>(o)}
0623 {
0624 hooks::set_spare_storage(this, o.spare_storage());
0625 no_value_policy_type::on_result_copy_construction(this, o);
0626 }
0627
0628
0629
0630 BOOST_OUTCOME_TEMPLATE(class T)
0631 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_compatible_conversion<T, void, void>))
0632 constexpr basic_result(success_type<T> &&o) noexcept(detail::is_nothrow_constructible<value_type, T>)
0633 : base{in_place_type<value_type_if_enabled>, detail::extract_value_from_success<value_type>(static_cast<success_type<T> &&>(o))}
0634 {
0635 hooks::set_spare_storage(this, o.spare_storage());
0636 no_value_policy_type::on_result_move_construction(this, static_cast<success_type<T> &&>(o));
0637 }
0638
0639
0640
0641 BOOST_OUTCOME_TEMPLATE(class T)
0642 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_compatible_conversion<void, T, void>))
0643 constexpr basic_result(const failure_type<T> &o, explicit_compatible_copy_conversion_tag = explicit_compatible_copy_conversion_tag()) noexcept(
0644 detail::is_nothrow_constructible<error_type, T>)
0645 : base{in_place_type<error_type_if_enabled>, detail::extract_error_from_failure<error_type>(o)}
0646 {
0647 hooks::set_spare_storage(this, o.spare_storage());
0648 no_value_policy_type::on_result_copy_construction(this, o);
0649 }
0650
0651
0652
0653 BOOST_OUTCOME_TEMPLATE(class T)
0654 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_compatible_conversion<void, T, void>))
0655 constexpr basic_result(failure_type<T> &&o, explicit_compatible_move_conversion_tag = explicit_compatible_move_conversion_tag()) noexcept(
0656 detail::is_nothrow_constructible<error_type, T>)
0657 : base{in_place_type<error_type_if_enabled>, detail::extract_error_from_failure<error_type>(static_cast<failure_type<T> &&>(o))}
0658 {
0659 hooks::set_spare_storage(this, o.spare_storage());
0660 no_value_policy_type::on_result_move_construction(this, static_cast<failure_type<T> &&>(o));
0661 }
0662
0663
0664
0665 BOOST_OUTCOME_TEMPLATE(class T)
0666 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_make_error_code_compatible_conversion<void, T, void>))
0667 constexpr basic_result(const failure_type<T> &o,
0668 explicit_make_error_code_compatible_copy_conversion_tag =
0669 explicit_make_error_code_compatible_copy_conversion_tag()) noexcept(noexcept(make_error_code(std::declval<T>())))
0670 : base{in_place_type<error_type_if_enabled>, make_error_code(detail::extract_error_from_failure<error_type>(o))}
0671 {
0672 hooks::set_spare_storage(this, o.spare_storage());
0673 no_value_policy_type::on_result_copy_construction(this, o);
0674 }
0675
0676
0677
0678 BOOST_OUTCOME_TEMPLATE(class T)
0679 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_make_error_code_compatible_conversion<void, T, void>))
0680 constexpr basic_result(failure_type<T> &&o,
0681 explicit_make_error_code_compatible_move_conversion_tag =
0682 explicit_make_error_code_compatible_move_conversion_tag()) noexcept(noexcept(make_error_code(std::declval<T>())))
0683 : base{in_place_type<error_type_if_enabled>, make_error_code(detail::extract_error_from_failure<error_type>(static_cast<failure_type<T> &&>(o)))}
0684 {
0685 hooks::set_spare_storage(this, o.spare_storage());
0686 no_value_policy_type::on_result_move_construction(this, static_cast<failure_type<T> &&>(o));
0687 }
0688
0689
0690
0691 BOOST_OUTCOME_TEMPLATE(class T)
0692 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_make_exception_ptr_compatible_conversion<void, T, void>))
0693 constexpr basic_result(const failure_type<T> &o,
0694 explicit_make_exception_ptr_compatible_copy_conversion_tag =
0695 explicit_make_exception_ptr_compatible_copy_conversion_tag()) noexcept(noexcept(make_exception_ptr(std::declval<T>())))
0696 : base{in_place_type<error_type_if_enabled>, make_exception_ptr(detail::extract_error_from_failure<error_type>(o))}
0697 {
0698 hooks::set_spare_storage(this, o.spare_storage());
0699 no_value_policy_type::on_result_copy_construction(this, o);
0700 }
0701
0702
0703
0704 BOOST_OUTCOME_TEMPLATE(class T)
0705 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_make_exception_ptr_compatible_conversion<void, T, void>))
0706 constexpr basic_result(failure_type<T> &&o,
0707 explicit_make_exception_ptr_compatible_move_conversion_tag =
0708 explicit_make_exception_ptr_compatible_move_conversion_tag()) noexcept(noexcept(make_exception_ptr(std::declval<T>())))
0709 : base{in_place_type<error_type_if_enabled>, make_exception_ptr(detail::extract_error_from_failure<error_type>(static_cast<failure_type<T> &&>(o)))}
0710 {
0711 hooks::set_spare_storage(this, o.spare_storage());
0712 no_value_policy_type::on_result_move_construction(this, static_cast<failure_type<T> &&>(o));
0713 }
0714
0715
0716
0717
0718 constexpr void swap(basic_result &o) noexcept((std::is_void<value_type>::value || detail::is_nothrow_swappable<value_type>::value)
0719 && (std::is_void<error_type>::value || detail::is_nothrow_swappable<error_type>::value))
0720 {
0721 this->_state.swap(o._state);
0722 }
0723
0724
0725
0726
0727 auto as_failure() const & { return failure(this->assume_error(), hooks::spare_storage(this)); }
0728
0729
0730
0731 auto as_failure() &&
0732 {
0733 this->_state._status.set_have_moved_from(true);
0734 return failure(static_cast<basic_result &&>(*this).assume_error(), hooks::spare_storage(this));
0735 }
0736
0737 #ifdef __APPLE__
0738 failure_type<error_type> _xcode_workaround_as_failure() &&;
0739 #endif
0740 };
0741
0742
0743
0744
0745 template <class R, class S, class P> inline void swap(basic_result<R, S, P> &a, basic_result<R, S, P> &b) noexcept(noexcept(a.swap(b)))
0746 {
0747 a.swap(b);
0748 }
0749
0750 #if !defined(NDEBUG)
0751
0752
0753
0754
0755 static_assert(std::is_trivially_copyable<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not trivially copyable!");
0756 static_assert(std::is_trivially_assignable<basic_result<int, long, policy::all_narrow>, basic_result<int, long, policy::all_narrow>>::value,
0757 "result<int> is not trivially assignable!");
0758 static_assert(std::is_trivially_destructible<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not trivially destructible!");
0759 static_assert(std::is_trivially_copy_constructible<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not trivially copy constructible!");
0760 static_assert(std::is_trivially_move_constructible<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not trivially move constructible!");
0761 static_assert(std::is_trivially_copy_assignable<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not trivially copy assignable!");
0762 static_assert(std::is_trivially_move_assignable<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not trivially move assignable!");
0763
0764 static_assert(std::is_standard_layout<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not a standard layout type!");
0765 #endif
0766
0767 BOOST_OUTCOME_V2_NAMESPACE_END
0768
0769 #if defined(_MSC_VER) && !defined(__clang__)
0770 #pragma warning(pop)
0771 #endif
0772
0773 #ifdef __clang__
0774 #pragma clang diagnostic pop
0775 #endif
0776
0777 #endif