Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:59:08

0001 /* Finaliser for a very simple result type
0002 (C) 2017-2024 Niall Douglas <http://www.nedproductions.biz/> (5 commits)
0003 File Created: Oct 2017
0004 
0005 
0006 Boost Software License - Version 1.0 - August 17th, 2003
0007 
0008 Permission is hereby granted, free of charge, to any person or organization
0009 obtaining a copy of the software and accompanying documentation covered by
0010 this license (the "Software") to use, reproduce, display, distribute,
0011 execute, and transmit the Software, and to prepare derivative works of the
0012 Software, and to permit third-parties to whom the Software is furnished to
0013 do so, all subject to the following:
0014 
0015 The copyright notices in the Software and this entire statement, including
0016 the above license grant, this restriction and the following disclaimer,
0017 must be included in all copies of the Software, in whole or in part, and
0018 all derivative works of the Software, unless such copies or derivative
0019 works are solely in the form of machine-executable object code generated by
0020 a source language processor.
0021 
0022 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0023 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0024 FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
0025 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
0026 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
0027 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
0028 DEALINGS IN THE SOFTWARE.
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;  // NOLINT
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 }  // namespace detail
0155 
0156 BOOST_OUTCOME_V2_NAMESPACE_END
0157 
0158 #endif