mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-15 04:13:11 +00: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
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 a new issue