diff options
author | Dominick Allen <djallen@librehumanitas.org> | 2024-10-15 20:56:26 -0500 |
---|---|---|
committer | Dominick Allen <djallen@librehumanitas.org> | 2024-10-15 20:56:26 -0500 |
commit | f3ac764684c64fbdd2094853a80b23e570cd5d9c (patch) | |
tree | 3b7f64480a1247455d28e23b6bb5ff63303c9170 /include/fud_result.hpp | |
parent | 71976e927cca43b970cb659c03fd6908c352ea3d (diff) |
Conver to using static constructors for string, sqlite, files.
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)); } |