1 /* A very simple result type
2 (C) 2017-2022 Niall Douglas <http://www.nedproductions.biz/> (14 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_BASIC_RESULT_HPP
32 #define BOOST_OUTCOME_BASIC_RESULT_HPP
35 #include "convert.hpp"
36 #include "detail/basic_result_final.hpp"
38 #include "policy/all_narrow.hpp"
39 #include "policy/terminate.hpp"
42 #pragma clang diagnostic push
43 #pragma clang diagnostic ignored "-Wdocumentation" // Standardese markup confuses clang
46 BOOST_OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
48 template <class R, class S, class NoValuePolicy> //
53 // These are reused by basic_outcome to save load on the compiler
54 template <class value_type, class error_type> struct result_predicates
56 // Predicate for the implicit constructors to be available. Weakened to allow result<int, C enum>.
57 static constexpr bool implicit_constructors_enabled = //
58 !(trait::is_error_type<std::decay_t<value_type>>::value &&
59 trait::is_error_type<std::decay_t<error_type>>::value) // both value and error types are not whitelisted error types
60 && ((!detail::is_implicitly_constructible<value_type, error_type> &&
61 !detail::is_implicitly_constructible<error_type, value_type>) // if value and error types cannot be constructed into one another
62 || (trait::is_error_type<std::decay_t<error_type>>::value // if error type is a whitelisted error type
63 && !detail::is_implicitly_constructible<error_type, value_type> // AND which cannot be constructed from the value type
64 && std::is_integral<value_type>::value)); // AND the value type is some integral type
66 // Predicate for the value converting constructor to be available. Weakened to allow result<int, C enum>.
68 static constexpr bool enable_value_converting_constructor = //
69 implicit_constructors_enabled //
70 && !is_in_place_type_t<std::decay_t<T>>::value // not in place construction
71 && !trait::is_error_type_enum<error_type, std::decay_t<T>>::value // not an enum valid for my error type
72 && ((detail::is_implicitly_constructible<value_type, T> && !detail::is_implicitly_constructible<error_type, T>) // is unambiguously for value type
73 || (std::is_same<value_type, std::decay_t<T>>::value // OR is my value type exactly
74 && detail::is_implicitly_constructible<value_type, T>) ); // and my value type is constructible from this ref form of T
77 // Predicate for the error converting constructor to be available. Weakened to allow result<int, C enum>.
79 static constexpr bool enable_error_converting_constructor = //
80 implicit_constructors_enabled //
81 && !is_in_place_type_t<std::decay_t<T>>::value // not in place construction
82 && !trait::is_error_type_enum<error_type, std::decay_t<T>>::value // not an enum valid for my error type
83 && ((!detail::is_implicitly_constructible<value_type, T> && detail::is_implicitly_constructible<error_type, T>) // is unambiguously for error type
84 || (std::is_same<error_type, std::decay_t<T>>::value // OR is my error type exactly
85 && detail::is_implicitly_constructible<error_type, T>) ); // and my error type is constructible from this ref form of T
87 // Predicate for the error condition converting constructor to be available.
88 template <class ErrorCondEnum>
89 static constexpr bool enable_error_condition_converting_constructor = //
90 !is_in_place_type_t<std::decay_t<ErrorCondEnum>>::value // not in place construction
91 && trait::is_error_type_enum<error_type, std::decay_t<ErrorCondEnum>>::value // is an error condition enum
92 /*&& !detail::is_implicitly_constructible<value_type, ErrorCondEnum> && !detail::is_implicitly_constructible<error_type, ErrorCondEnum>*/; // not
97 // Predicate for the converting constructor from a compatible input to be available.
98 template <class T, class U, class V>
99 static constexpr bool enable_compatible_conversion = //
100 (std::is_void<T>::value ||
101 detail::is_explicitly_constructible<value_type, typename basic_result<T, U, V>::value_type>) // if our value types are constructible
102 &&(std::is_void<U>::value ||
103 detail::is_explicitly_constructible<error_type, typename basic_result<T, U, V>::error_type>) // if our error types are constructible
106 // Predicate for the converting constructor from a make_error_code() of the input to be available.
107 template <class T, class U, class V>
108 static constexpr bool enable_make_error_code_compatible_conversion = //
109 trait::is_error_code_available<std::decay_t<error_type>>::value // if error type has an error code
110 && !enable_compatible_conversion<T, U, V> // and the normal compatible conversion is not available
111 && (std::is_void<T>::value ||
112 detail::is_explicitly_constructible<value_type, typename basic_result<T, U, V>::value_type>) // and if our value types are constructible
113 &&detail::is_explicitly_constructible<error_type,
114 typename trait::is_error_code_available<U>::type>; // and our error type is constructible from a make_error_code()
116 // Predicate for the converting constructor from a make_exception_ptr() of the input to be available.
117 template <class T, class U, class V>
118 static constexpr bool enable_make_exception_ptr_compatible_conversion = //
119 trait::is_exception_ptr_available<std::decay_t<error_type>>::value // if error type has an exception ptr
120 && !enable_compatible_conversion<T, U, V> // and the normal compatible conversion is not available
121 && (std::is_void<T>::value ||
122 detail::is_explicitly_constructible<value_type, typename basic_result<T, U, V>::value_type>) // and if our value types are constructible
123 &&detail::is_explicitly_constructible<error_type, typename trait::is_exception_ptr_available<U>::type>; // and our error type is constructible from a
124 // make_exception_ptr()
126 // Predicate for the implicit converting inplace constructor from a compatible input to be available.
127 struct disable_inplace_value_error_constructor;
128 template <class... Args>
129 using choose_inplace_value_error_constructor = std::conditional_t< //
130 detail::is_constructible<value_type, Args...> && detail::is_constructible<error_type, Args...>, //
131 disable_inplace_value_error_constructor, //
132 std::conditional_t< //
133 detail::is_constructible<value_type, Args...>, //
135 std::conditional_t< //
136 detail::is_constructible<error_type, Args...>, //
138 disable_inplace_value_error_constructor>>>;
139 template <class... Args>
140 static constexpr bool enable_inplace_value_error_constructor =
141 implicit_constructors_enabled //
142 && !std::is_same<choose_inplace_value_error_constructor<Args...>, disable_inplace_value_error_constructor>::value;
145 template <class T, class U> constexpr inline const U &extract_value_from_success(const success_type<U> &v) { return v.value(); }
146 template <class T, class U> constexpr inline U &&extract_value_from_success(success_type<U> &&v) { return static_cast<success_type<U> &&>(v).value(); }
147 template <class T> constexpr inline T extract_value_from_success(const success_type<void> & /*unused*/) { return T{}; }
149 template <class T, class U, class V> constexpr inline const U &extract_error_from_failure(const failure_type<U, V> &v) { return v.error(); }
150 template <class T, class U, class V> constexpr inline U &&extract_error_from_failure(failure_type<U, V> &&v)
152 return static_cast<failure_type<U, V> &&>(v).error();
154 template <class T, class V> constexpr inline T extract_error_from_failure(const failure_type<void, V> & /*unused*/) { return T{}; }
156 template <class T> struct is_basic_result
158 static constexpr bool value = false;
160 template <class R, class S, class T> struct is_basic_result<basic_result<R, S, T>>
162 static constexpr bool value = true;
164 } // namespace detail
166 /*! AWAITING HUGO JSON CONVERSION TOOL
167 type alias template <class T> is_basic_result. Potential doc page: `is_basic_result<T>`
169 template <class T> using is_basic_result = detail::is_basic_result<std::decay_t<T>>;
170 /*! AWAITING HUGO JSON CONVERSION TOOL
171 SIGNATURE NOT RECOGNISED
173 template <class T> static constexpr bool is_basic_result_v = detail::is_basic_result<std::decay_t<T>>::value;
177 #if defined(__cpp_concepts)
178 /* The `basic_result` concept.
179 \requires That `U` matches a `basic_result`.
182 concept BOOST_OUTCOME_GCC6_CONCEPT_BOOL basic_result =
183 BOOST_OUTCOME_V2_NAMESPACE::is_basic_result<U>::value ||
184 (requires(U v) { BOOST_OUTCOME_V2_NAMESPACE::basic_result<typename U::value_type, typename U::error_type, typename U::no_value_policy_type>(v); } && //
185 detail::convertible<U, BOOST_OUTCOME_V2_NAMESPACE::basic_result<typename U::value_type, typename U::error_type, typename U::no_value_policy_type>> && //
186 detail::base_of<BOOST_OUTCOME_V2_NAMESPACE::basic_result<typename U::value_type, typename U::error_type, typename U::no_value_policy_type>, U>);
190 inline no_match match_basic_result(...);
191 template <class R, class S, class NVP, class T, //
192 typename = typename T::value_type, //
193 typename = typename T::error_type, //
194 typename = typename T::no_value_policy_type, //
195 typename std::enable_if_t<std::is_convertible<T, BOOST_OUTCOME_V2_NAMESPACE::basic_result<R, S, NVP>>::value && //
196 std::is_base_of<BOOST_OUTCOME_V2_NAMESPACE::basic_result<R, S, NVP>, T>::value,
198 inline BOOST_OUTCOME_V2_NAMESPACE::basic_result<R, S, NVP> match_basic_result(BOOST_OUTCOME_V2_NAMESPACE::basic_result<R, S, NVP> &&, T &&);
201 static constexpr bool basic_result = BOOST_OUTCOME_V2_NAMESPACE::is_basic_result<U>::value ||
202 !std::is_same<no_match, decltype(match_basic_result(std::declval<BOOST_OUTCOME_V2_NAMESPACE::detail::devoid<U>>(),
203 std::declval<BOOST_OUTCOME_V2_NAMESPACE::detail::devoid<U>>()))>::value;
204 } // namespace detail
205 /* The `basic_result` concept.
206 \requires That `U` matches a `basic_result`.
208 template <class U> static constexpr bool basic_result = detail::basic_result<U>;
210 } // namespace concepts
212 /*! AWAITING HUGO JSON CONVERSION TOOL
213 SIGNATURE NOT RECOGNISED
217 /*! AWAITING HUGO JSON CONVERSION TOOL
218 SIGNATURE NOT RECOGNISED
220 template <class R, class S, class NoValuePolicy> constexpr inline uint16_t spare_storage(const detail::basic_result_storage<R, S, NoValuePolicy> *r) noexcept
222 return r->_state._status.spare_storage_value;
224 /*! AWAITING HUGO JSON CONVERSION TOOL
225 SIGNATURE NOT RECOGNISED
227 template <class R, class S, class NoValuePolicy>
228 constexpr inline void set_spare_storage(detail::basic_result_storage<R, S, NoValuePolicy> *r, uint16_t v) noexcept
230 r->_state._status.spare_storage_value = v;
234 /*! AWAITING HUGO JSON CONVERSION TOOL
235 type definition template <class R, class S, class NoValuePolicy> basic_result. Potential doc page: `basic_result<T, E, NoValuePolicy>`
237 template <class R, class S, class NoValuePolicy> //
238 class BOOST_OUTCOME_NODISCARD basic_result : public detail::basic_result_final<R, S, NoValuePolicy>
240 static_assert(trait::type_can_be_used_in_basic_result<R>, "The type R cannot be used in a basic_result");
241 static_assert(trait::type_can_be_used_in_basic_result<S>, "The type S cannot be used in a basic_result");
243 using base = detail::basic_result_final<R, S, NoValuePolicy>;
245 struct implicit_constructors_disabled_tag
248 struct value_converting_constructor_tag
251 struct error_converting_constructor_tag
254 struct error_condition_converting_constructor_tag
257 struct explicit_valueornone_converting_constructor_tag
260 struct explicit_valueorerror_converting_constructor_tag
263 struct explicit_compatible_copy_conversion_tag
266 struct explicit_compatible_move_conversion_tag
269 struct explicit_make_error_code_compatible_copy_conversion_tag
272 struct explicit_make_error_code_compatible_move_conversion_tag
275 struct explicit_make_exception_ptr_compatible_copy_conversion_tag
278 struct explicit_make_exception_ptr_compatible_move_conversion_tag
283 using value_type = R;
284 using error_type = S;
285 using no_value_policy_type = NoValuePolicy;
287 using value_type_if_enabled = typename base::_value_type;
288 using error_type_if_enabled = typename base::_error_type;
290 template <class T, class U = S, class V = NoValuePolicy> using rebind = basic_result<T, U, V>;
293 // Requirement predicates for result.
296 using base = detail::result_predicates<value_type, error_type>;
298 // Predicate for any constructors to be available at all
299 static constexpr bool constructors_enabled = !std::is_same<std::decay_t<value_type>, std::decay_t<error_type>>::value;
301 // Predicate for implicit constructors to be available at all
302 static constexpr bool implicit_constructors_enabled = constructors_enabled && base::implicit_constructors_enabled;
304 // Predicate for the value converting constructor to be available.
306 static constexpr bool enable_value_converting_constructor = //
307 constructors_enabled //
308 && !std::is_same<std::decay_t<T>, basic_result>::value // not my type
309 && base::template enable_value_converting_constructor<T>;
311 // Predicate for the error converting constructor to be available.
313 static constexpr bool enable_error_converting_constructor = //
314 constructors_enabled //
315 && !std::is_same<std::decay_t<T>, basic_result>::value // not my type
316 && base::template enable_error_converting_constructor<T>;
318 // Predicate for the error condition converting constructor to be available.
319 template <class ErrorCondEnum>
320 static constexpr bool enable_error_condition_converting_constructor = //
321 constructors_enabled //
322 && !std::is_same<std::decay_t<ErrorCondEnum>, basic_result>::value // not my type
323 && base::template enable_error_condition_converting_constructor<ErrorCondEnum>;
325 // Predicate for the converting constructor from a compatible input to be available.
326 template <class T, class U, class V>
327 static constexpr bool enable_compatible_conversion = //
328 constructors_enabled //
329 && !std::is_same<basic_result<T, U, V>, basic_result>::value // not my type
330 && base::template enable_compatible_conversion<T, U, V>;
332 // Predicate for the converting constructor from a make_error_code() of the input to be available.
333 template <class T, class U, class V>
334 static constexpr bool enable_make_error_code_compatible_conversion = //
335 constructors_enabled //
336 && !std::is_same<basic_result<T, U, V>, basic_result>::value // not my type
337 && base::template enable_make_error_code_compatible_conversion<T, U, V>;
339 // Predicate for the converting constructor from a make_exception_ptr() of the input to be available.
340 template <class T, class U, class V>
341 static constexpr bool enable_make_exception_ptr_compatible_conversion = //
342 constructors_enabled //
343 && !std::is_same<basic_result<T, U, V>, basic_result>::value // not my type
344 && base::template enable_make_exception_ptr_compatible_conversion<T, U, V>;
346 // Predicate for the inplace construction of value to be available.
347 template <class... Args>
348 static constexpr bool enable_inplace_value_constructor = //
349 constructors_enabled //
350 && (std::is_void<value_type>::value //
351 || detail::is_constructible<value_type, Args...>);
353 // Predicate for the inplace construction of error to be available.
354 template <class... Args>
355 static constexpr bool enable_inplace_error_constructor = //
356 constructors_enabled //
357 && (std::is_void<error_type>::value //
358 || detail::is_constructible<error_type, Args...>);
360 // Predicate for the implicit converting inplace constructor to be available.
361 template <class... Args>
362 static constexpr bool enable_inplace_value_error_constructor = //
363 constructors_enabled //
364 &&base::template enable_inplace_value_error_constructor<Args...>;
365 template <class... Args> using choose_inplace_value_error_constructor = typename base::template choose_inplace_value_error_constructor<Args...>;
369 /*! AWAITING HUGO JSON CONVERSION TOOL
370 SIGNATURE NOT RECOGNISED
372 basic_result() = delete;
373 /*! AWAITING HUGO JSON CONVERSION TOOL
374 SIGNATURE NOT RECOGNISED
376 basic_result(basic_result && /*unused*/) = default; // NOLINT
377 /*! AWAITING HUGO JSON CONVERSION TOOL
378 SIGNATURE NOT RECOGNISED
380 basic_result(const basic_result & /*unused*/) = default;
381 /*! AWAITING HUGO JSON CONVERSION TOOL
382 SIGNATURE NOT RECOGNISED
384 basic_result &operator=(basic_result && /*unused*/) = default; // NOLINT
385 /*! AWAITING HUGO JSON CONVERSION TOOL
386 SIGNATURE NOT RECOGNISED
388 basic_result &operator=(const basic_result & /*unused*/) = default;
389 ~basic_result() = default;
391 /*! AWAITING HUGO JSON CONVERSION TOOL
392 SIGNATURE NOT RECOGNISED
394 BOOST_OUTCOME_TEMPLATE(class Arg, class... Args)
395 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(!predicate::constructors_enabled && (sizeof...(Args) >= 0)))
396 basic_result(Arg && /*unused*/, Args &&... /*unused*/) = delete; // NOLINT basic_result<T, T> is NOT SUPPORTED, see docs!
398 /*! AWAITING HUGO JSON CONVERSION TOOL
399 SIGNATURE NOT RECOGNISED
401 BOOST_OUTCOME_TEMPLATE(class T)
402 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED((predicate::constructors_enabled && !predicate::implicit_constructors_enabled //
403 && (detail::is_implicitly_constructible<value_type, T> || detail::is_implicitly_constructible<error_type, T>) )))
404 basic_result(T && /*unused*/, implicit_constructors_disabled_tag /*unused*/ = implicit_constructors_disabled_tag()) =
405 delete; // NOLINT Implicit constructors disabled, use explicit in_place_type<T>, success() or failure(). see docs!
407 /*! AWAITING HUGO JSON CONVERSION TOOL
408 SIGNATURE NOT RECOGNISED
410 BOOST_OUTCOME_TEMPLATE(class T)
411 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_value_converting_constructor<T>))
412 constexpr basic_result(T &&t, value_converting_constructor_tag /*unused*/ = value_converting_constructor_tag()) noexcept(
413 detail::is_nothrow_constructible<value_type, T>) // NOLINT
414 : base{in_place_type<typename base::value_type>, static_cast<T &&>(t)}
416 no_value_policy_type::on_result_construction(this, static_cast<T &&>(t));
418 /*! AWAITING HUGO JSON CONVERSION TOOL
419 SIGNATURE NOT RECOGNISED
421 BOOST_OUTCOME_TEMPLATE(class T)
422 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_error_converting_constructor<T>))
423 constexpr basic_result(T &&t, error_converting_constructor_tag /*unused*/ = error_converting_constructor_tag()) noexcept(
424 detail::is_nothrow_constructible<error_type, T>) // NOLINT
425 : base{in_place_type<typename base::error_type>, static_cast<T &&>(t)}
427 no_value_policy_type::on_result_construction(this, static_cast<T &&>(t));
429 /*! AWAITING HUGO JSON CONVERSION TOOL
430 SIGNATURE NOT RECOGNISED
432 BOOST_OUTCOME_TEMPLATE(class ErrorCondEnum)
433 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TEXPR(error_type(make_error_code(ErrorCondEnum()))), //
434 BOOST_OUTCOME_TPRED(predicate::template enable_error_condition_converting_constructor<ErrorCondEnum>))
435 constexpr basic_result(ErrorCondEnum &&t, error_condition_converting_constructor_tag /*unused*/ = error_condition_converting_constructor_tag()) noexcept(
436 noexcept(error_type(make_error_code(static_cast<ErrorCondEnum &&>(t))))) // NOLINT
437 : base{in_place_type<typename base::error_type>, make_error_code(t)}
439 no_value_policy_type::on_result_construction(this, static_cast<ErrorCondEnum &&>(t));
442 /*! AWAITING HUGO JSON CONVERSION TOOL
443 SIGNATURE NOT RECOGNISED
445 BOOST_OUTCOME_TEMPLATE(class T)
446 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(convert::value_or_error<basic_result, std::decay_t<T>>::enable_result_inputs || !concepts::basic_result<T>), //
447 BOOST_OUTCOME_TEXPR(convert::value_or_error<basic_result, std::decay_t<T>>{}(std::declval<T>())))
448 constexpr explicit basic_result(T &&o,
449 explicit_valueorerror_converting_constructor_tag /*unused*/ = explicit_valueorerror_converting_constructor_tag()) // NOLINT
450 : basic_result{convert::value_or_error<basic_result, std::decay_t<T>>{}(static_cast<T &&>(o))}
453 /*! AWAITING HUGO JSON CONVERSION TOOL
454 SIGNATURE NOT RECOGNISED
456 BOOST_OUTCOME_TEMPLATE(class T, class U, class V)
457 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_compatible_conversion<T, U, V>))
458 constexpr explicit basic_result(
459 const basic_result<T, U, V> &o,
460 explicit_compatible_copy_conversion_tag /*unused*/ =
461 explicit_compatible_copy_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&detail::is_nothrow_constructible<error_type, U>)
462 : base{typename base::compatible_conversion_tag(), o}
464 no_value_policy_type::on_result_copy_construction(this, o);
466 /*! AWAITING HUGO JSON CONVERSION TOOL
467 SIGNATURE NOT RECOGNISED
469 BOOST_OUTCOME_TEMPLATE(class T, class U, class V)
470 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_compatible_conversion<T, U, V>))
471 constexpr explicit basic_result(
472 basic_result<T, U, V> &&o,
473 explicit_compatible_move_conversion_tag /*unused*/ =
474 explicit_compatible_move_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T> &&detail::is_nothrow_constructible<error_type, U>)
475 : base{typename base::compatible_conversion_tag(), static_cast<basic_result<T, U, V> &&>(o)}
477 no_value_policy_type::on_result_move_construction(this, static_cast<basic_result<T, U, V> &&>(o));
479 /*! AWAITING HUGO JSON CONVERSION TOOL
480 SIGNATURE NOT RECOGNISED
482 BOOST_OUTCOME_TEMPLATE(class T, class U, class V)
483 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_make_error_code_compatible_conversion<T, U, V>))
484 constexpr explicit basic_result(const basic_result<T, U, V> &o,
485 explicit_make_error_code_compatible_copy_conversion_tag /*unused*/ =
486 explicit_make_error_code_compatible_copy_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T>
487 &&noexcept(make_error_code(std::declval<U>())))
488 : base{typename base::make_error_code_compatible_conversion_tag(), o}
490 no_value_policy_type::on_result_copy_construction(this, o);
492 /*! AWAITING HUGO JSON CONVERSION TOOL
493 SIGNATURE NOT RECOGNISED
495 BOOST_OUTCOME_TEMPLATE(class T, class U, class V)
496 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_make_error_code_compatible_conversion<T, U, V>))
497 constexpr explicit basic_result(basic_result<T, U, V> &&o,
498 explicit_make_error_code_compatible_move_conversion_tag /*unused*/ =
499 explicit_make_error_code_compatible_move_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T>
500 &&noexcept(make_error_code(std::declval<U>())))
501 : base{typename base::make_error_code_compatible_conversion_tag(), static_cast<basic_result<T, U, V> &&>(o)}
503 no_value_policy_type::on_result_move_construction(this, static_cast<basic_result<T, U, V> &&>(o));
505 /*! AWAITING HUGO JSON CONVERSION TOOL
506 SIGNATURE NOT RECOGNISED
508 BOOST_OUTCOME_TEMPLATE(class T, class U, class V)
509 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_make_exception_ptr_compatible_conversion<T, U, V>))
510 constexpr explicit basic_result(const basic_result<T, U, V> &o,
511 explicit_make_exception_ptr_compatible_copy_conversion_tag /*unused*/ =
512 explicit_make_exception_ptr_compatible_copy_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T>
513 &&noexcept(make_exception_ptr(std::declval<U>())))
514 : base{typename base::make_exception_ptr_compatible_conversion_tag(), o}
516 no_value_policy_type::on_result_copy_construction(this, o);
518 /*! AWAITING HUGO JSON CONVERSION TOOL
519 SIGNATURE NOT RECOGNISED
521 BOOST_OUTCOME_TEMPLATE(class T, class U, class V)
522 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_make_exception_ptr_compatible_conversion<T, U, V>))
523 constexpr explicit basic_result(basic_result<T, U, V> &&o,
524 explicit_make_exception_ptr_compatible_move_conversion_tag /*unused*/ =
525 explicit_make_exception_ptr_compatible_move_conversion_tag()) noexcept(detail::is_nothrow_constructible<value_type, T>
526 &&noexcept(make_exception_ptr(std::declval<U>())))
527 : base{typename base::make_exception_ptr_compatible_conversion_tag(), static_cast<basic_result<T, U, V> &&>(o)}
529 no_value_policy_type::on_result_move_construction(this, static_cast<basic_result<T, U, V> &&>(o));
532 /*! AWAITING HUGO JSON CONVERSION TOOL
533 SIGNATURE NOT RECOGNISED
535 BOOST_OUTCOME_TEMPLATE(class... Args)
536 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_inplace_value_constructor<Args...>))
537 constexpr explicit basic_result(in_place_type_t<value_type_if_enabled> _, Args &&... args) noexcept(detail::is_nothrow_constructible<value_type, Args...>)
538 : base{_, static_cast<Args &&>(args)...}
540 no_value_policy_type::on_result_in_place_construction(this, in_place_type<value_type>, static_cast<Args &&>(args)...);
542 /*! AWAITING HUGO JSON CONVERSION TOOL
543 SIGNATURE NOT RECOGNISED
545 BOOST_OUTCOME_TEMPLATE(class U, class... Args)
546 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_inplace_value_constructor<std::initializer_list<U>, Args...>))
547 constexpr explicit basic_result(in_place_type_t<value_type_if_enabled> _, std::initializer_list<U> il,
548 Args &&... args) noexcept(detail::is_nothrow_constructible<value_type, std::initializer_list<U>, Args...>)
549 : base{_, il, static_cast<Args &&>(args)...}
551 no_value_policy_type::on_result_in_place_construction(this, in_place_type<value_type>, il, static_cast<Args &&>(args)...);
553 /*! AWAITING HUGO JSON CONVERSION TOOL
554 SIGNATURE NOT RECOGNISED
556 BOOST_OUTCOME_TEMPLATE(class... Args)
557 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_inplace_error_constructor<Args...>))
558 constexpr explicit basic_result(in_place_type_t<error_type_if_enabled> _, Args &&... args) noexcept(detail::is_nothrow_constructible<error_type, Args...>)
559 : base{_, static_cast<Args &&>(args)...}
561 no_value_policy_type::on_result_in_place_construction(this, in_place_type<error_type>, static_cast<Args &&>(args)...);
563 /*! AWAITING HUGO JSON CONVERSION TOOL
564 SIGNATURE NOT RECOGNISED
566 BOOST_OUTCOME_TEMPLATE(class U, class... Args)
567 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_inplace_error_constructor<std::initializer_list<U>, Args...>))
568 constexpr explicit basic_result(in_place_type_t<error_type_if_enabled> _, std::initializer_list<U> il,
569 Args &&... args) noexcept(detail::is_nothrow_constructible<error_type, std::initializer_list<U>, Args...>)
570 : base{_, il, static_cast<Args &&>(args)...}
572 no_value_policy_type::on_result_in_place_construction(this, in_place_type<error_type>, il, static_cast<Args &&>(args)...);
574 /*! AWAITING HUGO JSON CONVERSION TOOL
575 SIGNATURE NOT RECOGNISED
577 BOOST_OUTCOME_TEMPLATE(class A1, class A2, class... Args)
578 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_inplace_value_error_constructor<A1, A2, Args...>))
579 constexpr basic_result(A1 &&a1, A2 &&a2, Args &&... args) noexcept(noexcept(
580 typename predicate::template choose_inplace_value_error_constructor<A1, A2, Args...>(std::declval<A1>(), std::declval<A2>(), std::declval<Args>()...)))
581 : basic_result(in_place_type<typename predicate::template choose_inplace_value_error_constructor<A1, A2, Args...>>, static_cast<A1 &&>(a1),
582 static_cast<A2 &&>(a2), static_cast<Args &&>(args)...)
586 /*! AWAITING HUGO JSON CONVERSION TOOL
587 SIGNATURE NOT RECOGNISED
589 constexpr basic_result(const success_type<void> &o) noexcept(std::is_nothrow_default_constructible<value_type>::value) // NOLINT
590 : base{in_place_type<value_type_if_enabled>}
592 hooks::set_spare_storage(this, o.spare_storage());
593 no_value_policy_type::on_result_copy_construction(this, o);
595 /*! AWAITING HUGO JSON CONVERSION TOOL
596 SIGNATURE NOT RECOGNISED
598 BOOST_OUTCOME_TEMPLATE(class T)
599 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_compatible_conversion<T, void, void>))
600 constexpr basic_result(const success_type<T> &o) noexcept(detail::is_nothrow_constructible<value_type, T>) // NOLINT
601 : base{in_place_type<value_type_if_enabled>, detail::extract_value_from_success<value_type>(o)}
603 hooks::set_spare_storage(this, o.spare_storage());
604 no_value_policy_type::on_result_copy_construction(this, o);
606 /*! AWAITING HUGO JSON CONVERSION TOOL
607 SIGNATURE NOT RECOGNISED
609 BOOST_OUTCOME_TEMPLATE(class T)
610 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(!std::is_void<T>::value && predicate::template enable_compatible_conversion<T, void, void>))
611 constexpr basic_result(success_type<T> &&o) noexcept(detail::is_nothrow_constructible<value_type, T>) // NOLINT
612 : base{in_place_type<value_type_if_enabled>, detail::extract_value_from_success<value_type>(static_cast<success_type<T> &&>(o))}
614 hooks::set_spare_storage(this, o.spare_storage());
615 no_value_policy_type::on_result_move_construction(this, static_cast<success_type<T> &&>(o));
617 /*! AWAITING HUGO JSON CONVERSION TOOL
618 SIGNATURE NOT RECOGNISED
620 BOOST_OUTCOME_TEMPLATE(class T)
621 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_compatible_conversion<void, T, void>))
622 constexpr basic_result(const failure_type<T> &o, explicit_compatible_copy_conversion_tag /*unused*/ = explicit_compatible_copy_conversion_tag()) noexcept(
623 detail::is_nothrow_constructible<error_type, T>) // NOLINT
624 : base{in_place_type<error_type_if_enabled>, detail::extract_error_from_failure<error_type>(o)}
626 hooks::set_spare_storage(this, o.spare_storage());
627 no_value_policy_type::on_result_copy_construction(this, o);
629 /*! AWAITING HUGO JSON CONVERSION TOOL
630 SIGNATURE NOT RECOGNISED
632 BOOST_OUTCOME_TEMPLATE(class T)
633 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_compatible_conversion<void, T, void>))
634 constexpr basic_result(failure_type<T> &&o, explicit_compatible_move_conversion_tag /*unused*/ = explicit_compatible_move_conversion_tag()) noexcept(
635 detail::is_nothrow_constructible<error_type, T>) // NOLINT
636 : base{in_place_type<error_type_if_enabled>, detail::extract_error_from_failure<error_type>(static_cast<failure_type<T> &&>(o))}
638 hooks::set_spare_storage(this, o.spare_storage());
639 no_value_policy_type::on_result_move_construction(this, static_cast<failure_type<T> &&>(o));
641 /*! AWAITING HUGO JSON CONVERSION TOOL
642 SIGNATURE NOT RECOGNISED
644 BOOST_OUTCOME_TEMPLATE(class T)
645 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_make_error_code_compatible_conversion<void, T, void>))
646 constexpr basic_result(const failure_type<T> &o,
647 explicit_make_error_code_compatible_copy_conversion_tag /*unused*/ =
648 explicit_make_error_code_compatible_copy_conversion_tag()) noexcept(noexcept(make_error_code(std::declval<T>()))) // NOLINT
649 : base{in_place_type<error_type_if_enabled>, make_error_code(detail::extract_error_from_failure<error_type>(o))}
651 hooks::set_spare_storage(this, o.spare_storage());
652 no_value_policy_type::on_result_copy_construction(this, o);
654 /*! AWAITING HUGO JSON CONVERSION TOOL
655 SIGNATURE NOT RECOGNISED
657 BOOST_OUTCOME_TEMPLATE(class T)
658 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_make_error_code_compatible_conversion<void, T, void>))
659 constexpr basic_result(failure_type<T> &&o,
660 explicit_make_error_code_compatible_move_conversion_tag /*unused*/ =
661 explicit_make_error_code_compatible_move_conversion_tag()) noexcept(noexcept(make_error_code(std::declval<T>()))) // NOLINT
662 : base{in_place_type<error_type_if_enabled>, make_error_code(detail::extract_error_from_failure<error_type>(static_cast<failure_type<T> &&>(o)))}
664 hooks::set_spare_storage(this, o.spare_storage());
665 no_value_policy_type::on_result_move_construction(this, static_cast<failure_type<T> &&>(o));
667 /*! AWAITING HUGO JSON CONVERSION TOOL
668 SIGNATURE NOT RECOGNISED
670 BOOST_OUTCOME_TEMPLATE(class T)
671 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_make_exception_ptr_compatible_conversion<void, T, void>))
672 constexpr basic_result(const failure_type<T> &o,
673 explicit_make_exception_ptr_compatible_copy_conversion_tag /*unused*/ =
674 explicit_make_exception_ptr_compatible_copy_conversion_tag()) noexcept(noexcept(make_exception_ptr(std::declval<T>()))) // NOLINT
675 : base{in_place_type<error_type_if_enabled>, make_exception_ptr(detail::extract_error_from_failure<error_type>(o))}
677 hooks::set_spare_storage(this, o.spare_storage());
678 no_value_policy_type::on_result_copy_construction(this, o);
680 /*! AWAITING HUGO JSON CONVERSION TOOL
681 SIGNATURE NOT RECOGNISED
683 BOOST_OUTCOME_TEMPLATE(class T)
684 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_make_exception_ptr_compatible_conversion<void, T, void>))
685 constexpr basic_result(failure_type<T> &&o,
686 explicit_make_exception_ptr_compatible_move_conversion_tag /*unused*/ =
687 explicit_make_exception_ptr_compatible_move_conversion_tag()) noexcept(noexcept(make_exception_ptr(std::declval<T>()))) // NOLINT
688 : base{in_place_type<error_type_if_enabled>, make_exception_ptr(detail::extract_error_from_failure<error_type>(static_cast<failure_type<T> &&>(o)))}
690 hooks::set_spare_storage(this, o.spare_storage());
691 no_value_policy_type::on_result_move_construction(this, static_cast<failure_type<T> &&>(o));
694 /*! AWAITING HUGO JSON CONVERSION TOOL
695 SIGNATURE NOT RECOGNISED
697 constexpr void swap(basic_result &o) noexcept((std::is_void<value_type>::value || detail::is_nothrow_swappable<value_type>::value) //
698 && (std::is_void<error_type>::value || detail::is_nothrow_swappable<error_type>::value))
700 this->_state.swap(o._state);
703 /*! AWAITING HUGO JSON CONVERSION TOOL
704 SIGNATURE NOT RECOGNISED
706 auto as_failure() const & { return failure(this->assume_error(), hooks::spare_storage(this)); }
707 /*! AWAITING HUGO JSON CONVERSION TOOL
708 SIGNATURE NOT RECOGNISED
712 this->_state._status.set_have_moved_from(true);
713 return failure(static_cast<basic_result &&>(*this).assume_error(), hooks::spare_storage(this));
717 failure_type<error_type> _xcode_workaround_as_failure() &&;
721 /*! AWAITING HUGO JSON CONVERSION TOOL
722 SIGNATURE NOT RECOGNISED
724 template <class R, class S, class P> inline void swap(basic_result<R, S, P> &a, basic_result<R, S, P> &b) noexcept(noexcept(a.swap(b)))
730 // Check is trivial in all ways except default constructibility
731 // static_assert(std::is_trivial<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not trivial!");
732 // static_assert(std::is_trivially_default_constructible<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not trivially default
734 static_assert(std::is_trivially_copyable<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not trivially copyable!");
735 static_assert(std::is_trivially_assignable<basic_result<int, long, policy::all_narrow>, basic_result<int, long, policy::all_narrow>>::value,
736 "result<int> is not trivially assignable!");
737 static_assert(std::is_trivially_destructible<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not trivially destructible!");
738 static_assert(std::is_trivially_copy_constructible<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not trivially copy constructible!");
739 static_assert(std::is_trivially_move_constructible<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not trivially move constructible!");
740 static_assert(std::is_trivially_copy_assignable<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not trivially copy assignable!");
741 static_assert(std::is_trivially_move_assignable<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not trivially move assignable!");
742 // Also check is standard layout
743 static_assert(std::is_standard_layout<basic_result<int, long, policy::all_narrow>>::value, "result<int> is not a standard layout type!");
746 BOOST_OUTCOME_V2_NAMESPACE_END
749 #pragma clang diagnostic pop