File indexing completed on 2025-12-16 09:59:08
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 #ifndef BOOST_OUTCOME_BASIC_RESULT_FINAL_HPP
0032 #define BOOST_OUTCOME_BASIC_RESULT_FINAL_HPP
0033
0034 #include "basic_result_error_observers.hpp"
0035 #include "basic_result_value_observers.hpp"
0036
0037 BOOST_OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
0038
0039 namespace detail
0040 {
0041 template <class R, class EC, class NoValuePolicy> using select_basic_result_impl = basic_result_error_observers<basic_result_value_observers<basic_result_storage<R, EC, NoValuePolicy>, R, NoValuePolicy>, EC, NoValuePolicy>;
0042
0043 template <class R, class S, class NoValuePolicy>
0044 class basic_result_final
0045 #if defined(BOOST_OUTCOME_DOXYGEN_IS_IN_THE_HOUSE)
0046 : public basic_result_error_observers<basic_result_value_observers<basic_result_storage<R, S, NoValuePolicy>, R, NoValuePolicy>, S, NoValuePolicy>
0047 #else
0048 : public select_basic_result_impl<R, S, NoValuePolicy>
0049 #endif
0050 {
0051 using base = select_basic_result_impl<R, S, NoValuePolicy>;
0052
0053 public:
0054 using base::base;
0055
0056 constexpr explicit operator bool() const noexcept { return this->_state._status.have_value(); }
0057 constexpr bool has_value() const noexcept { return this->_state._status.have_value(); }
0058 constexpr bool has_error() const noexcept { return this->_state._status.have_error(); }
0059 constexpr bool has_exception() const noexcept { return this->_state._status.have_exception(); }
0060 constexpr bool has_lost_consistency() const noexcept { return this->_state._status.have_lost_consistency(); }
0061 constexpr bool has_failure() const noexcept { return this->_state._status.have_error() || this->_state._status.have_exception(); }
0062
0063 BOOST_OUTCOME_TEMPLATE(class T, class U, class V)
0064 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TEXPR(std::declval<detail::devoid<R>>() == std::declval<detail::devoid<T>>()),
0065 BOOST_OUTCOME_TEXPR(std::declval<detail::devoid<S>>() == std::declval<detail::devoid<U>>()))
0066 constexpr bool operator==(const basic_result_final<T, U, V> &o) const noexcept(
0067 noexcept(std::declval<detail::devoid<R>>() == std::declval<detail::devoid<T>>()) && noexcept(std::declval<detail::devoid<S>>() == std::declval<detail::devoid<U>>()))
0068 {
0069 if(this->_state._status.have_value() && o._state._status.have_value())
0070 {
0071 return this->_state._value == o._state._value;
0072 }
0073 if(this->_state._status.have_error() && o._state._status.have_error())
0074 {
0075 return this->_state._error == o._state._error;
0076 }
0077 return false;
0078 }
0079 BOOST_OUTCOME_TEMPLATE(class T)
0080 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TEXPR(std::declval<R>() == std::declval<T>()))
0081 constexpr bool operator==(const success_type<T> &o) const noexcept(
0082 noexcept(std::declval<R>() == std::declval<T>()))
0083 {
0084 if(this->_state._status.have_value())
0085 {
0086 return this->_state._value == o.value();
0087 }
0088 return false;
0089 }
0090 constexpr bool operator==(const success_type<void> &o) const noexcept
0091 {
0092 (void) o;
0093 return this->_state._status.have_value();
0094 }
0095 BOOST_OUTCOME_TEMPLATE(class T)
0096 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TEXPR(std::declval<S>() == std::declval<T>()))
0097 constexpr bool operator==(const failure_type<T, void> &o) const noexcept(
0098 noexcept(std::declval<S>() == std::declval<T>()))
0099 {
0100 if(this->_state._status.have_error())
0101 {
0102 return this->_state._error == o.error();
0103 }
0104 return false;
0105 }
0106 BOOST_OUTCOME_TEMPLATE(class T, class U, class V)
0107 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TEXPR(std::declval<detail::devoid<R>>() != std::declval<detail::devoid<T>>()),
0108 BOOST_OUTCOME_TEXPR(std::declval<detail::devoid<S>>() != std::declval<detail::devoid<U>>()))
0109 constexpr bool operator!=(const basic_result_final<T, U, V> &o) const noexcept(
0110 noexcept(std::declval<detail::devoid<R>>() != std::declval<detail::devoid<T>>()) && noexcept(std::declval<detail::devoid<S>>() != std::declval<detail::devoid<U>>()))
0111 {
0112 if(this->_state._status.have_value() && o._state._status.have_value())
0113 {
0114 return this->_state._value != o._state._value;
0115 }
0116 if(this->_state._status.have_error() && o._state._status.have_error())
0117 {
0118 return this->_state._error != o._state._error;
0119 }
0120 return true;
0121 }
0122 BOOST_OUTCOME_TEMPLATE(class T)
0123 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TEXPR(std::declval<R>() != std::declval<T>()))
0124 constexpr bool operator!=(const success_type<T> &o) const noexcept(
0125 noexcept(std::declval<R>() != std::declval<T>()))
0126 {
0127 if(this->_state._status.have_value())
0128 {
0129 return this->_state._value != o.value();
0130 }
0131 return false;
0132 }
0133 constexpr bool operator!=(const success_type<void> &o) const noexcept
0134 {
0135 (void) o;
0136 return !this->_state._status.have_value();
0137 }
0138 BOOST_OUTCOME_TEMPLATE(class T)
0139 BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TEXPR(std::declval<S>() != std::declval<T>()))
0140 constexpr bool operator!=(const failure_type<T, void> &o) const noexcept(
0141 noexcept(std::declval<S>() != std::declval<T>()))
0142 {
0143 if(this->_state._status.have_error())
0144 {
0145 return this->_state._error != o.error();
0146 }
0147 return true;
0148 }
0149 };
0150 template <class T, class U, class V, class W> constexpr inline bool operator==(const success_type<W> &a, const basic_result_final<T, U, V> &b) noexcept(noexcept(b == a)) { return b == a; }
0151 template <class T, class U, class V, class W> constexpr inline bool operator==(const failure_type<W, void> &a, const basic_result_final<T, U, V> &b) noexcept(noexcept(b == a)) { return b == a; }
0152 template <class T, class U, class V, class W> constexpr inline bool operator!=(const success_type<W> &a, const basic_result_final<T, U, V> &b) noexcept(noexcept(b == a)) { return b != a; }
0153 template <class T, class U, class V, class W> constexpr inline bool operator!=(const failure_type<W, void> &a, const basic_result_final<T, U, V> &b) noexcept(noexcept(b == a)) { return b != a; }
0154 }
0155
0156 BOOST_OUTCOME_V2_NAMESPACE_END
0157
0158 #endif