summaryrefslogtreecommitdiff
path: root/include/fud_result.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/fud_result.hpp')
-rw-r--r--include/fud_result.hpp32
1 files changed, 32 insertions, 0 deletions
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<T>(m_value);
}
+ [[nodiscard]] constexpr const T& getOkayOr(const T& alternative) const&
+ {
+ if (!isOkay()) {
+ return alternative;
+ }
+ return std::get<T>(m_value);
+ }
+
[[nodiscard]] constexpr const E& getError() const&
{
return std::get<E>(m_value);
}
+ [[nodiscard]] constexpr const E& getErrorOr(const E& alternative) const&
+ {
+ if (!isError()) {
+ return alternative;
+ }
+ return std::get<E>(m_value);
+ }
+
[[nodiscard]] constexpr T&& takeOkay()
{
return std::move(std::get<T>(m_value));
}
+ [[nodiscard]] constexpr T&& takeOkayOr(T&& alternative)
+ {
+ if (!isOkay()) {
+ return std::move(alternative);
+ }
+ return std::move(std::get<T>(m_value));
+ }
+
[[nodiscard]] constexpr E&& takeError()
{
return std::move(std::get<E>(m_value));
}
+ [[nodiscard]] constexpr E&& takeErrorOr(E&& alternative)
+ {
+ if (!isError()) {
+ return std::move(alternative);
+ }
+ return std::move(std::get<E>(m_value));
+ }
+
private:
constexpr Result() : m_value()
{