aboutsummaryrefslogtreecommitdiff
path: root/libs/kstd
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2026-07-14 15:27:49 +0200
committerFelix Morgner <felix.morgner@ost.ch>2026-07-14 15:27:49 +0200
commitaf017fa7983e6730b2f8fb6acee221dd39c02b7a (patch)
tree0d1238d237db0bbcaeb9a42995538c166638ef48 /libs/kstd
parent5d98c13c0a1aa1e5415dbe820d7b537477b79c18 (diff)
downloadkernel-af017fa7983e6730b2f8fb6acee221dd39c02b7a.tar.xz
kernel-af017fa7983e6730b2f8fb6acee221dd39c02b7a.zip
kstd: extract result helper alias
Diffstat (limited to 'libs/kstd')
-rw-r--r--libs/kstd/kstd/result.hpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/libs/kstd/kstd/result.hpp b/libs/kstd/kstd/result.hpp
new file mode 100644
index 00000000..7b027a8d
--- /dev/null
+++ b/libs/kstd/kstd/result.hpp
@@ -0,0 +1,35 @@
+#ifndef KSTD_RESULT_HPP
+#define KSTD_RESULT_HPP
+
+#include <kstd/system_error.hpp>
+
+#include <expected>
+#include <type_traits>
+#include <utility>
+
+namespace kstd
+{
+
+ template<typename SuccessType>
+ using result = std::expected<SuccessType, error_code>;
+
+ template<typename SuccessType>
+ requires(!std::is_void_v<SuccessType>)
+ constexpr auto inline success(SuccessType && value) -> result<std::remove_cvref_t<SuccessType>>
+ {
+ return result<std::remove_cvref_t<SuccessType>>{std::in_place, std::forward<SuccessType>(value)};
+ }
+
+ constexpr auto inline success() -> result<void>
+ {
+ return result<void>{std::in_place};
+ }
+
+ constexpr auto inline failure(error_code error) -> std::unexpected<error_code>
+ {
+ return std::unexpected(error);
+ }
+
+} // namespace kstd
+
+#endif \ No newline at end of file