]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/outcome/experimental/status_result.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / outcome / experimental / status_result.hpp
1 /* A very simple result type
2 (C) 2018-2019 Niall Douglas <http://www.nedproductions.biz/> (11 commits)
3 File Created: Apr 2018
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_EXPERIMENTAL_STATUS_RESULT_HPP
32 #define BOOST_OUTCOME_EXPERIMENTAL_STATUS_RESULT_HPP
33
34 #include "../basic_result.hpp"
35 #include "../policy/fail_to_compile_observers.hpp"
36
37 #include "status-code/system_error2.hpp"
38
39 BOOST_OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
40
41 namespace trait
42 {
43 namespace detail
44 {
45 // Shortcut this for lower build impact. Used to tell outcome's converting constructors
46 // that they can do E => EC or E => EP as necessary.
47 template <class DomainType> struct _is_error_code_available<BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE::status_code<DomainType>>
48 {
49 static constexpr bool value = true;
50 using type = BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE::status_code<DomainType>;
51 };
52 template <class DomainType> struct _is_error_code_available<BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE::errored_status_code<DomainType>>
53 {
54 static constexpr bool value = true;
55 using type = BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE::errored_status_code<DomainType>;
56 };
57 } // namespace detail
58 #if 0 // Do NOT enable weakened implicit construction for these types
59 template <class DomainType> struct is_error_type<BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE::status_code<DomainType>>
60 {
61 static constexpr bool value = true;
62 };
63 template <> struct is_error_type<BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE::errc>
64 {
65 static constexpr bool value = true;
66 };
67 template <class DomainType, class Enum> struct is_error_type_enum<BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE::status_code<DomainType>, Enum>
68 {
69 static constexpr bool value = boost::system::is_error_condition_enum<Enum>::value;
70 };
71 #endif
72 } // namespace trait
73
74 namespace detail
75 {
76 // Customise _set_error_is_errno
77 template <class State> constexpr inline void _set_error_is_errno(State &state, const BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE::generic_code & /*unused*/) { state._status |= status_error_is_errno; }
78 template <class State> constexpr inline void _set_error_is_errno(State &state, const BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE::posix_code & /*unused*/) { state._status |= status_error_is_errno; }
79 template <class State> constexpr inline void _set_error_is_errno(State &state, const BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE::errc & /*unused*/) { state._status |= status_error_is_errno; }
80
81 } // namespace detail
82
83 namespace experimental
84 {
85 using namespace BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE;
86 using BOOST_OUTCOME_V2_NAMESPACE::success;
87 using BOOST_OUTCOME_V2_NAMESPACE::failure;
88
89 namespace policy
90 {
91 using namespace BOOST_OUTCOME_V2_NAMESPACE::policy;
92 template <class T, class EC, class E> struct status_code_throw
93 {
94 static_assert(!std::is_same<T, T>::value, "policy::status_code_throw not specialised for these types, did you use status_result<T, status_code<DomainType>, E>?");
95 };
96 template <class T, class DomainType> struct status_code_throw<T, status_code<DomainType>, void> : base
97 {
98 using _base = base;
99 template <class Impl> static constexpr void wide_value_check(Impl &&self)
100 {
101 if(!base::_has_value(static_cast<Impl &&>(self)))
102 {
103 if(base::_has_error(static_cast<Impl &&>(self)))
104 {
105 #ifndef BOOST_NO_EXCEPTIONS
106 base::_error(static_cast<Impl &&>(self)).throw_exception();
107 #else
108 BOOST_OUTCOME_THROW_EXCEPTION("wide value check failed");
109 #endif
110 }
111 }
112 }
113 template <class Impl> static constexpr void wide_error_check(Impl &&self) { _base::narrow_error_check(static_cast<Impl &&>(self)); }
114 };
115 template <class T, class DomainType> struct status_code_throw<T, errored_status_code<DomainType>, void> : status_code_throw<T, status_code<DomainType>, void>
116 {
117 status_code_throw() = default;
118 using status_code_throw<T, status_code<DomainType>, void>::status_code_throw;
119 };
120
121 template <class T, class EC>
122 using default_status_result_policy = std::conditional_t< //
123 std::is_void<EC>::value, //
124 BOOST_OUTCOME_V2_NAMESPACE::policy::terminate, //
125 std::conditional_t<is_status_code<EC>::value || is_errored_status_code<EC>::value, //
126 status_code_throw<T, EC, void>, //
127 BOOST_OUTCOME_V2_NAMESPACE::policy::fail_to_compile_observers //
128 >>;
129 } // namespace policy
130
131 /*! AWAITING HUGO JSON CONVERSION TOOL
132 SIGNATURE NOT RECOGNISED
133 */
134 template <class R, class S = system_code, class NoValuePolicy = policy::default_status_result_policy<R, S>> //
135 using status_result = basic_result<R, S, NoValuePolicy>;
136
137 } // namespace experimental
138
139 BOOST_OUTCOME_V2_NAMESPACE_END
140
141 #endif