summaryrefslogtreecommitdiff
path: root/include/fud_result.hpp
diff options
context:
space:
mode:
authorDominick Allen <djallen@librehumanitas.org>2024-10-24 09:04:35 -0500
committerDominick Allen <djallen@librehumanitas.org>2024-10-24 09:04:35 -0500
commit512d026de016f2720060d264adec02e56123851d (patch)
tree2c48965d968db70e37ae82e287dc80bd205b2d4a /include/fud_result.hpp
parent5cc7cbc3704ec255eb5d0ac53b2cc0fcb1221d63 (diff)
As always, formatting is a pain.
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()
{