File indexing completed on 2025-12-16 09:59:12
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_EXPERIMENTAL_STATUS_RESULT_HPP
0032 #define BOOST_OUTCOME_EXPERIMENTAL_STATUS_RESULT_HPP
0033
0034 #include "../basic_result.hpp"
0035 #include "../policy/fail_to_compile_observers.hpp"
0036
0037 #ifndef BOOST_OUTCOME_SYSTEM_ERROR2_USE_STD_ADDRESSOF
0038 #if BOOST_OUTCOME_USE_STD_ADDRESSOF
0039 #define BOOST_OUTCOME_SYSTEM_ERROR2_USE_STD_ADDRESSOF 1
0040 #endif
0041 #endif
0042
0043 #if __PCPP_ALWAYS_TRUE__
0044 #include "status-code/system_error2.hpp"
0045 #elif !BOOST_OUTCOME_USE_SYSTEM_STATUS_CODE && __has_include("status-code/system_error2.hpp")
0046 #include "status-code/system_error2.hpp"
0047 #else
0048 #include <status-code/system_error2.hpp>
0049 #endif
0050
0051 BOOST_OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
0052
0053 namespace trait
0054 {
0055 namespace detail
0056 {
0057
0058
0059 template <class DomainType> struct _is_error_code_available<BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE::status_code<DomainType>>
0060 {
0061 static constexpr bool value = true;
0062 using type = BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE::status_code<DomainType>;
0063 };
0064 template <class DomainType> struct _is_error_code_available<BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE::errored_status_code<DomainType>>
0065 {
0066 static constexpr bool value = true;
0067 using type = BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE::errored_status_code<DomainType>;
0068 };
0069 }
0070 #if 0
0071 template <class DomainType> struct is_error_type<BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE::status_code<DomainType>>
0072 {
0073 static constexpr bool value = true;
0074 };
0075 template <> struct is_error_type<BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE::errc>
0076 {
0077 static constexpr bool value = true;
0078 };
0079 template <class DomainType, class Enum> struct is_error_type_enum<BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE::status_code<DomainType>, Enum>
0080 {
0081 static constexpr bool value = boost::system::is_error_condition_enum<Enum>::value;
0082 };
0083 #endif
0084
0085 template <class DomainType> struct is_move_bitcopying<BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE::status_code<DomainType>>
0086 {
0087 static constexpr bool value = BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE::traits::is_move_bitcopying<BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE::status_code<DomainType>>::value;
0088 };
0089 template <class DomainType> struct is_move_bitcopying<BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE::errored_status_code<DomainType>>
0090 {
0091 static constexpr bool value = BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE::traits::is_move_bitcopying<BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE::errored_status_code<DomainType>>::value;
0092 };
0093 }
0094
0095 namespace detail
0096 {
0097
0098 template <class State> constexpr inline void _set_error_is_errno(State &state, const BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE::generic_code & )
0099 {
0100 state._status.set_have_error_is_errno(true);
0101 }
0102 #ifndef BOOST_OUTCOME_SYSTEM_ERROR2_NOT_POSIX
0103 template <class State> constexpr inline void _set_error_is_errno(State &state, const BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE::posix_code & )
0104 {
0105 state._status.set_have_error_is_errno(true);
0106 }
0107 #endif
0108 template <class State> constexpr inline void _set_error_is_errno(State &state, const BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE::errc & )
0109 {
0110 state._status.set_have_error_is_errno(true);
0111 }
0112
0113 }
0114
0115 namespace experimental
0116 {
0117 using namespace BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE;
0118 using BOOST_OUTCOME_V2_NAMESPACE::failure;
0119 using BOOST_OUTCOME_V2_NAMESPACE::success;
0120
0121 namespace policy
0122 {
0123 using namespace BOOST_OUTCOME_V2_NAMESPACE::policy;
0124 template <class T, class EC, class E> struct status_code_throw
0125 {
0126 static_assert(!std::is_same<T, T>::value,
0127 "policy::status_code_throw not specialised for these types, did you use status_result<T, status_code<DomainType>, E>?");
0128 };
0129 template <class T, class DomainType> struct status_code_throw<T, status_code<DomainType>, void> : base
0130 {
0131 using _base = base;
0132 template <class Impl> static constexpr void wide_value_check(Impl &&self)
0133 {
0134 if(!base::_has_value(static_cast<Impl &&>(self)))
0135 {
0136 if(base::_has_error(static_cast<Impl &&>(self)))
0137 {
0138 #ifndef BOOST_NO_EXCEPTIONS
0139 base::_error(static_cast<Impl &&>(self)).throw_exception();
0140 #else
0141 BOOST_OUTCOME_THROW_EXCEPTION("wide value check failed");
0142 #endif
0143 }
0144 }
0145 }
0146 template <class Impl> static constexpr void wide_error_check(Impl &&self) { _base::narrow_error_check(static_cast<Impl &&>(self)); }
0147 };
0148 template <class T, class DomainType>
0149 struct status_code_throw<T, errored_status_code<DomainType>, void> : status_code_throw<T, status_code<DomainType>, void>
0150 {
0151 status_code_throw() = default;
0152 using status_code_throw<T, status_code<DomainType>, void>::status_code_throw;
0153 };
0154
0155 template <class T, class EC>
0156 using default_status_result_policy = std::conditional_t<
0157 std::is_void<EC>::value,
0158 BOOST_OUTCOME_V2_NAMESPACE::policy::terminate,
0159 std::conditional_t<is_status_code<EC>::value || is_errored_status_code<EC>::value,
0160 status_code_throw<T, EC, void>,
0161 BOOST_OUTCOME_V2_NAMESPACE::policy::fail_to_compile_observers
0162 >>;
0163 }
0164
0165
0166
0167
0168 template <class R, class S = erased_errored_status_code<typename system_code::value_type>,
0169 class NoValuePolicy = policy::default_status_result_policy<R, S>>
0170 using status_result = basic_result<R, S, NoValuePolicy>;
0171
0172
0173
0174
0175 BOOST_OUTCOME_TEMPLATE(class R, class S, class NoValuePolicy)
0176 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(std::is_copy_constructible<R>::value && (is_status_code<S>::value || is_errored_status_code<S>::value)))
0177 inline basic_result<R, S, NoValuePolicy> clone(const basic_result<R, S, NoValuePolicy> &v)
0178 {
0179 if(v)
0180 {
0181 return success_type<R>(v.assume_value());
0182 }
0183 return failure_type<S>(v.assume_error().clone(), hooks::spare_storage(&v));
0184 }
0185
0186
0187
0188
0189 BOOST_OUTCOME_TEMPLATE(class S, class NoValuePolicy)
0190 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(is_status_code<S>::value || is_errored_status_code<S>::value))
0191 inline basic_result<void, S, NoValuePolicy> clone(const basic_result<void, S, NoValuePolicy> &v)
0192 {
0193 if(v)
0194 {
0195 return success_type<void>();
0196 }
0197 return failure_type<S>(v.assume_error().clone(), hooks::spare_storage(&v));
0198 }
0199
0200 }
0201
0202 BOOST_OUTCOME_V2_NAMESPACE_END
0203
0204 #endif