File indexing completed on 2025-12-16 09:59:09
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_TRAIT_STD_ERROR_CODE_HPP
0032 #define BOOST_OUTCOME_TRAIT_STD_ERROR_CODE_HPP
0033
0034 #include "../config.hpp"
0035
0036 #include <system_error>
0037
0038 BOOST_OUTCOME_V2_NAMESPACE_BEGIN
0039
0040 namespace detail
0041 {
0042
0043 template <class State> constexpr inline void _set_error_is_errno(State &state, const std::error_code &error)
0044 {
0045 if(error.category() == std::generic_category()
0046 #ifndef _WIN32
0047 || error.category() == std::system_category()
0048 #endif
0049 )
0050 {
0051 state._status.set_have_error_is_errno(true);
0052 }
0053 }
0054 template <class State> constexpr inline void _set_error_is_errno(State &state, const std::error_condition &error)
0055 {
0056 if(error.category() == std::generic_category()
0057 #ifndef _WIN32
0058 || error.category() == std::system_category()
0059 #endif
0060 )
0061 {
0062 state._status.set_have_error_is_errno(true);
0063 }
0064 }
0065 template <class State> constexpr inline void _set_error_is_errno(State &state, const std::errc & ) {
0066 state._status.set_have_error_is_errno(true);
0067 }
0068
0069 }
0070
0071 namespace policy
0072 {
0073 namespace detail
0074 {
0075
0076
0077 inline std::error_code make_error_code(std::error_code v) { return v; }
0078
0079
0080 template <class T> constexpr inline decltype(auto) error_code(T &&v) { return make_error_code(std::forward<T>(v)); }
0081
0082 struct std_enum_overload_tag
0083 {
0084 };
0085 }
0086
0087
0088
0089
0090 template <class T> constexpr inline decltype(auto) error_code(T &&v) { return detail::error_code(std::forward<T>(v)); }
0091
0092
0093
0094
0095
0096 inline void outcome_throw_as_system_error_with_payload(const std::error_code &error) { BOOST_OUTCOME_THROW_EXCEPTION(std::system_error(error)); }
0097 BOOST_OUTCOME_TEMPLATE(class Error)
0098 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(std::is_error_code_enum<std::decay_t<Error>>::value || std::is_error_condition_enum<std::decay_t<Error>>::value))
0099 inline void outcome_throw_as_system_error_with_payload(Error &&error, detail::std_enum_overload_tag = detail::std_enum_overload_tag()) { BOOST_OUTCOME_THROW_EXCEPTION(std::system_error(make_error_code(error))); }
0100 }
0101
0102 namespace trait
0103 {
0104 namespace detail
0105 {
0106 template <> struct _is_error_code_available<std::error_code>
0107 {
0108
0109 static constexpr bool value = true;
0110 using type = std::error_code;
0111 };
0112 }
0113
0114
0115 template <> struct is_error_type<std::error_code>
0116 {
0117 static constexpr bool value = true;
0118 };
0119
0120 template <class Enum> struct is_error_type_enum<std::error_code, Enum>
0121 {
0122 static constexpr bool value = std::is_error_condition_enum<Enum>::value;
0123 };
0124
0125 }
0126
0127 BOOST_OUTCOME_V2_NAMESPACE_END
0128
0129 #endif