mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-08-17 01:10:28 +03:00
AK: Elaborate the Error constructors a bit
The old constraints were making clang mad, so express them in a less complex way.
This commit is contained in:
parent
099a6bc45f
commit
58252a7684
Notes:
sideshowbarker
2024-07-17 07:38:17 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/58252a7684 Pull-request: https://github.com/SerenityOS/serenity/pull/16396 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/awesomekling ✅
26
AK/Error.h
26
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<typename U>
|
||||
ALWAYS_INLINE ErrorOr(ErrorOr<U, ErrorType> const& value)
|
||||
: m_value_or_error(value.m_value_or_error.visit([](U const& v) -> Variant<T, ErrorType> { return v; }, [](ErrorType const& error) -> Variant<T, ErrorType> { return error; }))
|
||||
{
|
||||
}
|
||||
|
||||
template<typename U>
|
||||
ALWAYS_INLINE ErrorOr(ErrorOr<U, ErrorType>& value)
|
||||
: m_value_or_error(value.m_value_or_error.visit([](U& v) { return Variant<T, ErrorType>(move(v)); }, [](ErrorType& error) { return Variant<T, ErrorType>(move(error)); }))
|
||||
{
|
||||
}
|
||||
|
||||
template<typename U>
|
||||
ALWAYS_INLINE ErrorOr(ErrorOr<U, ErrorType>&& value)
|
||||
: m_value_or_error(value.visit([](U& v) { return Variant<T, ErrorType>(move(v)); }, [](ErrorType& error) { return Variant<T, ErrorType>(move(error)); }))
|
||||
{
|
||||
}
|
||||
|
||||
template<typename U>
|
||||
ALWAYS_INLINE ErrorOr(U&& value)
|
||||
requires(!IsSame<RemoveCVReference<U>, ErrorOr<T, ErrorType>>)
|
||||
requires(
|
||||
requires { T(declval<U>()); } || requires { ErrorType(declval<RemoveCVReference<U>>()); })
|
||||
: m_value_or_error(forward<U>(value))
|
||||
{
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user