From 58252a7684c8c41df7f0e0d72ec3c8508d539567 Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Fri, 9 Dec 2022 20:08:09 +0330 Subject: [PATCH] AK: Elaborate the Error constructors a bit The old constraints were making clang mad, so express them in a less complex way. --- AK/Error.h | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/AK/Error.h b/AK/Error.h index 4e2109c99a..8b3fcdd558 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)) { }