From 79620980ea3880f6512a35b9d688a60a02ff8b98 Mon Sep 17 00:00:00 2001 From: Dominick Allen Date: Sat, 5 Oct 2024 08:33:39 -0500 Subject: Formatting changes. Refactoring out detail::CopyMove from Result. --- include/fud_result.hpp | 45 ++++++++++++--------------------------------- 1 file changed, 12 insertions(+), 33 deletions(-) (limited to 'include/fud_result.hpp') 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 -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 class [[nodiscard]] Result { @@ -84,43 +60,46 @@ class [[nodiscard]] Result { [[nodiscard]] T getOkay() const { - return std::get>(m_value).copy(); + return std::get(m_value); } [[nodiscard]] E getError() const { - return std::get>(m_value).copy(); + return std::get(m_value); } [[nodiscard]] T&& getOkay() { - return std::get>(m_value).take(); + return std::move(std::get(m_value)); } [[nodiscard]] E&& getError() { - return std::get>(m_value).take(); + return std::move(std::get(m_value)); } private: explicit Result() : m_value() { } - explicit Result(const T& value) : m_value{detail::CopyMove{value}} + + explicit Result(const T& value) : m_value{value} { } - explicit Result(const E& value) : m_value{detail::CopyMove{value}} + + explicit Result(const E& value) : m_value{value} { } - explicit Result(T&& value) : m_value{detail::CopyMove{std::move(value)}} + explicit Result(T&& value) : m_value{std::move(value)} { } - explicit Result(E&& value) : m_value{detail::CopyMove{std::move(value)}} + + explicit Result(E&& value) : m_value{std::move(value)} { } - std::variant, detail::CopyMove> m_value; + std::variant m_value; }; } // namespace fud -- cgit v1.2.3