123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- #ifndef BOOST_OUTCOME_TRAIT_STD_ERROR_CODE_HPP
- #define BOOST_OUTCOME_TRAIT_STD_ERROR_CODE_HPP
- #include "../config.hpp"
- #include <system_error>
- BOOST_OUTCOME_V2_NAMESPACE_BEGIN
- namespace detail
- {
-
- template <class State> constexpr inline void _set_error_is_errno(State &state, const std::error_code &error)
- {
- if(error.category() == std::generic_category()
- #ifndef _WIN32
- || error.category() == std::system_category()
- #endif
- )
- {
- state._status.set_have_error_is_errno(true);
- }
- }
- template <class State> constexpr inline void _set_error_is_errno(State &state, const std::error_condition &error)
- {
- if(error.category() == std::generic_category()
- #ifndef _WIN32
- || error.category() == std::system_category()
- #endif
- )
- {
- state._status.set_have_error_is_errno(true);
- }
- }
- template <class State> constexpr inline void _set_error_is_errno(State &state, const std::errc & /*unused*/) {
- state._status.set_have_error_is_errno(true);
- }
- }
- namespace policy
- {
- namespace detail
- {
-
- inline std::error_code make_error_code(std::error_code v) { return v; }
-
- template <class T> constexpr inline decltype(auto) error_code(T &&v) { return make_error_code(std::forward<T>(v)); }
- struct std_enum_overload_tag
- {
- };
- }
-
- template <class T> constexpr inline decltype(auto) error_code(T &&v) { return detail::error_code(std::forward<T>(v)); }
-
-
- inline void outcome_throw_as_system_error_with_payload(const std::error_code &error) { BOOST_OUTCOME_THROW_EXCEPTION(std::system_error(error)); }
- BOOST_OUTCOME_TEMPLATE(class Error)
- 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))
- inline void outcome_throw_as_system_error_with_payload(Error &&error, detail::std_enum_overload_tag /*unused*/ = detail::std_enum_overload_tag()) { BOOST_OUTCOME_THROW_EXCEPTION(std::system_error(make_error_code(error))); }
- }
- namespace trait
- {
- namespace detail
- {
- template <> struct _is_error_code_available<std::error_code>
- {
-
- static constexpr bool value = true;
- using type = std::error_code;
- };
- }
-
- template <> struct is_error_type<std::error_code>
- {
- static constexpr bool value = true;
- };
-
- template <class Enum> struct is_error_type_enum<std::error_code, Enum>
- {
- static constexpr bool value = std::is_error_condition_enum<Enum>::value;
- };
- }
- BOOST_OUTCOME_V2_NAMESPACE_END
- #endif
|