diff --git a/AK/Error.h b/AK/Error.h index 4e2109c99a3..8b3fcdd5589 100644 --- a/AK/Error.h +++ b/AK/Error.h @@ -81,9 +81,33 @@ public: { } + ALWAYS_INLINE ErrorOr(ErrorOr&&) = default; + ALWAYS_INLINE ErrorOr(ErrorOr const&) = default; + ALWAYS_INLINE ErrorOr& operator=(ErrorOr&&) = default; + ALWAYS_INLINE ErrorOr& operator=(ErrorOr const&) = default; + + template + ALWAYS_INLINE ErrorOr(ErrorOr const& value) + : m_value_or_error(value.m_value_or_error.visit([](U const& v) -> Variant { return v; }, [](ErrorType const& error) -> Variant { return error; })) + { + } + + template + ALWAYS_INLINE ErrorOr(ErrorOr& value) + : m_value_or_error(value.m_value_or_error.visit([](U& v) { return Variant(move(v)); }, [](ErrorType& error) { return Variant(move(error)); })) + { + } + + template + ALWAYS_INLINE ErrorOr(ErrorOr&& value) + : m_value_or_error(value.visit([](U& v) { return Variant(move(v)); }, [](ErrorType& error) { return Variant(move(error)); })) + { + } + template ALWAYS_INLINE ErrorOr(U&& value) - requires(!IsSame, ErrorOr>) + requires( + requires { T(declval()); } || requires { ErrorType(declval>()); }) : m_value_or_error(forward(value)) { }