From 512d026de016f2720060d264adec02e56123851d Mon Sep 17 00:00:00 2001 From: Dominick Allen Date: Thu, 24 Oct 2024 09:04:35 -0500 Subject: As always, formatting is a pain. --- include/fud_result.hpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'include/fud_result.hpp') diff --git a/include/fud_result.hpp b/include/fud_result.hpp index 877c49c..95f3e5c 100644 --- a/include/fud_result.hpp +++ b/include/fud_result.hpp @@ -104,21 +104,53 @@ class [[nodiscard]] Result { return std::get(m_value); } + [[nodiscard]] constexpr const T& getOkayOr(const T& alternative) const& + { + if (!isOkay()) { + return alternative; + } + return std::get(m_value); + } + [[nodiscard]] constexpr const E& getError() const& { return std::get(m_value); } + [[nodiscard]] constexpr const E& getErrorOr(const E& alternative) const& + { + if (!isError()) { + return alternative; + } + return std::get(m_value); + } + [[nodiscard]] constexpr T&& takeOkay() { return std::move(std::get(m_value)); } + [[nodiscard]] constexpr T&& takeOkayOr(T&& alternative) + { + if (!isOkay()) { + return std::move(alternative); + } + return std::move(std::get(m_value)); + } + [[nodiscard]] constexpr E&& takeError() { return std::move(std::get(m_value)); } + [[nodiscard]] constexpr E&& takeErrorOr(E&& alternative) + { + if (!isError()) { + return std::move(alternative); + } + return std::move(std::get(m_value)); + } + private: constexpr Result() : m_value() { -- cgit v1.2.3