]>
Commit | Line | Data |
---|---|---|
92f5a8d4 | 1 | /* A very simple result type |
f67539c2 | 2 | (C) 2017-2020 Niall Douglas <http://www.nedproductions.biz/> (10 commits) |
92f5a8d4 TL |
3 | File Created: June 2017 |
4 | ||
5 | ||
6 | Boost Software License - Version 1.0 - August 17th, 2003 | |
7 | ||
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: | |
14 | ||
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. | |
21 | ||
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. | |
29 | */ | |
30 | ||
31 | #ifndef BOOST_OUTCOME_BOOST_RESULT_HPP | |
32 | #define BOOST_OUTCOME_BOOST_RESULT_HPP | |
33 | ||
34 | #include "config.hpp" | |
35 | ||
92f5a8d4 | 36 | #include "boost/system/system_error.hpp" |
20effc67 TL |
37 | #include "boost/exception_ptr.hpp" |
38 | #include "boost/version.hpp" | |
92f5a8d4 TL |
39 | |
40 | BOOST_OUTCOME_V2_NAMESPACE_EXPORT_BEGIN | |
41 | ||
f67539c2 | 42 | /*! AWAITING HUGO JSON CONVERSION TOOL |
92f5a8d4 TL |
43 | SIGNATURE NOT RECOGNISED |
44 | */ | |
45 | namespace policy | |
46 | { | |
47 | namespace detail | |
48 | { | |
49 | /* Pass through `make_error_code` function for `boost::system::error_code`. | |
50 | */ | |
51 | inline boost::system::error_code make_error_code(boost::system::error_code v) { return v; } | |
52 | ||
53 | /* Pass through `make_exception_ptr` function for `boost::exception_ptr`. | |
f67539c2 | 54 | */ |
92f5a8d4 TL |
55 | inline boost::exception_ptr make_exception_ptr(boost::exception_ptr v) { return v; } |
56 | } // namespace detail | |
57 | } // namespace policy | |
58 | BOOST_OUTCOME_V2_NAMESPACE_END | |
59 | ||
60 | #include "std_result.hpp" | |
61 | ||
62 | ||
63 | // ADL injection of outcome_throw_as_system_error_with_payload | |
64 | namespace boost | |
65 | { | |
66 | namespace system | |
67 | { | |
68 | inline void outcome_throw_as_system_error_with_payload(const error_code &error) { BOOST_OUTCOME_THROW_EXCEPTION(system_error(error)); } | |
69 | namespace errc | |
70 | { | |
71 | BOOST_OUTCOME_TEMPLATE(class Error) | |
72 | BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(is_error_code_enum<std::decay_t<Error>>::value || is_error_condition_enum<std::decay_t<Error>>::value)) | |
73 | inline void outcome_throw_as_system_error_with_payload(Error &&error) { BOOST_OUTCOME_THROW_EXCEPTION(system_error(make_error_code(error))); } | |
74 | } // namespace errc | |
75 | } // namespace system | |
76 | } // namespace boost | |
77 | ||
78 | BOOST_OUTCOME_V2_NAMESPACE_EXPORT_BEGIN | |
79 | ||
80 | namespace detail | |
81 | { | |
82 | // Customise _set_error_is_errno | |
83 | template <class State> constexpr inline void _set_error_is_errno(State &state, const boost::system::error_code &error) | |
84 | { | |
85 | if(error.category() == boost::system::generic_category() | |
86 | #ifndef _WIN32 | |
87 | || error.category() == boost::system::system_category() | |
88 | #endif | |
89 | ) | |
90 | { | |
f67539c2 | 91 | state._status.set_have_error_is_errno(true); |
92f5a8d4 TL |
92 | } |
93 | } | |
94 | template <class State> constexpr inline void _set_error_is_errno(State &state, const boost::system::error_condition &error) | |
95 | { | |
96 | if(error.category() == boost::system::generic_category() | |
97 | #ifndef _WIN32 | |
98 | || error.category() == boost::system::system_category() | |
99 | #endif | |
100 | ) | |
101 | { | |
f67539c2 | 102 | state._status.set_have_error_is_errno(true); |
92f5a8d4 TL |
103 | } |
104 | } | |
f67539c2 TL |
105 | template <class State> constexpr inline void _set_error_is_errno(State &state, const boost::system::errc::errc_t & /*unused*/) |
106 | { | |
107 | state._status.set_have_error_is_errno(true); | |
108 | } | |
92f5a8d4 TL |
109 | |
110 | } // namespace detail | |
111 | ||
f67539c2 | 112 | /*! AWAITING HUGO JSON CONVERSION TOOL |
92f5a8d4 TL |
113 | SIGNATURE NOT RECOGNISED |
114 | */ | |
115 | namespace trait | |
116 | { | |
117 | namespace detail | |
118 | { | |
119 | // Shortcut these for lower build impact | |
120 | template <> struct _is_error_code_available<boost::system::error_code> | |
121 | { | |
122 | static constexpr bool value = true; | |
123 | using type = boost::system::error_code; | |
124 | }; | |
125 | template <> struct _is_exception_ptr_available<boost::exception_ptr> | |
126 | { | |
127 | static constexpr bool value = true; | |
128 | using type = boost::exception_ptr; | |
129 | }; | |
130 | } // namespace detail | |
131 | ||
132 | // boost::system::error_code is an error type | |
133 | template <> struct is_error_type<boost::system::error_code> | |
134 | { | |
135 | static constexpr bool value = true; | |
136 | }; | |
137 | // boost::system::error_code::errc_t is an error type | |
138 | template <> struct is_error_type<boost::system::errc::errc_t> | |
139 | { | |
140 | static constexpr bool value = true; | |
141 | }; | |
142 | // boost::exception_ptr is an error types | |
143 | template <> struct is_error_type<boost::exception_ptr> | |
144 | { | |
145 | static constexpr bool value = true; | |
146 | }; | |
147 | // For boost::system::error_code, boost::system::is_error_condition_enum<> is the trait we want. | |
148 | template <class Enum> struct is_error_type_enum<boost::system::error_code, Enum> | |
149 | { | |
150 | static constexpr bool value = boost::system::is_error_condition_enum<Enum>::value; | |
151 | }; | |
152 | ||
153 | } // namespace trait | |
154 | ||
155 | ||
f67539c2 | 156 | /*! AWAITING HUGO JSON CONVERSION TOOL |
92f5a8d4 TL |
157 | SIGNATURE NOT RECOGNISED |
158 | */ | |
159 | template <class R, class S = boost::system::error_code, class NoValuePolicy = policy::default_policy<R, S, void>> // | |
160 | using boost_result = basic_result<R, S, NoValuePolicy>; | |
161 | ||
f67539c2 | 162 | /*! AWAITING HUGO JSON CONVERSION TOOL |
92f5a8d4 TL |
163 | type alias template <class R, class S = boost::system::error_code> boost_unchecked. Potential doc page: `boost_unchecked<T, E = boost::system::error_code>` |
164 | */ | |
165 | template <class R, class S = boost::system::error_code> using boost_unchecked = boost_result<R, S, policy::all_narrow>; | |
166 | ||
f67539c2 | 167 | /*! AWAITING HUGO JSON CONVERSION TOOL |
92f5a8d4 TL |
168 | type alias template <class R, class S = boost::system::error_code> boost_checked. Potential doc page: `boost_checked<T, E = boost::system::error_code>` |
169 | */ | |
170 | template <class R, class S = boost::system::error_code> using boost_checked = boost_result<R, S, policy::throw_bad_result_access<S, void>>; | |
171 | ||
172 | BOOST_OUTCOME_V2_NAMESPACE_END | |
173 | ||
174 | #endif |