diff options
Diffstat (limited to 'include/fud_result.hpp')
-rw-r--r-- | include/fud_result.hpp | 45 |
1 files changed, 12 insertions, 33 deletions
diff --git a/include/fud_result.hpp b/include/fud_result.hpp index 076af21..74954df 100644 --- a/include/fud_result.hpp +++ b/include/fud_result.hpp @@ -23,30 +23,6 @@ namespace fud { -namespace detail { -template <typename T> -class CopyMove { - public: - explicit constexpr CopyMove(T value) : m_value{std::move(value)} - { - } - - constexpr T&& take() - { - return std::move(m_value); - } - - constexpr T copy() const - { - return m_value; - } - - private: - T m_value; -}; - -} // namespace detail - /** \brief A result type which contains either a T on success or an E on error. */ template <typename T, typename E> class [[nodiscard]] Result { @@ -84,43 +60,46 @@ class [[nodiscard]] Result { [[nodiscard]] T getOkay() const { - return std::get<detail::CopyMove<T>>(m_value).copy(); + return std::get<T>(m_value); } [[nodiscard]] E getError() const { - return std::get<detail::CopyMove<E>>(m_value).copy(); + return std::get<E>(m_value); } [[nodiscard]] T&& getOkay() { - return std::get<detail::CopyMove<T>>(m_value).take(); + return std::move(std::get<T>(m_value)); } [[nodiscard]] E&& getError() { - return std::get<detail::CopyMove<E>>(m_value).take(); + return std::move(std::get<E>(m_value)); } private: explicit Result() : m_value() { } - explicit Result(const T& value) : m_value{detail::CopyMove<T>{value}} + + explicit Result(const T& value) : m_value{value} { } - explicit Result(const E& value) : m_value{detail::CopyMove<E>{value}} + + explicit Result(const E& value) : m_value{value} { } - explicit Result(T&& value) : m_value{detail::CopyMove<T>{std::move(value)}} + explicit Result(T&& value) : m_value{std::move(value)} { } - explicit Result(E&& value) : m_value{detail::CopyMove<E>{std::move(value)}} + + explicit Result(E&& value) : m_value{std::move(value)} { } - std::variant<detail::CopyMove<T>, detail::CopyMove<E>> m_value; + std::variant<T, E> m_value; }; } // namespace fud |