/* A very simple result type (C) 2017-2019 Niall Douglas (14 commits) File Created: June 2017 Boost Software License - Version 1.0 - August 17th, 2003 Permission is hereby granted, free of charge, to any person or organization obtaining a copy of the software and accompanying documentation covered by this license (the "Software") to use, reproduce, display, distribute, execute, and transmit the Software, and to prepare derivative works of the Software, and to permit third-parties to whom the Software is furnished to do so, all subject to the following: The copyright notices in the Software and this entire statement, including the above license grant, this restriction and the following disclaimer, must be included in all copies of the Software, in whole or in part, and all derivative works of the Software, unless such copies or derivative works are solely in the form of machine-executable object code generated by a source language processor. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #ifndef BOOST_OUTCOME_BASIC_RESULT_HPP #define BOOST_OUTCOME_BASIC_RESULT_HPP #include "config.hpp" #include "convert.hpp" #include "detail/basic_result_final.hpp" #include "policy/all_narrow.hpp" #include "policy/terminate.hpp" #ifdef __clang__ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" // Standardese markup confuses clang #endif BOOST_OUTCOME_V2_NAMESPACE_EXPORT_BEGIN template // #if !defined(__GNUC__) || __GNUC__ >= 10 // GCC's constraints implementation is buggy BOOST_OUTCOME_REQUIRES(trait::type_can_be_used_in_basic_result &&trait::type_can_be_used_in_basic_result && (std::is_void::value || std::is_default_constructible::value)) // #endif class basic_result; namespace detail { // These are reused by basic_outcome to save load on the compiler template struct result_predicates { // Predicate for the implicit constructors to be available. Weakened to allow result. static constexpr bool implicit_constructors_enabled = // !(trait::is_error_type>::value && trait::is_error_type>::value) // both value and error types are not whitelisted error types && ((!detail::is_implicitly_constructible && !detail::is_implicitly_constructible) // if value and error types cannot be constructed into one another || (trait::is_error_type>::value // if error type is a whitelisted error type && !detail::is_implicitly_constructible // AND which cannot be constructed from the value type && std::is_integral::value)); // AND the value type is some integral type // Predicate for the value converting constructor to be available. Weakened to allow result. template static constexpr bool enable_value_converting_constructor = // implicit_constructors_enabled // && !is_in_place_type_t>::value // not in place construction && !trait::is_error_type_enum>::value // not an enum valid for my error type && ((detail::is_implicitly_constructible && !detail::is_implicitly_constructible) // is unambiguously for value type || (std::is_same>::value // OR is my value type exactly && detail::is_implicitly_constructible) ); // and my value type is constructible from this ref form of T // Predicate for the error converting constructor to be available. Weakened to allow result. template static constexpr bool enable_error_converting_constructor = // implicit_constructors_enabled // && !is_in_place_type_t>::value // not in place construction && !trait::is_error_type_enum>::value // not an enum valid for my error type && ((!detail::is_implicitly_constructible && detail::is_implicitly_constructible) // is unambiguously for error type || (std::is_same>::value // OR is my error type exactly && detail::is_implicitly_constructible) ); // and my error type is constructible from this ref form of T // Predicate for the error condition converting constructor to be available. template static constexpr bool enable_error_condition_converting_constructor = // !is_in_place_type_t>::value // not in place construction && trait::is_error_type_enum>::value // is an error condition enum /*&& !detail::is_implicitly_constructible && !detail::is_implicitly_constructible*/; // not constructible via any other means // Predicate for the converting constructor from a compatible input to be available. template static constexpr bool enable_compatible_conversion = // (std::is_void::value || detail::is_explicitly_constructible::value_type>) // if our value types are constructible &&(std::is_void::value || detail::is_explicitly_constructible::error_type>) // if our error types are constructible ; // Predicate for the converting constructor from a make_error_code() of the input to be available. template static constexpr bool enable_make_error_code_compatible_conversion = // trait::is_error_code_available>::value // if error type has an error code && !enable_compatible_conversion // and the normal compatible conversion is not available && (std::is_void::value || detail::is_explicitly_constructible::value_type>) // and if our value types are constructible &&detail::is_explicitly_constructible::type>; // and our error type is constructible from a make_error_code() // Predicate for the converting constructor from a make_exception_ptr() of the input to be available. template static constexpr bool enable_make_exception_ptr_compatible_conversion = // trait::is_exception_ptr_available>::value // if error type has an exception ptr && !enable_compatible_conversion // and the normal compatible conversion is not available && (std::is_void::value || detail::is_explicitly_constructible::value_type>) // and if our value types are constructible &&detail::is_explicitly_constructible::type>; // and our error type is constructible from a make_exception_ptr() // Predicate for the implicit converting inplace constructor from a compatible input to be available. struct disable_inplace_value_error_constructor; template using choose_inplace_value_error_constructor = std::conditional_t< // std::is_constructible::value && std::is_constructible::value, // disable_inplace_value_error_constructor, // std::conditional_t< // std::is_constructible::value, // value_type, // std::conditional_t< // std::is_constructible::value, // error_type, // disable_inplace_value_error_constructor>>>; template static constexpr bool enable_inplace_value_error_constructor = implicit_constructors_enabled // && !std::is_same, disable_inplace_value_error_constructor>::value; }; template constexpr inline const U &extract_value_from_success(const success_type &v) { return v.value(); } template constexpr inline U &&extract_value_from_success(success_type &&v) { return static_cast &&>(v).value(); } template constexpr inline T extract_value_from_success(const success_type & /*unused*/) { return T{}; } template constexpr inline const U &extract_error_from_failure(const failure_type &v) { return v.error(); } template constexpr inline U &&extract_error_from_failure(failure_type &&v) { return static_cast &&>(v).error(); } template constexpr inline T extract_error_from_failure(const failure_type & /*unused*/) { return T{}; } template struct is_basic_result { static constexpr bool value = false; }; template struct is_basic_result> { static constexpr bool value = true; }; } // namespace detail /*! AWAITING HUGO JSON CONVERSION TOOL type alias template is_basic_result. Potential doc page: `is_basic_result` */ template using is_basic_result = detail::is_basic_result>; /*! AWAITING HUGO JSON CONVERSION TOOL SIGNATURE NOT RECOGNISED */ template static constexpr bool is_basic_result_v = detail::is_basic_result>::value; /*! AWAITING HUGO JSON CONVERSION TOOL SIGNATURE NOT RECOGNISED */ namespace hooks { /*! AWAITING HUGO JSON CONVERSION TOOL SIGNATURE NOT RECOGNISED */ template constexpr inline void hook_result_construction(T * /*unused*/, U && /*unused*/) noexcept {} /*! AWAITING HUGO JSON CONVERSION TOOL SIGNATURE NOT RECOGNISED */ template constexpr inline void hook_result_copy_construction(T * /*unused*/, U && /*unused*/) noexcept {} /*! AWAITING HUGO JSON CONVERSION TOOL SIGNATURE NOT RECOGNISED */ template constexpr inline void hook_result_move_construction(T * /*unused*/, U && /*unused*/) noexcept {} /*! AWAITING HUGO JSON CONVERSION TOOL SIGNATURE NOT RECOGNISED */ template constexpr inline void hook_result_in_place_construction(T * /*unused*/, in_place_type_t /*unused*/, Args &&... /*unused*/) noexcept {} /*! AWAITING HUGO JSON CONVERSION TOOL SIGNATURE NOT RECOGNISED */ template constexpr inline uint16_t spare_storage(const detail::basic_result_final *r) noexcept { return (r->_state._status >> detail::status_2byte_shift) & 0xffff; } /*! AWAITING HUGO JSON CONVERSION TOOL SIGNATURE NOT RECOGNISED */ template constexpr inline void set_spare_storage(detail::basic_result_final *r, uint16_t v) noexcept { r->_state._status |= (v << detail::status_2byte_shift); } } // namespace hooks /*! AWAITING HUGO JSON CONVERSION TOOL type definition template basic_result. Potential doc page: `basic_result` */ template // #if !defined(__GNUC__) || __GNUC__ >= 10 // GCC's constraints implementation is buggy BOOST_OUTCOME_REQUIRES(trait::type_can_be_used_in_basic_result &&trait::type_can_be_used_in_basic_result && (std::is_void::value || std::is_default_constructible::value)) // #endif class BOOST_OUTCOME_NODISCARD basic_result : public detail::basic_result_final { static_assert(trait::type_can_be_used_in_basic_result, "The type R cannot be used in a basic_result"); static_assert(trait::type_can_be_used_in_basic_result, "The type S cannot be used in a basic_result"); static_assert(std::is_void::value || std::is_default_constructible::value, "The type S must be void or default constructible"); using base = detail::basic_result_final; struct implicit_constructors_disabled_tag { }; struct value_converting_constructor_tag { }; struct error_converting_constructor_tag { }; struct error_condition_converting_constructor_tag { }; struct explicit_valueornone_converting_constructor_tag { }; struct explicit_valueorerror_converting_constructor_tag { }; struct explicit_compatible_copy_conversion_tag { }; struct explicit_compatible_move_conversion_tag { }; struct explicit_make_error_code_compatible_copy_conversion_tag { }; struct explicit_make_error_code_compatible_move_conversion_tag { }; struct explicit_make_exception_ptr_compatible_copy_conversion_tag { }; struct explicit_make_exception_ptr_compatible_move_conversion_tag { }; public: using value_type = R; using error_type = S; using value_type_if_enabled = typename base::_value_type; using error_type_if_enabled = typename base::_error_type; template using rebind = basic_result; protected: // Requirement predicates for result. struct predicate { using base = detail::result_predicates; // Predicate for any constructors to be available at all static constexpr bool constructors_enabled = !std::is_same, std::decay_t>::value; // Predicate for implicit constructors to be available at all static constexpr bool implicit_constructors_enabled = constructors_enabled && base::implicit_constructors_enabled; // Predicate for the value converting constructor to be available. template static constexpr bool enable_value_converting_constructor = // constructors_enabled // && !std::is_same, basic_result>::value // not my type && base::template enable_value_converting_constructor; // Predicate for the error converting constructor to be available. template static constexpr bool enable_error_converting_constructor = // constructors_enabled // && !std::is_same, basic_result>::value // not my type && base::template enable_error_converting_constructor; // Predicate for the error condition converting constructor to be available. template static constexpr bool enable_error_condition_converting_constructor = // constructors_enabled // && !std::is_same, basic_result>::value // not my type && base::template enable_error_condition_converting_constructor; // Predicate for the converting constructor from a compatible input to be available. template static constexpr bool enable_compatible_conversion = // constructors_enabled // && !std::is_same, basic_result>::value // not my type && base::template enable_compatible_conversion; // Predicate for the converting constructor from a make_error_code() of the input to be available. template static constexpr bool enable_make_error_code_compatible_conversion = // constructors_enabled // && !std::is_same, basic_result>::value // not my type && base::template enable_make_error_code_compatible_conversion; // Predicate for the converting constructor from a make_exception_ptr() of the input to be available. template static constexpr bool enable_make_exception_ptr_compatible_conversion = // constructors_enabled // && !std::is_same, basic_result>::value // not my type && base::template enable_make_exception_ptr_compatible_conversion; // Predicate for the inplace construction of value to be available. template static constexpr bool enable_inplace_value_constructor = // constructors_enabled // && (std::is_void::value // || std::is_constructible::value); // Predicate for the inplace construction of error to be available. template static constexpr bool enable_inplace_error_constructor = // constructors_enabled // && (std::is_void::value // || std::is_constructible::value); // Predicate for the implicit converting inplace constructor to be available. template static constexpr bool enable_inplace_value_error_constructor = // constructors_enabled // &&base::template enable_inplace_value_error_constructor; template using choose_inplace_value_error_constructor = typename base::template choose_inplace_value_error_constructor; }; public: /*! AWAITING HUGO JSON CONVERSION TOOL SIGNATURE NOT RECOGNISED */ basic_result() = delete; /*! AWAITING HUGO JSON CONVERSION TOOL SIGNATURE NOT RECOGNISED */ basic_result(basic_result && /*unused*/) = default; // NOLINT /*! AWAITING HUGO JSON CONVERSION TOOL SIGNATURE NOT RECOGNISED */ basic_result(const basic_result & /*unused*/) = default; /*! AWAITING HUGO JSON CONVERSION TOOL SIGNATURE NOT RECOGNISED */ basic_result &operator=(basic_result && /*unused*/) = default; // NOLINT /*! AWAITING HUGO JSON CONVERSION TOOL SIGNATURE NOT RECOGNISED */ basic_result &operator=(const basic_result & /*unused*/) = default; ~basic_result() = default; /*! AWAITING HUGO JSON CONVERSION TOOL SIGNATURE NOT RECOGNISED */ BOOST_OUTCOME_TEMPLATE(class Arg, class... Args) BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(!predicate::constructors_enabled && (sizeof...(Args) >= 0))) basic_result(Arg && /*unused*/, Args &&... /*unused*/) = delete; // NOLINT basic_result is NOT SUPPORTED, see docs! /*! AWAITING HUGO JSON CONVERSION TOOL SIGNATURE NOT RECOGNISED */ BOOST_OUTCOME_TEMPLATE(class T) BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED((predicate::constructors_enabled && !predicate::implicit_constructors_enabled // && (detail::is_implicitly_constructible || detail::is_implicitly_constructible) ))) basic_result(T && /*unused*/, implicit_constructors_disabled_tag /*unused*/ = implicit_constructors_disabled_tag()) = delete; // NOLINT Implicit constructors disabled, use explicit in_place_type, success() or failure(). see docs! /*! AWAITING HUGO JSON CONVERSION TOOL SIGNATURE NOT RECOGNISED */ BOOST_OUTCOME_TEMPLATE(class T) BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_value_converting_constructor)) constexpr basic_result(T &&t, value_converting_constructor_tag /*unused*/ = value_converting_constructor_tag()) noexcept(std::is_nothrow_constructible::value) // NOLINT : base{in_place_type, static_cast(t)} { using namespace hooks; hook_result_construction(this, static_cast(t)); } /*! AWAITING HUGO JSON CONVERSION TOOL SIGNATURE NOT RECOGNISED */ BOOST_OUTCOME_TEMPLATE(class T) BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_error_converting_constructor)) constexpr basic_result(T &&t, error_converting_constructor_tag /*unused*/ = error_converting_constructor_tag()) noexcept(std::is_nothrow_constructible::value) // NOLINT : base{in_place_type, static_cast(t)} { using namespace hooks; hook_result_construction(this, static_cast(t)); } /*! AWAITING HUGO JSON CONVERSION TOOL SIGNATURE NOT RECOGNISED */ BOOST_OUTCOME_TEMPLATE(class ErrorCondEnum) BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TEXPR(error_type(make_error_code(ErrorCondEnum()))), // BOOST_OUTCOME_TPRED(predicate::template enable_error_condition_converting_constructor)) constexpr basic_result(ErrorCondEnum &&t, error_condition_converting_constructor_tag /*unused*/ = error_condition_converting_constructor_tag()) noexcept(noexcept(error_type(make_error_code(static_cast(t))))) // NOLINT : base{in_place_type, make_error_code(t)} { using namespace hooks; hook_result_construction(this, static_cast(t)); } /*! AWAITING HUGO JSON CONVERSION TOOL SIGNATURE NOT RECOGNISED */ BOOST_OUTCOME_TEMPLATE(class T) BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(convert::value_or_error>::enable_result_inputs || !is_basic_result_v), // BOOST_OUTCOME_TEXPR(convert::value_or_error>{}(std::declval()))) constexpr explicit basic_result(T &&o, explicit_valueorerror_converting_constructor_tag /*unused*/ = explicit_valueorerror_converting_constructor_tag()) // NOLINT : basic_result{convert::value_or_error>{}(static_cast(o))} { } /*! AWAITING HUGO JSON CONVERSION TOOL SIGNATURE NOT RECOGNISED */ BOOST_OUTCOME_TEMPLATE(class T, class U, class V) BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_compatible_conversion)) constexpr explicit basic_result(const basic_result &o, explicit_compatible_copy_conversion_tag /*unused*/ = explicit_compatible_copy_conversion_tag()) noexcept(std::is_nothrow_constructible::value &&std::is_nothrow_constructible::value) : base{typename base::compatible_conversion_tag(), o} { using namespace hooks; hook_result_copy_construction(this, o); } /*! AWAITING HUGO JSON CONVERSION TOOL SIGNATURE NOT RECOGNISED */ BOOST_OUTCOME_TEMPLATE(class T, class U, class V) BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_compatible_conversion)) constexpr explicit basic_result(basic_result &&o, explicit_compatible_move_conversion_tag /*unused*/ = explicit_compatible_move_conversion_tag()) noexcept(std::is_nothrow_constructible::value &&std::is_nothrow_constructible::value) : base{typename base::compatible_conversion_tag(), static_cast &&>(o)} { using namespace hooks; hook_result_move_construction(this, static_cast &&>(o)); } /*! AWAITING HUGO JSON CONVERSION TOOL SIGNATURE NOT RECOGNISED */ BOOST_OUTCOME_TEMPLATE(class T, class U, class V) BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_make_error_code_compatible_conversion)) constexpr explicit basic_result(const basic_result &o, explicit_make_error_code_compatible_copy_conversion_tag /*unused*/ = explicit_make_error_code_compatible_copy_conversion_tag()) noexcept(std::is_nothrow_constructible::value &&noexcept(make_error_code(std::declval()))) : base{typename base::make_error_code_compatible_conversion_tag(), o} { using namespace hooks; hook_result_copy_construction(this, o); } /*! AWAITING HUGO JSON CONVERSION TOOL SIGNATURE NOT RECOGNISED */ BOOST_OUTCOME_TEMPLATE(class T, class U, class V) BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_make_error_code_compatible_conversion)) constexpr explicit basic_result(basic_result &&o, explicit_make_error_code_compatible_move_conversion_tag /*unused*/ = explicit_make_error_code_compatible_move_conversion_tag()) noexcept(std::is_nothrow_constructible::value &&noexcept(make_error_code(std::declval()))) : base{typename base::make_error_code_compatible_conversion_tag(), static_cast &&>(o)} { using namespace hooks; hook_result_move_construction(this, static_cast &&>(o)); } /*! AWAITING HUGO JSON CONVERSION TOOL SIGNATURE NOT RECOGNISED */ BOOST_OUTCOME_TEMPLATE(class T, class U, class V) BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_make_exception_ptr_compatible_conversion)) constexpr explicit basic_result(const basic_result &o, explicit_make_exception_ptr_compatible_copy_conversion_tag /*unused*/ = explicit_make_exception_ptr_compatible_copy_conversion_tag()) noexcept(std::is_nothrow_constructible::value &&noexcept(make_exception_ptr(std::declval()))) : base{typename base::make_exception_ptr_compatible_conversion_tag(), o} { using namespace hooks; hook_result_copy_construction(this, o); } /*! AWAITING HUGO JSON CONVERSION TOOL SIGNATURE NOT RECOGNISED */ BOOST_OUTCOME_TEMPLATE(class T, class U, class V) BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_make_exception_ptr_compatible_conversion)) constexpr explicit basic_result(basic_result &&o, explicit_make_exception_ptr_compatible_move_conversion_tag /*unused*/ = explicit_make_exception_ptr_compatible_move_conversion_tag()) noexcept(std::is_nothrow_constructible::value &&noexcept(make_exception_ptr(std::declval()))) : base{typename base::make_exception_ptr_compatible_conversion_tag(), static_cast &&>(o)} { using namespace hooks; hook_result_move_construction(this, static_cast &&>(o)); } /*! AWAITING HUGO JSON CONVERSION TOOL SIGNATURE NOT RECOGNISED */ BOOST_OUTCOME_TEMPLATE(class... Args) BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_inplace_value_constructor)) constexpr explicit basic_result(in_place_type_t _, Args &&... args) noexcept(std::is_nothrow_constructible::value) : base{_, static_cast(args)...} { using namespace hooks; hook_result_in_place_construction(this, in_place_type, static_cast(args)...); } /*! AWAITING HUGO JSON CONVERSION TOOL SIGNATURE NOT RECOGNISED */ BOOST_OUTCOME_TEMPLATE(class U, class... Args) BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_inplace_value_constructor, Args...>)) constexpr explicit basic_result(in_place_type_t _, std::initializer_list il, Args &&... args) noexcept(std::is_nothrow_constructible, Args...>::value) : base{_, il, static_cast(args)...} { using namespace hooks; hook_result_in_place_construction(this, in_place_type, il, static_cast(args)...); } /*! AWAITING HUGO JSON CONVERSION TOOL SIGNATURE NOT RECOGNISED */ BOOST_OUTCOME_TEMPLATE(class... Args) BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_inplace_error_constructor)) constexpr explicit basic_result(in_place_type_t _, Args &&... args) noexcept(std::is_nothrow_constructible::value) : base{_, static_cast(args)...} { using namespace hooks; hook_result_in_place_construction(this, in_place_type, static_cast(args)...); } /*! AWAITING HUGO JSON CONVERSION TOOL SIGNATURE NOT RECOGNISED */ BOOST_OUTCOME_TEMPLATE(class U, class... Args) BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_inplace_error_constructor, Args...>)) constexpr explicit basic_result(in_place_type_t _, std::initializer_list il, Args &&... args) noexcept(std::is_nothrow_constructible, Args...>::value) : base{_, il, static_cast(args)...} { using namespace hooks; hook_result_in_place_construction(this, in_place_type, il, static_cast(args)...); } /*! AWAITING HUGO JSON CONVERSION TOOL SIGNATURE NOT RECOGNISED */ BOOST_OUTCOME_TEMPLATE(class A1, class A2, class... Args) BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_inplace_value_error_constructor)) constexpr basic_result(A1 &&a1, A2 &&a2, Args &&... args) noexcept(noexcept(typename predicate::template choose_inplace_value_error_constructor(std::declval(), std::declval(), std::declval()...))) : basic_result(in_place_type>, static_cast(a1), static_cast(a2), static_cast(args)...) { /* I was a little surprised that the below is needed given that we forward to another constructor. But it turns out that ADL only fires on the first constructor for some reason. */ using namespace hooks; // hook_result_in_place_construction(in_place_type>, this); } /*! AWAITING HUGO JSON CONVERSION TOOL SIGNATURE NOT RECOGNISED */ constexpr basic_result(const success_type &o) noexcept(std::is_nothrow_default_constructible::value) // NOLINT : base{in_place_type} { using namespace hooks; hook_result_copy_construction(this, o); } /*! AWAITING HUGO JSON CONVERSION TOOL SIGNATURE NOT RECOGNISED */ BOOST_OUTCOME_TEMPLATE(class T) BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_compatible_conversion)) constexpr basic_result(const success_type &o) noexcept(std::is_nothrow_constructible::value) // NOLINT : base{in_place_type, detail::extract_value_from_success(o)} { using namespace hooks; hook_result_copy_construction(this, o); } /*! AWAITING HUGO JSON CONVERSION TOOL SIGNATURE NOT RECOGNISED */ BOOST_OUTCOME_TEMPLATE(class T) BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(!std::is_void::value && predicate::template enable_compatible_conversion)) constexpr basic_result(success_type &&o) noexcept(std::is_nothrow_constructible::value) // NOLINT : base{in_place_type, detail::extract_value_from_success(static_cast &&>(o))} { using namespace hooks; hook_result_move_construction(this, static_cast &&>(o)); } /*! AWAITING HUGO JSON CONVERSION TOOL SIGNATURE NOT RECOGNISED */ BOOST_OUTCOME_TEMPLATE(class T) BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_compatible_conversion)) constexpr basic_result(const failure_type &o, explicit_compatible_copy_conversion_tag /*unused*/ = explicit_compatible_copy_conversion_tag()) noexcept(std::is_nothrow_constructible::value) // NOLINT : base{in_place_type, detail::extract_error_from_failure(o)} { using namespace hooks; hook_result_copy_construction(this, o); } /*! AWAITING HUGO JSON CONVERSION TOOL SIGNATURE NOT RECOGNISED */ BOOST_OUTCOME_TEMPLATE(class T) BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_compatible_conversion)) constexpr basic_result(failure_type &&o, explicit_compatible_move_conversion_tag /*unused*/ = explicit_compatible_move_conversion_tag()) noexcept(std::is_nothrow_constructible::value) // NOLINT : base{in_place_type, detail::extract_error_from_failure(static_cast &&>(o))} { using namespace hooks; hook_result_move_construction(this, static_cast &&>(o)); } /*! AWAITING HUGO JSON CONVERSION TOOL SIGNATURE NOT RECOGNISED */ BOOST_OUTCOME_TEMPLATE(class T) BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_make_error_code_compatible_conversion)) constexpr basic_result(const failure_type &o, explicit_make_error_code_compatible_copy_conversion_tag /*unused*/ = explicit_make_error_code_compatible_copy_conversion_tag()) noexcept(noexcept(make_error_code(std::declval()))) // NOLINT : base{in_place_type, make_error_code(detail::extract_error_from_failure(o))} { using namespace hooks; hook_result_copy_construction(this, o); } /*! AWAITING HUGO JSON CONVERSION TOOL SIGNATURE NOT RECOGNISED */ BOOST_OUTCOME_TEMPLATE(class T) BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_make_error_code_compatible_conversion)) constexpr basic_result(failure_type &&o, explicit_make_error_code_compatible_move_conversion_tag /*unused*/ = explicit_make_error_code_compatible_move_conversion_tag()) noexcept(noexcept(make_error_code(std::declval()))) // NOLINT : base{in_place_type, make_error_code(detail::extract_error_from_failure(static_cast &&>(o)))} { using namespace hooks; hook_result_move_construction(this, static_cast &&>(o)); } /*! AWAITING HUGO JSON CONVERSION TOOL SIGNATURE NOT RECOGNISED */ BOOST_OUTCOME_TEMPLATE(class T) BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_make_exception_ptr_compatible_conversion)) constexpr basic_result(const failure_type &o, explicit_make_exception_ptr_compatible_copy_conversion_tag /*unused*/ = explicit_make_exception_ptr_compatible_copy_conversion_tag()) noexcept(noexcept(make_exception_ptr(std::declval()))) // NOLINT : base{in_place_type, make_exception_ptr(detail::extract_error_from_failure(o))} { using namespace hooks; hook_result_copy_construction(this, o); } /*! AWAITING HUGO JSON CONVERSION TOOL SIGNATURE NOT RECOGNISED */ BOOST_OUTCOME_TEMPLATE(class T) BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TPRED(predicate::template enable_make_exception_ptr_compatible_conversion)) constexpr basic_result(failure_type &&o, explicit_make_exception_ptr_compatible_move_conversion_tag /*unused*/ = explicit_make_exception_ptr_compatible_move_conversion_tag()) noexcept(noexcept(make_exception_ptr(std::declval()))) // NOLINT : base{in_place_type, make_exception_ptr(detail::extract_error_from_failure(static_cast &&>(o)))} { using namespace hooks; hook_result_move_construction(this, static_cast &&>(o)); } /*! AWAITING HUGO JSON CONVERSION TOOL SIGNATURE NOT RECOGNISED */ constexpr void swap(basic_result &o) noexcept((std::is_void::value || detail::is_nothrow_swappable::value) // && (std::is_void::value || detail::is_nothrow_swappable::value)) { constexpr bool value_throws = !std::is_void::value && !detail::is_nothrow_swappable::value; constexpr bool error_throws = !std::is_void::value && !detail::is_nothrow_swappable::value; detail::basic_result_storage_swap(*this, o); } /*! AWAITING HUGO JSON CONVERSION TOOL SIGNATURE NOT RECOGNISED */ auto as_failure() const & { return failure(this->assume_error()); } /*! AWAITING HUGO JSON CONVERSION TOOL SIGNATURE NOT RECOGNISED */ auto as_failure() && { return failure(static_cast(*this).assume_error()); } }; /*! AWAITING HUGO JSON CONVERSION TOOL SIGNATURE NOT RECOGNISED */ template inline void swap(basic_result &a, basic_result &b) noexcept(noexcept(a.swap(b))) { a.swap(b); } #if !defined(NDEBUG) // Check is trivial in all ways except default constructibility // static_assert(std::is_trivial>::value, "result is not trivial!"); // static_assert(std::is_trivially_default_constructible>::value, "result is not trivially default constructible!"); static_assert(std::is_trivially_copyable>::value, "result is not trivially copyable!"); static_assert(std::is_trivially_assignable, basic_result>::value, "result is not trivially assignable!"); static_assert(std::is_trivially_destructible>::value, "result is not trivially destructible!"); static_assert(std::is_trivially_copy_constructible>::value, "result is not trivially copy constructible!"); static_assert(std::is_trivially_move_constructible>::value, "result is not trivially move constructible!"); static_assert(std::is_trivially_copy_assignable>::value, "result is not trivially copy assignable!"); static_assert(std::is_trivially_move_assignable>::value, "result is not trivially move assignable!"); // Also check is standard layout static_assert(std::is_standard_layout>::value, "result is not a standard layout type!"); #endif BOOST_OUTCOME_V2_NAMESPACE_END #ifdef __clang__ #pragma clang diagnostic pop #endif #endif