From 8249b28bea29e8ce17eac12776a60ec3f9e47176 Mon Sep 17 00:00:00 2001 From: Dominick Allen Date: Thu, 17 Oct 2024 19:42:29 -0500 Subject: Rename InvalidInput to ArgumentInvalid. --- include/fud_result.hpp | 55 +++++++++++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 21 deletions(-) (limited to 'include/fud_result.hpp') diff --git a/include/fud_result.hpp b/include/fud_result.hpp index 5dabaf5..4bfb819 100644 --- a/include/fud_result.hpp +++ b/include/fud_result.hpp @@ -28,6 +28,22 @@ class [[nodiscard]] Result { public: using ResultType = Result; + Result(const T& value) : m_value{value} + { + } + + Result(const E& value) : m_value{value} + { + } + + Result(T&& value) : m_value{std::move(value)} + { + } + + Result(E&& value) : m_value{std::move(value)} + { + } + static ResultType okay(const T& okay) { return ResultType{okay}; @@ -49,22 +65,26 @@ class [[nodiscard]] Result { } template - static ResultType okay(const Result& okayRes) { + static ResultType okay(const Result& okayRes) + { return ResultType{okayRes.getOkay()}; } template - static ResultType okay(Result&& okayRes) { + static ResultType okay(Result&& okayRes) + { return ResultType{okayRes.takeOkay()}; } template - static ResultType error(const Result& errorRes) { + static ResultType error(const Result& errorRes) + { return ResultType{errorRes.getError()}; } template - static ResultType error(Result&& errorRes) { + static ResultType error(Result&& errorRes) + { return ResultType{errorRes.takeError()}; } @@ -99,29 +119,22 @@ class [[nodiscard]] Result { } private: - explicit Result() : m_value() - { - } - - explicit Result(const T& value) : m_value{value} - { - } - - explicit Result(const E& value) : m_value{value} - { - } - - explicit Result(T&& value): m_value{std::move(value)} - { - } - - explicit Result(E&& value) : m_value{std::move(value)} + Result() : m_value() { } std::variant m_value; }; +#define M_TakeOrReturn(HYGIENE_EXPRESSION) \ + ({ \ + auto HYGIENE_RESULT{(HYGIENE_EXPRESSION)}; \ + if (HYGIENE_RESULT.isError()) { \ + return HYGIENE_RESULT.takeError(); \ + } \ + HYGIENE_RESULT.takeOkay(); \ + }) + } // namespace fud #endif -- cgit v1.2.3