123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- #ifndef BOOST_OUTCOME_BASIC_RESULT_FINAL_HPP
- #define BOOST_OUTCOME_BASIC_RESULT_FINAL_HPP
- #include "basic_result_error_observers.hpp"
- #include "basic_result_value_observers.hpp"
- BOOST_OUTCOME_V2_NAMESPACE_EXPORT_BEGIN
- namespace detail
- {
- 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>;
- template <class R, class S, class NoValuePolicy>
- class basic_result_final
- #if defined(BOOST_OUTCOME_DOXYGEN_IS_IN_THE_HOUSE)
- : public basic_result_error_observers<basic_result_value_observers<basic_result_storage<R, S, NoValuePolicy>, R, NoValuePolicy>, S, NoValuePolicy>
- #else
- : public select_basic_result_impl<R, S, NoValuePolicy>
- #endif
- {
- using base = select_basic_result_impl<R, S, NoValuePolicy>;
- public:
- using base::base;
- constexpr explicit operator bool() const noexcept { return this->_state._status.have_value(); }
- constexpr bool has_value() const noexcept { return this->_state._status.have_value(); }
- constexpr bool has_error() const noexcept { return this->_state._status.have_error(); }
- constexpr bool has_exception() const noexcept { return this->_state._status.have_exception(); }
- constexpr bool has_lost_consistency() const noexcept { return this->_state._status.have_lost_consistency(); }
- constexpr bool has_failure() const noexcept { return this->_state._status.have_error() || this->_state._status.have_exception(); }
- BOOST_OUTCOME_TEMPLATE(class T, class U, class V)
- BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TEXPR(std::declval<detail::devoid<R>>() == std::declval<detail::devoid<T>>()),
- BOOST_OUTCOME_TEXPR(std::declval<detail::devoid<S>>() == std::declval<detail::devoid<U>>()))
- constexpr bool operator==(const basic_result_final<T, U, V> &o) const noexcept(
- noexcept(std::declval<detail::devoid<R>>() == std::declval<detail::devoid<T>>()) && noexcept(std::declval<detail::devoid<S>>() == std::declval<detail::devoid<U>>()))
- {
- if(this->_state._status.have_value() && o._state._status.have_value())
- {
- return this->_state._value == o._state._value;
- }
- if(this->_state._status.have_error() && o._state._status.have_error())
- {
- return this->_state._error == o._state._error;
- }
- return false;
- }
- BOOST_OUTCOME_TEMPLATE(class T)
- BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TEXPR(std::declval<R>() == std::declval<T>()))
- constexpr bool operator==(const success_type<T> &o) const noexcept(
- noexcept(std::declval<R>() == std::declval<T>()))
- {
- if(this->_state._status.have_value())
- {
- return this->_state._value == o.value();
- }
- return false;
- }
- constexpr bool operator==(const success_type<void> &o) const noexcept
- {
- (void) o;
- return this->_state._status.have_value();
- }
- BOOST_OUTCOME_TEMPLATE(class T)
- BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TEXPR(std::declval<S>() == std::declval<T>()))
- constexpr bool operator==(const failure_type<T, void> &o) const noexcept(
- noexcept(std::declval<S>() == std::declval<T>()))
- {
- if(this->_state._status.have_error())
- {
- return this->_state._error == o.error();
- }
- return false;
- }
- BOOST_OUTCOME_TEMPLATE(class T, class U, class V)
- BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TEXPR(std::declval<detail::devoid<R>>() != std::declval<detail::devoid<T>>()),
- BOOST_OUTCOME_TEXPR(std::declval<detail::devoid<S>>() != std::declval<detail::devoid<U>>()))
- constexpr bool operator!=(const basic_result_final<T, U, V> &o) const noexcept(
- noexcept(std::declval<detail::devoid<R>>() != std::declval<detail::devoid<T>>()) && noexcept(std::declval<detail::devoid<S>>() != std::declval<detail::devoid<U>>()))
- {
- if(this->_state._status.have_value() && o._state._status.have_value())
- {
- return this->_state._value != o._state._value;
- }
- if(this->_state._status.have_error() && o._state._status.have_error())
- {
- return this->_state._error != o._state._error;
- }
- return true;
- }
- BOOST_OUTCOME_TEMPLATE(class T)
- BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TEXPR(std::declval<R>() != std::declval<T>()))
- constexpr bool operator!=(const success_type<T> &o) const noexcept(
- noexcept(std::declval<R>() != std::declval<T>()))
- {
- if(this->_state._status.have_value())
- {
- return this->_state._value != o.value();
- }
- return false;
- }
- constexpr bool operator!=(const success_type<void> &o) const noexcept
- {
- (void) o;
- return !this->_state._status.have_value();
- }
- BOOST_OUTCOME_TEMPLATE(class T)
- BOOST_OUTCOME_TREQUIRES(BOOST_OUTCOME_TEXPR(std::declval<S>() != std::declval<T>()))
- constexpr bool operator!=(const failure_type<T, void> &o) const noexcept(
- noexcept(std::declval<S>() != std::declval<T>()))
- {
- if(this->_state._status.have_error())
- {
- return this->_state._error != o.error();
- }
- return true;
- }
- };
- 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; }
- 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; }
- 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; }
- 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; }
- }
- BOOST_OUTCOME_V2_NAMESPACE_END
- #endif
|