summaryrefslogtreecommitdiff
path: root/asl
diff options
context:
space:
mode:
authorSteven Le Rouzic <steven.lerouzic@gmail.com>2025-01-31 00:30:08 +0100
committerSteven Le Rouzic <steven.lerouzic@gmail.com>2025-01-31 00:30:08 +0100
commita89e72929ed047344e221f65542e763e3f6ac3de (patch)
treeca36c931c8b23a766c89f4e2fb7822afcace3866 /asl
parent224048d0f4022f91c2074daddf9dcafbf11f2be9 (diff)
Add try macro for status & status_or
Diffstat (limited to 'asl')
-rw-r--r--asl/status.hpp4
-rw-r--r--asl/status_or.hpp7
2 files changed, 11 insertions, 0 deletions
diff --git a/asl/status.hpp b/asl/status.hpp
index 42695c3..169dfce 100644
--- a/asl/status.hpp
+++ b/asl/status.hpp
@@ -118,6 +118,8 @@ public:
return {};
}
+ constexpr status&& throw_status() && { return ASL_MOVE(*this); }
+
friend void AslFormat(Formatter& f, const status&);
template<typename H>
@@ -150,4 +152,6 @@ ASL_DEFINE_ERROR_(internal)
ASL_DEFINE_ERROR_(runtime)
ASL_DEFINE_ERROR_(invalid_argument)
+#define ASL_TRY(VALUE) if (VALUE.ok()) {} else { return ASL_MOVE(VALUE).throw_status(); }
+
} // namespace asl
diff --git a/asl/status_or.hpp b/asl/status_or.hpp
index cb65147..ec76e47 100644
--- a/asl/status_or.hpp
+++ b/asl/status_or.hpp
@@ -127,6 +127,8 @@ public:
constexpr string_view message() const { return m_status.message(); }
+ constexpr status&& throw_status() && { return ASL_MOVE(m_status); }
+
// @Todo(C++23) Deducing this
constexpr const T& value() const&
{
@@ -160,6 +162,11 @@ public:
return ok() ? ASL_MOVE(value()) : static_cast<T>(ASL_FWD(other_value));
}
+ friend void AslFormat(Formatter& f, const status_or& status)
+ {
+ AslFormat(f, status.m_status);
+ }
+
template<typename H>
requires hashable<T>
friend H AslHashValue(H h, const status_or& s)