1 /* A very simple result type
2 (C) 2017-2019 Niall Douglas <http://www.nedproductions.biz/> (10 commits)
3 File Created: June 2017
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_BOOST_RESULT_HPP
32 #define BOOST_OUTCOME_BOOST_RESULT_HPP
36 #include "boost/exception_ptr.hpp"
37 #include "boost/system/system_error.hpp"
39 BOOST_OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
41 /*! AWAITING HUGO JSON CONVERSION TOOL
42 SIGNATURE NOT RECOGNISED
48 /* Pass through `make_error_code` function for `boost::system::error_code`.
50 inline boost::system::error_code make_error_code(boost::system::error_code v) { return v; }
52 /* Pass through `make_exception_ptr` function for `boost::exception_ptr`.
53 The reason this needs to be here, declared before the rest of Outcome,
54 is that there is no boost::make_exception_ptr as Boost still uses the old
55 naming boost::copy_exception. Therefore the ADL discovered make_exception_ptr
56 doesn't work, hence this hacky pre-declaration here.
58 I was tempted to just inject a boost::make_exception_ptr, but I can see
59 Boost doing that itself at some point. This hack should keep working after.
61 inline boost::exception_ptr make_exception_ptr(boost::exception_ptr v) { return v; }
64 BOOST_OUTCOME_V2_NAMESPACE_END
66 #include "std_result.hpp"
69 // ADL injection of outcome_throw_as_system_error_with_payload
74 inline void outcome_throw_as_system_error_with_payload(const error_code &error) { BOOST_OUTCOME_THROW_EXCEPTION(system_error(error)); }
77 BOOST_OUTCOME_TEMPLATE(class Error)
78 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(is_error_code_enum<std::decay_t<Error>>::value || is_error_condition_enum<std::decay_t<Error>>::value))
79 inline void outcome_throw_as_system_error_with_payload(Error &&error) { BOOST_OUTCOME_THROW_EXCEPTION(system_error(make_error_code(error))); }
84 BOOST_OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
88 // Customise _set_error_is_errno
89 template <class State> constexpr inline void _set_error_is_errno(State &state, const boost::system::error_code &error)
91 if(error.category() == boost::system::generic_category()
93 || error.category() == boost::system::system_category()
97 state._status |= status_error_is_errno;
100 template <class State> constexpr inline void _set_error_is_errno(State &state, const boost::system::error_condition &error)
102 if(error.category() == boost::system::generic_category()
104 || error.category() == boost::system::system_category()
108 state._status |= status_error_is_errno;
111 template <class State> constexpr inline void _set_error_is_errno(State &state, const boost::system::errc::errc_t & /*unused*/) { state._status |= status_error_is_errno; }
113 } // namespace detail
115 /*! AWAITING HUGO JSON CONVERSION TOOL
116 SIGNATURE NOT RECOGNISED
122 // Shortcut these for lower build impact
123 template <> struct _is_error_code_available<boost::system::error_code>
125 static constexpr bool value = true;
126 using type = boost::system::error_code;
128 template <> struct _is_exception_ptr_available<boost::exception_ptr>
130 static constexpr bool value = true;
131 using type = boost::exception_ptr;
133 } // namespace detail
135 // boost::system::error_code is an error type
136 template <> struct is_error_type<boost::system::error_code>
138 static constexpr bool value = true;
140 // boost::system::error_code::errc_t is an error type
141 template <> struct is_error_type<boost::system::errc::errc_t>
143 static constexpr bool value = true;
145 // boost::exception_ptr is an error types
146 template <> struct is_error_type<boost::exception_ptr>
148 static constexpr bool value = true;
150 // For boost::system::error_code, boost::system::is_error_condition_enum<> is the trait we want.
151 template <class Enum> struct is_error_type_enum<boost::system::error_code, Enum>
153 static constexpr bool value = boost::system::is_error_condition_enum<Enum>::value;
159 /*! AWAITING HUGO JSON CONVERSION TOOL
160 SIGNATURE NOT RECOGNISED
162 template <class R, class S = boost::system::error_code, class NoValuePolicy = policy::default_policy<R, S, void>> //
163 using boost_result = basic_result<R, S, NoValuePolicy>;
165 /*! AWAITING HUGO JSON CONVERSION TOOL
166 type alias template <class R, class S = boost::system::error_code> boost_unchecked. Potential doc page: `boost_unchecked<T, E = boost::system::error_code>`
168 template <class R, class S = boost::system::error_code> using boost_unchecked = boost_result<R, S, policy::all_narrow>;
170 /*! AWAITING HUGO JSON CONVERSION TOOL
171 type alias template <class R, class S = boost::system::error_code> boost_checked. Potential doc page: `boost_checked<T, E = boost::system::error_code>`
173 template <class R, class S = boost::system::error_code> using boost_checked = boost_result<R, S, policy::throw_bad_result_access<S, void>>;
175 BOOST_OUTCOME_V2_NAMESPACE_END