2 (C) 2018-2019 Niall Douglas <http://www.nedproductions.biz/> (6 commits)
3 File Created: March 2018
6 Boost Software License - Version 1.0 - August 17th, 2003
8 Permission is hereby granted, free of charge, to any person or organization
9 obtaining a copy of the software and accompanying documentation covered by
10 this license (the "Software") to use, reproduce, display, distribute,
11 execute, and transmit the Software, and to prepare derivative works of the
12 Software, and to permit third-parties to whom the Software is furnished to
13 do so, all subject to the following:
15 The copyright notices in the Software and this entire statement, including
16 the above license grant, this restriction and the following disclaimer,
17 must be included in all copies of the Software, in whole or in part, and
18 all derivative works of the Software, unless such copies or derivative
19 works are solely in the form of machine-executable object code generated by
20 a source language processor.
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
25 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
26 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
27 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28 DEALINGS IN THE SOFTWARE.
31 #ifndef BOOST_OUTCOME_TRAIT_STD_ERROR_CODE_HPP
32 #define BOOST_OUTCOME_TRAIT_STD_ERROR_CODE_HPP
34 #include "../config.hpp"
36 #include <system_error>
38 BOOST_OUTCOME_V2_NAMESPACE_BEGIN
42 // Customise _set_error_is_errno
43 template <class State> constexpr inline void _set_error_is_errno(State &state, const std::error_code &error)
45 if(error.category() == std::generic_category()
47 || error.category() == std::system_category()
51 state._status |= status_error_is_errno;
54 template <class State> constexpr inline void _set_error_is_errno(State &state, const std::error_condition &error)
56 if(error.category() == std::generic_category()
58 || error.category() == std::system_category()
62 state._status |= status_error_is_errno;
65 template <class State> constexpr inline void _set_error_is_errno(State &state, const std::errc & /*unused*/) { state._status |= status_error_is_errno; }
73 /* Pass through `make_error_code` function for `std::error_code`.
75 inline std::error_code make_error_code(std::error_code v) { return v; }
77 // Try ADL, if not use fall backs above
78 template <class T> constexpr inline decltype(auto) error_code(T &&v) { return make_error_code(std::forward<T>(v)); }
80 struct std_enum_overload_tag
85 /*! AWAITING HUGO JSON CONVERSION TOOL
86 SIGNATURE NOT RECOGNISED
88 template <class T> constexpr inline decltype(auto) error_code(T &&v) { return detail::error_code(std::forward<T>(v)); }
90 /*! AWAITING HUGO JSON CONVERSION TOOL
91 SIGNATURE NOT RECOGNISED
93 // inline void outcome_throw_as_system_error_with_payload(...) = delete; // To use the error_code_throw_as_system_error policy with a custom Error type, you must define a outcome_throw_as_system_error_with_payload() free function to say how to handle the payload
94 inline void outcome_throw_as_system_error_with_payload(const std::error_code &error) { BOOST_OUTCOME_THROW_EXCEPTION(std::system_error(error)); } // NOLINT
95 BOOST_OUTCOME_TEMPLATE(class Error)
96 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))
97 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))); } // NOLINT
104 template <> struct _is_error_code_available<std::error_code>
106 // Shortcut this for lower build impact
107 static constexpr bool value = true;
108 using type = std::error_code;
110 } // namespace detail
112 // std::error_code is an error type
113 template <> struct is_error_type<std::error_code>
115 static constexpr bool value = true;
117 // For std::error_code, std::is_error_condition_enum<> is the trait we want.
118 template <class Enum> struct is_error_type_enum<std::error_code, Enum>
120 static constexpr bool value = std::is_error_condition_enum<Enum>::value;
125 BOOST_OUTCOME_V2_NAMESPACE_END