diff options
Diffstat (limited to 'include/fud_result.hpp')
-rw-r--r-- | include/fud_result.hpp | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/include/fud_result.hpp b/include/fud_result.hpp index dae084a..3acf776 100644 --- a/include/fud_result.hpp +++ b/include/fud_result.hpp @@ -47,6 +47,26 @@ class [[nodiscard]] Result { return ResultType{std::move(error)}; } + template <typename F> + static ResultType okay(const Result<T, F>& okayRes) { + return ResultType{okayRes.getOkay()}; + } + + template <typename F> + static ResultType okay(Result<T, F>&& okayRes) { + return ResultType{okayRes.takeOkay()}; + } + + template <typename U> + static ResultType error(const Result<U, E>& errorRes) { + return ResultType{errorRes.getError()}; + } + + template <typename U> + static ResultType error(Result<U, E>&& errorRes) { + return ResultType{errorRes.takeError()}; + } + [[nodiscard]] constexpr bool isOkay() const { return (m_value.index() == 0); @@ -67,12 +87,12 @@ class [[nodiscard]] Result { return std::get<E>(m_value); } - [[nodiscard]] const T&& getOkay() const&& + [[nodiscard]] T&& takeOkay() { return std::move(std::get<T>(m_value)); } - [[nodiscard]] const E&& getError() const&& + [[nodiscard]] E&& takeError() { return std::move(std::get<E>(m_value)); } |