diff options
author | Andreas Kling <kling@serenityos.org> | 2021-11-08 00:36:35 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-11-08 00:36:35 +0100 |
commit | 7ee10c69264cb278845a1e1b06d5acf2e5e7ddf0 (patch) | |
tree | 517b0c09df934a85825e746a37ac39dcf5ee144b /AK | |
parent | 5e473a63d30098efbfd6bd076bad1faba88d9e93 (diff) | |
download | serenity-7ee10c69264cb278845a1e1b06d5acf2e5e7ddf0.zip |
AK: Add some more ways to construct Error and ErrorOr<T>
This is preparation for using Error in the kernel instead of KResult.
Diffstat (limited to 'AK')
-rw-r--r-- | AK/Error.h | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/AK/Error.h b/AK/Error.h index 2e7295fbac..b85a0ac012 100644 --- a/AK/Error.h +++ b/AK/Error.h @@ -58,6 +58,12 @@ public: { } + template<typename U> + ALWAYS_INLINE ErrorOr(U&& value) requires(!IsSame<RemoveCVReference<U>, ErrorOr<T>>) + : m_value(forward<U>(value)) + { + } + #ifdef __serenity__ ErrorOr(ErrnoCode code) : m_error(Error::from_errno(code)) @@ -74,6 +80,9 @@ public: ErrorOr(ErrorOr const& other) = default; ~ErrorOr() = default; + ErrorOr& operator=(ErrorOr&& other) = default; + ErrorOr& operator=(ErrorOr const& other) = default; + T& value() { return m_value.value(); } Error& error() { return m_error.value(); } @@ -98,11 +107,21 @@ public: { } +#ifdef __serenity__ + ErrorOr(ErrnoCode code) + : m_error(Error::from_errno(code)) + { + } +#endif + ErrorOr() = default; ErrorOr(ErrorOr&& other) = default; - ErrorOr(const ErrorOr& other) = default; + ErrorOr(ErrorOr const& other) = default; ~ErrorOr() = default; + ErrorOr& operator=(ErrorOr&& other) = default; + ErrorOr& operator=(ErrorOr const& other) = default; + ErrorType& error() { return m_error.value(); } bool is_error() const { return m_error.has_value(); } ErrorType release_error() { return m_error.release_value(); } |