diff options
author | Dominick Allen <djallen@librehumanitas.org> | 2024-10-17 19:42:29 -0500 |
---|---|---|
committer | Dominick Allen <djallen@librehumanitas.org> | 2024-10-17 19:42:29 -0500 |
commit | 8249b28bea29e8ce17eac12776a60ec3f9e47176 (patch) | |
tree | 98318d7564b5f618cfb59e23cc6b918fcab88ee8 /include/fud_result.hpp | |
parent | b32e83ece42cec5aa9dee370bcdf349d23dbc8ba (diff) |
Rename InvalidInput to ArgumentInvalid.
Diffstat (limited to 'include/fud_result.hpp')
-rw-r--r-- | include/fud_result.hpp | 55 |
1 files changed, 34 insertions, 21 deletions
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<T, E>; + 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 <typename F> - static ResultType okay(const Result<T, F>& okayRes) { + static ResultType okay(const Result<T, F>& okayRes) + { return ResultType{okayRes.getOkay()}; } template <typename F> - static ResultType okay(Result<T, F>&& okayRes) { + static ResultType okay(Result<T, F>&& okayRes) + { return ResultType{okayRes.takeOkay()}; } template <typename U> - static ResultType error(const Result<U, E>& errorRes) { + static ResultType error(const Result<U, E>& errorRes) + { return ResultType{errorRes.getError()}; } template <typename U> - static ResultType error(Result<U, E>&& errorRes) { + static ResultType error(Result<U, E>&& 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<T, E> 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 |