diff --git a/AK/Error.h b/AK/Error.h index 2e7295fbac0..b85a0ac012d 100644 --- a/AK/Error.h +++ b/AK/Error.h @@ -58,6 +58,12 @@ public: { } + template + ALWAYS_INLINE ErrorOr(U&& value) requires(!IsSame, ErrorOr>) + : m_value(forward(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(); }