File indexing completed on 2025-11-03 09:31:51
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 #ifndef BOOST_OUTCOME_SYSTEM_ERROR2_STATUS_CODE_HPP
0026 #define BOOST_OUTCOME_SYSTEM_ERROR2_STATUS_CODE_HPP
0027 
0028 #include "status_code_domain.hpp"
0029 
0030 #if(__cplusplus >= 201700 || _HAS_CXX17) && !defined(BOOST_OUTCOME_SYSTEM_ERROR2_DISABLE_STD_IN_PLACE)
0031 
0032 #include <utility>  // for in_place
0033 
0034 BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE_BEGIN
0035 using in_place_t = std::in_place_t;
0036 using std::in_place;
0037 BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE_END
0038 
0039 #else
0040 
0041 BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE_BEGIN
0042 
0043 struct in_place_t
0044 {
0045   explicit in_place_t() = default;
0046 };
0047 
0048 constexpr in_place_t in_place{};
0049 BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE_END
0050 #endif
0051 
0052 BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE_BEGIN
0053 
0054 
0055 namespace mixins
0056 {
0057   template <class Base, class T> struct mixin : public Base
0058   {
0059     using Base::Base;
0060   };
0061 }  
0062 
0063 namespace detail
0064 {
0065   BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(class ErasedType)  
0066   BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(traits::is_move_bitcopying<ErasedType>::value))
0067   struct erased
0068   {
0069     using value_type = ErasedType;
0070   };
0071 }  
0072 
0073 
0074 
0075 
0076 template <class ErasedType>  
0077 using status_code_erased_tag_type = detail::erased<ErasedType>;
0078 
0079 
0080 
0081 
0082 
0083 
0084 
0085 
0086 
0087 
0088 
0089 
0090 
0091 
0092 
0093 
0094 
0095 
0096 
0097 
0098 
0099 
0100 
0101 
0102 
0103 
0104 
0105 
0106 
0107 
0108 
0109 
0110 
0111 
0112 
0113 
0114 
0115 
0116 
0117 
0118 
0119 
0120 
0121 
0122 template <class Enum> struct quick_status_code_from_enum;
0123 
0124 namespace detail
0125 {
0126   template <class T> struct is_status_code
0127   {
0128     static constexpr bool value = false;
0129   };
0130   template <class T> struct is_status_code<status_code<T>>
0131   {
0132     static constexpr bool value = true;
0133   };
0134   template <class T> struct is_erased_status_code
0135   {
0136     static constexpr bool value = false;
0137   };
0138   template <class T> struct is_erased_status_code<status_code<detail::erased<T>>>
0139   {
0140     static constexpr bool value = true;
0141   };
0142 
0143 #if !defined(__GNUC__) || defined(__clang__) || __GNUC__ >= 8
0144   
0145   namespace impl
0146   {
0147     template <typename... Ts> struct make_void
0148     {
0149       using type = void;
0150     };
0151     template <typename... Ts> using void_t = typename make_void<Ts...>::type;
0152     template <class...> struct types
0153     {
0154       using type = types;
0155     };
0156     template <template <class...> class T, class types, class = void> struct test_apply
0157     {
0158       using type = void;
0159     };
0160     template <template <class...> class T, class... Ts> struct test_apply<T, types<Ts...>, void_t<T<Ts...>>>
0161     {
0162       using type = T<Ts...>;
0163     };
0164   }  
0165   template <template <class...> class T, class... Ts> using test_apply = impl::test_apply<T, impl::types<Ts...>>;
0166 
0167   template <class T, class... Args> using get_make_status_code_result = decltype(make_status_code(std::declval<T>(), std::declval<Args>()...));
0168   template <class... Args> using safe_get_make_status_code_result = test_apply<get_make_status_code_result, Args...>;
0169 
0170 #else
0171 
0172   
0173   
0174   namespace impl
0175   {
0176     template <typename... Ts> struct make_void
0177     {
0178       using type = void;
0179     };
0180     template <typename... Ts> using void_t = typename make_void<Ts...>::type;
0181     template <class...> struct types
0182     {
0183       using type = types;
0184     };
0185     template <typename Types, typename = void> struct make_status_code_rettype
0186     {
0187       using type = void;
0188     };
0189     template <typename... Args> using get_make_status_code_result = decltype(make_status_code(std::declval<Args>()...));
0190     template <typename... Args> struct make_status_code_rettype<types<Args...>, void_t<get_make_status_code_result<Args...>>>
0191     {
0192       using type = get_make_status_code_result<Args...>;
0193     };
0194   }  
0195   template <class... Args> struct safe_get_make_status_code_result
0196   {
0197     using type = typename impl::make_status_code_rettype<impl::types<Args...>>::type;
0198   };
0199 #endif
0200 }  
0201 
0202 
0203 template <class T> struct is_status_code
0204 {
0205   static constexpr bool value =
0206   detail::is_status_code<typename std::decay<T>::type>::value || detail::is_erased_status_code<typename std::decay<T>::type>::value;
0207 };
0208 
0209 
0210 
0211 
0212 
0213 
0214 template <> class BOOST_OUTCOME_SYSTEM_ERROR2_TRIVIAL_ABI status_code<void>
0215 {
0216   template <class T> friend class status_code;
0217 
0218 public:
0219   
0220   using domain_type = void;
0221   
0222   using value_type = void;
0223   
0224   using string_ref = typename status_code_domain::string_ref;
0225 
0226 protected:
0227   const status_code_domain *_domain{nullptr};
0228 
0229 protected:
0230   
0231   status_code() = default;
0232   
0233   status_code(const status_code &) = default;
0234   
0235   status_code(status_code &&) = default;
0236   
0237   status_code &operator=(const status_code &) = default;
0238   
0239   status_code &operator=(status_code &&) = default;
0240   
0241   ~status_code() = default;
0242 
0243   
0244   constexpr explicit status_code(const status_code_domain *v) noexcept
0245       : _domain(v)
0246   {
0247   }
0248 
0249   
0250   constexpr const status_code_domain *_domain_ptr() const noexcept { return _domain; }
0251 
0252 public:
0253   
0254   constexpr const status_code_domain &domain() const noexcept { return *_domain; }
0255   
0256   BOOST_OUTCOME_SYSTEM_ERROR2_NODISCARD constexpr bool empty() const noexcept { return _domain == nullptr; }
0257 
0258   
0259   BOOST_OUTCOME_SYSTEM_ERROR2_CONSTEXPR20 string_ref message() const noexcept
0260   {
0261     
0262     if(_domain != nullptr)
0263     {
0264       return _domain->_do_message(*this);
0265     }
0266     return string_ref("(empty)");
0267   }
0268   
0269   BOOST_OUTCOME_SYSTEM_ERROR2_CONSTEXPR20 bool success() const noexcept { return (_domain != nullptr) ? !_domain->_do_failure(*this) : false; }
0270   
0271   BOOST_OUTCOME_SYSTEM_ERROR2_CONSTEXPR20 bool failure() const noexcept { return (_domain != nullptr) ? _domain->_do_failure(*this) : false; }
0272   
0273 
0274 
0275 
0276 
0277   template <class T> BOOST_OUTCOME_SYSTEM_ERROR2_CONSTEXPR14 bool strictly_equivalent(const status_code<T> &o) const noexcept
0278   {
0279     if(_domain && o._domain)
0280     {
0281       return _domain->_do_equivalent(*this, o);
0282     }
0283     
0284     if(!_domain && !o._domain)
0285     {
0286       return true;  
0287     }
0288     
0289     return false;
0290   }
0291   
0292 
0293 
0294 
0295   template <class T> BOOST_OUTCOME_SYSTEM_ERROR2_CONSTEXPR14 inline bool equivalent(const status_code<T> &o) const noexcept;
0296 #if defined(_CPPUNWIND) || defined(__EXCEPTIONS) || defined(BOOST_OUTCOME_STANDARDESE_IS_IN_THE_HOUSE)
0297   
0298   BOOST_OUTCOME_SYSTEM_ERROR2_NORETURN void throw_exception() const
0299   {
0300     _domain->_do_throw_exception(*this);
0301     abort();  
0302   }
0303 #endif
0304 };
0305 
0306 namespace detail
0307 {
0308   template <class DomainType> struct get_domain_value_type
0309   {
0310     using domain_type = DomainType;
0311     using value_type = typename domain_type::value_type;
0312   };
0313   template <class ErasedType> struct get_domain_value_type<erased<ErasedType>>
0314   {
0315     using domain_type = status_code_domain;
0316     using value_type = ErasedType;
0317   };
0318   template <class DomainType> class BOOST_OUTCOME_SYSTEM_ERROR2_TRIVIAL_ABI status_code_storage : public status_code<void>
0319   {
0320     static_assert(!std::is_void<DomainType>::value, "status_code_storage<void> should never occur!");
0321     using _base = status_code<void>;
0322 
0323   public:
0324     
0325     using domain_type = typename get_domain_value_type<DomainType>::domain_type;
0326     
0327     using value_type = typename get_domain_value_type<DomainType>::value_type;
0328     
0329     using string_ref = typename domain_type::string_ref;
0330 
0331 #ifndef NDEBUG
0332     static_assert(std::is_move_constructible<value_type>::value || std::is_copy_constructible<value_type>::value,
0333                   "DomainType::value_type is neither move nor copy constructible!");
0334     static_assert(!std::is_default_constructible<value_type>::value || std::is_nothrow_default_constructible<value_type>::value,
0335                   "DomainType::value_type is not nothrow default constructible!");
0336     static_assert(!std::is_move_constructible<value_type>::value || std::is_nothrow_move_constructible<value_type>::value,
0337                   "DomainType::value_type is not nothrow move constructible!");
0338     static_assert(std::is_nothrow_destructible<value_type>::value, "DomainType::value_type is not nothrow destructible!");
0339 #endif
0340 
0341     
0342     
0343     constexpr const domain_type &domain() const noexcept { return *static_cast<const domain_type *>(this->_domain); }
0344 
0345     
0346     BOOST_OUTCOME_SYSTEM_ERROR2_CONSTEXPR14 void clear() noexcept
0347     {
0348       this->_value.~value_type();
0349       this->_domain = nullptr;
0350       new(std::addressof(this->_value)) value_type();
0351     }
0352 
0353 #if __cplusplus >= 201400 || _MSC_VER >= 1910 
0354     
0355     constexpr value_type &value() & noexcept { return this->_value; }
0356     
0357     constexpr value_type &&value() && noexcept { return static_cast<value_type &&>(this->_value); }
0358 #endif
0359     
0360     constexpr const value_type &value() const & noexcept { return this->_value; }
0361     
0362     constexpr const value_type &&value() const && noexcept { return static_cast<const value_type &&>(this->_value); }
0363 
0364   protected:
0365     status_code_storage() = default;
0366     status_code_storage(const status_code_storage &) = default;
0367     BOOST_OUTCOME_SYSTEM_ERROR2_CONSTEXPR14 status_code_storage(status_code_storage &&o) noexcept
0368         : _base(static_cast<status_code_storage &&>(o))
0369         , _value(static_cast<status_code_storage &&>(o)._value)
0370     {
0371       o._domain = nullptr;
0372     }
0373     status_code_storage &operator=(const status_code_storage &) = default;
0374     BOOST_OUTCOME_SYSTEM_ERROR2_CONSTEXPR14 status_code_storage &operator=(status_code_storage &&o) noexcept
0375     {
0376       this->~status_code_storage();
0377       new(this) status_code_storage(static_cast<status_code_storage &&>(o));
0378       return *this;
0379     }
0380     ~status_code_storage() = default;
0381 
0382     value_type _value{};
0383     struct _value_type_constructor
0384     {
0385     };
0386     template <class... Args>
0387     constexpr status_code_storage(_value_type_constructor , const status_code_domain *v, Args &&...args)
0388         : _base(v)
0389         , _value(static_cast<Args &&>(args)...)
0390     {
0391     }
0392   };
0393 
0394   template <class DomainType> struct has_stateful_mixin
0395   {
0396     static constexpr bool value = (sizeof(status_code_storage<DomainType>) != sizeof(mixins::mixin<status_code_storage<DomainType>, DomainType>));
0397   };
0398 
0399   template <class ToDomain, class FromDomain> struct domain_value_type_erasure_is_safe
0400   {
0401     using to_value_type = typename get_domain_value_type<ToDomain>::value_type;
0402     using from_value_type = typename get_domain_value_type<FromDomain>::value_type;
0403     static constexpr bool value = traits::is_move_bitcopying<to_value_type>::value                                     
0404                                   && traits::is_move_bitcopying<from_value_type>::value                                
0405                                   && sizeof(status_code_storage<FromDomain>) <= sizeof(status_code_storage<ToDomain>)  
0406                                   && !has_stateful_mixin<FromDomain>::value;
0407   };
0408   template <class ToDomain> struct domain_value_type_erasure_is_safe<ToDomain, void>
0409   {
0410     static constexpr bool value = false;
0411   };
0412 }  
0413 
0414 namespace traits
0415 {
0416   
0417   template <class StatusCode> using has_stateful_mixin = detail::has_stateful_mixin<typename detail::remove_cvref<StatusCode>::type::value_type>;
0418 
0419   
0420   template <class To, class From>
0421   using is_type_erasable_to =
0422   detail::domain_value_type_erasure_is_safe<typename detail::remove_cvref<To>::type::domain_type, typename detail::remove_cvref<From>::type::domain_type>;
0423 }  
0424 
0425 
0426 
0427 
0428 
0429 
0430 
0431 
0432 
0433 
0434 
0435 
0436 
0437 
0438 template <class DomainType> class BOOST_OUTCOME_SYSTEM_ERROR2_TRIVIAL_ABI status_code : public mixins::mixin<detail::status_code_storage<DomainType>, DomainType>
0439 {
0440   template <class T> friend class status_code;
0441   using _base = mixins::mixin<detail::status_code_storage<DomainType>, DomainType>;
0442 
0443 public:
0444   
0445   using domain_type = DomainType;
0446   
0447   using value_type = typename domain_type::value_type;
0448   
0449   using string_ref = typename domain_type::string_ref;
0450 
0451 protected:
0452   using _base::_base;
0453 
0454 public:
0455   
0456   status_code() = default;
0457   
0458   status_code(const status_code &) = default;
0459   
0460   status_code(status_code &&) = default;  
0461   
0462   status_code &operator=(const status_code &) = default;
0463   
0464   status_code &operator=(status_code &&) = default;  
0465   ~status_code() = default;
0466 
0467   
0468   BOOST_OUTCOME_SYSTEM_ERROR2_CONSTEXPR14 status_code clone() const { return *this; }
0469 
0470   
0471   
0472   BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(
0473   class T, class... Args,  
0474   class MakeStatusCodeResult =
0475   typename detail::safe_get_make_status_code_result<T, Args...>::type)  
0476   BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(!std::is_same<typename std::decay<T>::type, status_code>::value       
0477                                               && !std::is_same<typename std::decay<T>::type, in_place_t>::value     
0478                                               && is_status_code<MakeStatusCodeResult>::value                        
0479                                               && std::is_constructible<status_code, MakeStatusCodeResult>::value))  
0480   constexpr status_code(T &&v, Args &&...args) noexcept(noexcept(make_status_code(std::declval<T>(), std::declval<Args>()...)))  
0481       : status_code(make_status_code(static_cast<T &&>(v), static_cast<Args &&>(args)...))
0482   {
0483   }
0484   
0485   BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(class Enum,                                                                                
0486                          class QuickStatusCodeType = typename quick_status_code_from_enum<Enum>::code_type)         
0487   BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(std::is_constructible<status_code, QuickStatusCodeType>::value))      
0488   constexpr status_code(Enum &&v) noexcept(std::is_nothrow_constructible<status_code, QuickStatusCodeType>::value)  
0489       : status_code(QuickStatusCodeType(static_cast<Enum &&>(v)))
0490   {
0491   }
0492   
0493   template <class... Args>
0494   constexpr explicit status_code(in_place_t , Args &&...args) noexcept(std::is_nothrow_constructible<value_type, Args &&...>::value)
0495       : _base(typename _base::_value_type_constructor{}, &domain_type::get(), static_cast<Args &&>(args)...)
0496   {
0497   }
0498   
0499   template <class T, class... Args>
0500   constexpr explicit status_code(in_place_t , std::initializer_list<T> il,
0501                                  Args &&...args) noexcept(std::is_nothrow_constructible<value_type, std::initializer_list<T>, Args &&...>::value)
0502       : _base(typename _base::_value_type_constructor{}, &domain_type::get(), il, static_cast<Args &&>(args)...)
0503   {
0504   }
0505   
0506   constexpr explicit status_code(const value_type &v) noexcept(std::is_nothrow_copy_constructible<value_type>::value)
0507       : _base(typename _base::_value_type_constructor{}, &domain_type::get(), v)
0508   {
0509   }
0510   
0511   constexpr explicit status_code(value_type &&v) noexcept(std::is_nothrow_move_constructible<value_type>::value)
0512       : _base(typename _base::_value_type_constructor{}, &domain_type::get(), static_cast<value_type &&>(v))
0513   {
0514   }
0515   
0516 
0517 
0518 
0519   BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(class ErasedType)  
0520   BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(detail::domain_value_type_erasure_is_safe<domain_type, detail::erased<ErasedType>>::value))
0521   constexpr explicit status_code(const status_code<detail::erased<ErasedType>> &v) noexcept(std::is_nothrow_copy_constructible<value_type>::value)
0522       : status_code(detail::erasure_cast<value_type>(v.value()))
0523   {
0524 #if __cplusplus >= 201400
0525     assert(v.domain() == this->domain());
0526 #endif
0527   }
0528 
0529   
0530   BOOST_OUTCOME_SYSTEM_ERROR2_CONSTEXPR20 string_ref message() const noexcept
0531   {
0532     
0533     if(this->_domain != nullptr)
0534     {
0535       return string_ref(this->domain()._do_message(*this));
0536     }
0537     return string_ref("(empty)");
0538   }
0539 };
0540 
0541 namespace traits
0542 {
0543   template <class DomainType> struct is_move_bitcopying<status_code<DomainType>>
0544   {
0545     static constexpr bool value = is_move_bitcopying<typename DomainType::value_type>::value;
0546   };
0547 }  
0548 
0549 
0550 
0551 
0552 
0553 
0554 
0555 
0556 
0557 
0558 
0559 template <class ErasedType>
0560 class BOOST_OUTCOME_SYSTEM_ERROR2_TRIVIAL_ABI status_code<detail::erased<ErasedType>>
0561     : public mixins::mixin<detail::status_code_storage<detail::erased<ErasedType>>, detail::erased<ErasedType>>
0562 {
0563   template <class T> friend class status_code;
0564   using _base = mixins::mixin<detail::status_code_storage<detail::erased<ErasedType>>, detail::erased<ErasedType>>;
0565 
0566 public:
0567   
0568   using domain_type = void;
0569   
0570   using value_type = ErasedType;
0571   
0572   using string_ref = typename _base::string_ref;
0573 
0574 public:
0575   
0576   status_code() = default;
0577   
0578   status_code(const status_code &) = delete;
0579   
0580   status_code(status_code &&) = default;  
0581   
0582   status_code &operator=(const status_code &) = delete;
0583   
0584   status_code &operator=(status_code &&) = default;  
0585   BOOST_OUTCOME_SYSTEM_ERROR2_CONSTEXPR20 ~status_code()
0586   {
0587     if(nullptr != this->_domain)
0588     {
0589       status_code_domain::payload_info_t info{sizeof(value_type), sizeof(status_code), alignof(status_code)};
0590       this->_domain->_do_erased_destroy(*this, info);
0591     }
0592   }
0593 
0594   
0595   BOOST_OUTCOME_SYSTEM_ERROR2_CONSTEXPR20 status_code clone() const
0596   {
0597     if(nullptr == this->_domain)
0598     {
0599       return {};
0600     }
0601     status_code x;
0602     if(!this->_domain->_do_erased_copy(x, *this, this->_domain->payload_info()))
0603     {
0604       abort();  
0605     }
0606     return x;
0607   }
0608 
0609   
0610   
0611   
0612   BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(class DomainType)  
0613   BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(detail::domain_value_type_erasure_is_safe<detail::erased<ErasedType>, DomainType>::value),
0614                           BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(!detail::is_erased_status_code<status_code<typename std::decay<DomainType>::type>>::value))
0615   constexpr status_code(const status_code<DomainType> &v) noexcept  
0616       : _base(typename _base::_value_type_constructor{}, v._domain_ptr(), detail::erasure_cast<value_type>(v.value()))
0617   {
0618   }
0619   
0620   BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(class DomainType)  
0621   BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(detail::domain_value_type_erasure_is_safe<detail::erased<ErasedType>, DomainType>::value))
0622   BOOST_OUTCOME_SYSTEM_ERROR2_CONSTEXPR14 status_code(status_code<DomainType> &&v) noexcept  
0623       : _base(typename _base::_value_type_constructor{}, v._domain_ptr(), detail::erasure_cast<value_type>(v.value()))
0624   {
0625     alignas(alignof(typename DomainType::value_type)) char buffer[sizeof(typename DomainType::value_type)];
0626     new(buffer) typename DomainType::value_type(static_cast<status_code<DomainType> &&>(v).value());
0627     
0628     (void) buffer;
0629     v._domain = nullptr;
0630   }
0631   
0632   BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(
0633   class T, class... Args,  
0634   class MakeStatusCodeResult =
0635   typename detail::safe_get_make_status_code_result<T, Args...>::type)  
0636   BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(!std::is_same<typename std::decay<T>::type, status_code>::value       
0637                                               && !std::is_same<typename std::decay<T>::type, value_type>::value     
0638                                               && is_status_code<MakeStatusCodeResult>::value                        
0639                                               && std::is_constructible<status_code, MakeStatusCodeResult>::value))  
0640   constexpr status_code(T &&v, Args &&...args) noexcept(noexcept(make_status_code(std::declval<T>(), std::declval<Args>()...)))  
0641       : status_code(make_status_code(static_cast<T &&>(v), static_cast<Args &&>(args)...))
0642   {
0643   }
0644 
0645   
0646   BOOST_OUTCOME_SYSTEM_ERROR2_TEMPLATE(class Enum,                                                                                
0647                          class QuickStatusCodeType = typename quick_status_code_from_enum<Enum>::code_type)         
0648   BOOST_OUTCOME_SYSTEM_ERROR2_TREQUIRES(BOOST_OUTCOME_SYSTEM_ERROR2_TPRED(std::is_constructible<status_code, QuickStatusCodeType>::value))      
0649   constexpr status_code(Enum &&v) noexcept(std::is_nothrow_constructible<status_code, QuickStatusCodeType>::value)  
0650       : status_code(QuickStatusCodeType(static_cast<Enum &&>(v)))
0651   {
0652   }
0653 
0654 #if defined(_CPPUNWIND) || defined(__EXCEPTIONS) || defined(BOOST_OUTCOME_STANDARDESE_IS_IN_THE_HOUSE)
0655   
0656   
0657   explicit BOOST_OUTCOME_SYSTEM_ERROR2_CONSTEXPR14 status_code(in_place_t, const status_code<void> &v)  
0658       : _base(typename _base::_value_type_constructor{}, v._domain_ptr(), value_type{})
0659   {
0660     status_code_domain::payload_info_t info{sizeof(value_type), sizeof(status_code), alignof(status_code)};
0661     if(this->_domain->_do_erased_copy(*this, v, info))
0662     {
0663       return;
0664     }
0665     struct _ final : public std::exception
0666     {
0667       virtual const char *what() const noexcept override { return "status_code: source domain's erased copy function returned failure or refusal"; }
0668     };
0669     throw _{};
0670   }
0671 #endif
0672   
0673   
0674   BOOST_OUTCOME_SYSTEM_ERROR2_CONSTEXPR20 status_code(std::nothrow_t, const status_code<void> &v) noexcept  
0675       : _base(typename _base::_value_type_constructor{}, v._domain_ptr(), value_type{})
0676   {
0677 #if defined(_CPPUNWIND) || defined(__EXCEPTIONS) || defined(BOOST_OUTCOME_STANDARDESE_IS_IN_THE_HOUSE)
0678     try
0679 #endif
0680     {
0681       status_code_domain::payload_info_t info{sizeof(value_type), sizeof(status_code), alignof(status_code)};
0682       if(this->_domain->_do_erased_copy(*this, v, info))
0683       {
0684         return;
0685       }
0686       this->_domain = nullptr;
0687     }
0688 #if defined(_CPPUNWIND) || defined(__EXCEPTIONS) || defined(BOOST_OUTCOME_STANDARDESE_IS_IN_THE_HOUSE)
0689     catch(...)
0690     {
0691       this->_domain = nullptr;
0692     }
0693 #endif
0694   }
0695 
0696   
0697   
0698   BOOST_OUTCOME_SYSTEM_ERROR2_CONSTEXPR14 void clear() noexcept { *this = status_code(); }
0699   
0700   constexpr value_type value() const noexcept { return this->_value; }
0701 };
0702 
0703 
0704 
0705 
0706 template <class ErasedType> using erased_status_code = status_code<detail::erased<ErasedType>>;
0707 
0708 namespace traits
0709 {
0710   template <class ErasedType> struct is_move_bitcopying<status_code<detail::erased<ErasedType>>>
0711   {
0712     static constexpr bool value = true;
0713   };
0714 }  
0715 
0716 BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE_END
0717 
0718 #ifndef BOOST_OUTCOME_SYSTEM_ERROR2_DISABLE_INLINE_GDB_PRETTY_PRINTERS
0719 #if defined(__ELF__)
0720 #ifdef __clang__
0721 #pragma clang diagnostic push
0722 #pragma clang diagnostic ignored "-Woverlength-strings"
0723 #endif
0724 __asm__(
0725 ".pushsection \".debug_gdb_scripts\", \"MS\",%progbits,1\n"
0726 ".ascii \"\\4gdb.inlined-script.BOOST_OUTCOME_SYSTEM_ERROR2_INLINE_GDB_PRETTY_PRINTERS_H\\n\"\n"
0727 ".ascii \"import gdb.printing\\n\"\n"
0728 ".ascii \"import gdb\\n\"\n"
0729 ".ascii \"import os\\n\"\n"
0730 
0731 ".ascii \"def synthesise_gdb_value_from_string(s):\\n\"\n"
0732 ".ascii \"    '''For when you want to return a synthetic string from children()'''\\n\"\n"
0733 ".ascii \"    return gdb.Value(s + '\\\\0').cast(gdb.lookup_type('char').pointer())\\n\"\n"
0734 
0735 ".ascii \"class StatusCodePrinter(object):\\n\"\n"
0736 ".ascii \"    '''Print a system_error2::status_code<T>'''\\n\"\n"
0737 
0738 ".ascii \"    def __init__(self, val):\\n\"\n"
0739 ".ascii \"        self.val = val\\n\"\n"
0740 
0741 ".ascii \"    def children(self):\\n\"\n"
0742 ".ascii \"        s = str(self.val['_domain'])\\n\"\n"
0743 ".ascii \"        if 'posix_code_domain' in s or 'generic_code_domain' in s:\\n\"\n"
0744 ".ascii \"            yield ('msg', synthesise_gdb_value_from_string(str(self.val['_value']) + ' (' + os.strerror(int(self.val['_value'])) + ')'))\\n\"\n"
0745 ".ascii \"        yield ('domain', self.val['_domain'])\\n\"\n"
0746 ".ascii \"        yield ('value', self.val['_value'])\\n\"\n"
0747 
0748 ".ascii \"    def display_hint(self):\\n\"\n"
0749 ".ascii \"        return None\\n\"\n"
0750 
0751 ".ascii \"    def to_string(self):\\n\"\n"
0752 ".ascii \"        s = str(self.val['_domain'])\\n\"\n"
0753 ".ascii \"        if 'posix_code_domain' in s or 'generic_code_domain' in s:\\n\"\n"
0754 ".ascii \"            return str(self.val['_value']) + ' (' + os.strerror(int(self.val['_value'])) + ')'\\n\"\n"
0755 ".ascii \"        else:\\n\"\n"
0756 ".ascii \"            return self.val['_value']\\n\"\n"
0757 
0758 ".ascii \"def build_pretty_printer():\\n\"\n"
0759 ".ascii \"    pp = gdb.printing.RegexpCollectionPrettyPrinter('system_error2')\\n\"\n"
0760 ".ascii \"    pp.add_printer('system_error2::status_code', '^(boost::)?system_error2::status_code<.*>$', StatusCodePrinter)\\n\"\n"
0761 ".ascii \"    return pp\\n\"\n"
0762 
0763 ".ascii \"def register_printers(obj = None):\\n\"\n"
0764 ".ascii \"    gdb.printing.register_pretty_printer(obj, build_pretty_printer(), replace = True)\\n\"\n"
0765 
0766 ".ascii \"register_printers(gdb.current_objfile())\\n\"\n"
0767 
0768 ".byte 0\n"
0769 ".popsection\n");
0770 #ifdef __clang__
0771 #pragma clang diagnostic pop
0772 #endif
0773 #endif  
0774 #endif  
0775 
0776 #endif