mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
AK: Fix constructing ErrorOr from ErrorOr of a related type
Mark other ErrorOr types as friends, and fix a typo in the && constructor, so that we can create an ErrorOr<Core::Object> from an ErrorOr<GUI::Widget>. Also, add some requires() clauses to these constructors so the error messages are clearer.
This commit is contained in:
parent
7b0adee487
commit
feb0eb9309
Notes:
sideshowbarker
2024-07-17 02:29:26 +09:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/SerenityOS/serenity/commit/feb0eb9309 Pull-request: https://github.com/SerenityOS/serenity/pull/16703
1 changed files with 7 additions and 1 deletions
|
@ -81,6 +81,9 @@ private:
|
|||
|
||||
template<typename T, typename E>
|
||||
class [[nodiscard]] ErrorOr {
|
||||
template<typename U, typename F>
|
||||
friend class ErrorOr;
|
||||
|
||||
public:
|
||||
using ResultType = T;
|
||||
using ErrorType = E;
|
||||
|
@ -98,19 +101,22 @@ public:
|
|||
|
||||
template<typename U>
|
||||
ALWAYS_INLINE ErrorOr(ErrorOr<U, ErrorType> const& value)
|
||||
requires(IsConvertible<U, T>)
|
||||
: 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)
|
||||
requires(IsConvertible<U, T>)
|
||||
: 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)); }))
|
||||
requires(IsConvertible<U, T>)
|
||||
: 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)); }))
|
||||
{
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue