1/* Policies for result and outcome
2(C) 2017-2024 Niall Douglas <http://www.nedproductions.biz/> (6 commits) and Andrzej KrzemieĊ„ski <akrzemi1@gmail.com> (1 commit)
3File Created: Oct 2017
4
5
6Boost Software License - Version 1.0 - August 17th, 2003
7
8Permission is hereby granted, free of charge, to any person or organization
9obtaining a copy of the software and accompanying documentation covered by
10this license (the "Software") to use, reproduce, display, distribute,
11execute, and transmit the Software, and to prepare derivative works of the
12Software, and to permit third-parties to whom the Software is furnished to
13do so, all subject to the following:
14
15The copyright notices in the Software and this entire statement, including
16the above license grant, this restriction and the following disclaimer,
17must be included in all copies of the Software, in whole or in part, and
18all derivative works of the Software, unless such copies or derivative
19works are solely in the form of machine-executable object code generated by
20a source language processor.
21
22THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
25SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
26FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
27ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28DEALINGS IN THE SOFTWARE.
29*/
30
31#ifndef BOOST_OUTCOME_POLICY_BASE_HPP
32#define BOOST_OUTCOME_POLICY_BASE_HPP
33
34#include "../detail/value_storage.hpp"
35
36BOOST_OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
37
38#if BOOST_OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
39/*! AWAITING HUGO JSON CONVERSION TOOL
40SIGNATURE NOT RECOGNISED
41*/
42namespace hooks
43{
44 /*! AWAITING HUGO JSON CONVERSION TOOL
45SIGNATURE NOT RECOGNISED
46*/
47 template <class T, class U> constexpr inline void hook_result_construction(T * /*unused*/, U && /*unused*/) noexcept {}
48 /*! AWAITING HUGO JSON CONVERSION TOOL
49SIGNATURE NOT RECOGNISED
50*/
51 template <class T, class U> constexpr inline void hook_result_copy_construction(T * /*unused*/, U && /*unused*/) noexcept {}
52 /*! AWAITING HUGO JSON CONVERSION TOOL
53SIGNATURE NOT RECOGNISED
54*/
55 template <class T, class U> constexpr inline void hook_result_move_construction(T * /*unused*/, U && /*unused*/) noexcept {}
56 /*! AWAITING HUGO JSON CONVERSION TOOL
57SIGNATURE NOT RECOGNISED
58*/
59 template <class T, class U, class... Args>
60 constexpr inline void hook_result_in_place_construction(T * /*unused*/, in_place_type_t<U> /*unused*/, Args &&... /*unused*/) noexcept
61 {
62 }
63 /*! AWAITING HUGO JSON CONVERSION TOOL
64SIGNATURE NOT RECOGNISED
65*/
66 template <class T, class... U> constexpr inline void hook_outcome_construction(T * /*unused*/, U &&... /*unused*/) noexcept {}
67 /*! AWAITING HUGO JSON CONVERSION TOOL
68SIGNATURE NOT RECOGNISED
69*/
70 template <class T, class U> constexpr inline void hook_outcome_copy_construction(T * /*unused*/, U && /*unused*/) noexcept {}
71 /*! AWAITING HUGO JSON CONVERSION TOOL
72SIGNATURE NOT RECOGNISED
73*/
74 template <class T, class U> constexpr inline void hook_outcome_move_construction(T * /*unused*/, U && /*unused*/) noexcept {}
75 /*! AWAITING HUGO JSON CONVERSION TOOL
76SIGNATURE NOT RECOGNISED
77*/
78 template <class T, class U, class... Args>
79 constexpr inline void hook_outcome_in_place_construction(T * /*unused*/, in_place_type_t<U> /*unused*/, Args &&... /*unused*/) noexcept
80 {
81 }
82} // namespace hooks
83#endif
84
85namespace policy
86{
87 namespace detail
88 {
89 using BOOST_OUTCOME_V2_NAMESPACE::detail::make_ub;
90 }
91 /*! AWAITING HUGO JSON CONVERSION TOOL
92SIGNATURE NOT RECOGNISED
93*/
94 struct base
95 {
96 template <class... Args> static constexpr void _silence_unused(Args &&... /*unused*/) noexcept {}
97 protected:
98 template <class Impl> static constexpr void _make_ub(Impl &&self) noexcept { return detail::make_ub(static_cast<Impl &&>(self)); }
99 template <class Impl> static constexpr bool _has_value(Impl &&self) noexcept { return self._state._status.have_value(); }
100 template <class Impl> static constexpr bool _has_error(Impl &&self) noexcept { return self._state._status.have_error(); }
101 template <class Impl> static constexpr bool _has_exception(Impl &&self) noexcept { return self._state._status.have_exception(); }
102 template <class Impl> static constexpr bool _has_error_is_errno(Impl &&self) noexcept { return self._state._status.have_error_is_errno(); }
103
104 template <class Impl> static constexpr void _set_has_value(Impl &&self, bool v) noexcept { self._state._status.set_have_value(v); }
105 template <class Impl> static constexpr void _set_has_error(Impl &&self, bool v) noexcept { self._state._status.set_have_error(v); }
106 template <class Impl> static constexpr void _set_has_exception(Impl &&self, bool v) noexcept { self._state._status.set_have_exception(v); }
107 template <class Impl> static constexpr void _set_has_error_is_errno(Impl &&self, bool v) noexcept { self._state._status.set_have_error_is_errno(v); }
108
109 template <class Impl> static constexpr auto &&_value(Impl &&self) noexcept { return static_cast<Impl &&>(self)._state._value; }
110 template <class Impl> static constexpr auto &&_error(Impl &&self) noexcept { return static_cast<Impl &&>(self)._state._error; }
111
112 public:
113 template <class R, class S, class P, class NoValuePolicy, class Impl> static inline constexpr auto &&_exception(Impl &&self) noexcept;
114
115 template <class T, class U> static constexpr inline void on_result_construction(T *inst, U &&v) noexcept
116 {
117#if BOOST_OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
118 using namespace hooks;
119 hook_result_construction(inst, static_cast<U &&>(v));
120#else
121 (void) inst;
122 (void) v;
123#endif
124 }
125 template <class T, class U> static constexpr inline void on_result_copy_construction(T *inst, U &&v) noexcept
126 {
127#if BOOST_OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
128 using namespace hooks;
129 hook_result_copy_construction(inst, static_cast<U &&>(v));
130#else
131 (void) inst;
132 (void) v;
133#endif
134 }
135 template <class T, class U> static constexpr inline void on_result_move_construction(T *inst, U &&v) noexcept
136 {
137#if BOOST_OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
138 using namespace hooks;
139 hook_result_move_construction(inst, static_cast<U &&>(v));
140#else
141 (void) inst;
142 (void) v;
143#endif
144 }
145 template <class T, class U, class... Args>
146 static constexpr inline void on_result_in_place_construction(T *inst, in_place_type_t<U> _, Args &&... args) noexcept
147 {
148#if BOOST_OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
149 using namespace hooks;
150 hook_result_in_place_construction(inst, _, static_cast<Args &&>(args)...);
151#else
152 (void) inst;
153 (void) _;
154 _silence_unused(static_cast<Args &&>(args)...);
155#endif
156 }
157
158 template <class T, class... U> static constexpr inline void on_outcome_construction(T *inst, U &&... args) noexcept
159 {
160#if BOOST_OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
161 using namespace hooks;
162 hook_outcome_construction(inst, static_cast<U &&>(args)...);
163#else
164 (void) inst;
165 _silence_unused(static_cast<U &&>(args)...);
166#endif
167 }
168 template <class T, class U> static constexpr inline void on_outcome_copy_construction(T *inst, U &&v) noexcept
169 {
170#if BOOST_OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
171 using namespace hooks;
172 hook_outcome_copy_construction(inst, static_cast<U &&>(v));
173#else
174 (void) inst;
175 (void) v;
176#endif
177 }
178 template <class T, class U> static constexpr inline void on_outcome_move_construction(T *inst, U &&v) noexcept
179 {
180#if BOOST_OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
181 using namespace hooks;
182 hook_outcome_move_construction(inst, static_cast<U &&>(v));
183#else
184 (void) inst;
185 (void) v;
186#endif
187 }
188 template <class T, class U, class... Args>
189 static constexpr inline void on_outcome_in_place_construction(T *inst, in_place_type_t<U> _, Args &&... args) noexcept
190 {
191#if BOOST_OUTCOME_ENABLE_LEGACY_SUPPORT_FOR < 220
192 using namespace hooks;
193 hook_outcome_in_place_construction(inst, _, static_cast<Args &&>(args)...);
194#else
195 (void) inst;
196 (void) _;
197 _silence_unused(static_cast<Args &&>(args)...);
198#endif
199 }
200
201 template <class Impl> static constexpr void narrow_value_check(Impl &&self) noexcept
202 {
203 if(!_has_value(self))
204 {
205 _make_ub(self);
206 }
207 }
208 template <class Impl> static constexpr void narrow_error_check(Impl &&self) noexcept
209 {
210 if(!_has_error(self))
211 {
212 _make_ub(self);
213 }
214 }
215 template <class Impl> static constexpr void narrow_exception_check(Impl &&self) noexcept
216 {
217 if(!_has_exception(self))
218 {
219 _make_ub(self);
220 }
221 }
222 };
223} // namespace policy
224
225BOOST_OUTCOME_V2_NAMESPACE_END
226
227#endif
228

source code of boost/libs/outcome/include/boost/outcome/policy/base.hpp