mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 12:24:57 +00:00
AK: Allow Optional<T> to be constructed by OptionalNone()
This is needed by the Jakt runtime too.
This commit is contained in:
parent
12e4cd3b77
commit
cc0b970d81
1 changed files with 15 additions and 0 deletions
|
@ -44,6 +44,10 @@ using ConditionallyResultType = typename Detail::ConditionallyResultType<conditi
|
|||
template<typename>
|
||||
class Optional;
|
||||
|
||||
struct OptionalNone {
|
||||
explicit OptionalNone() = default;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
requires(!IsLvalueReference<T>) class [[nodiscard]] Optional<T> {
|
||||
template<typename U>
|
||||
|
@ -56,6 +60,16 @@ public:
|
|||
|
||||
ALWAYS_INLINE Optional() = default;
|
||||
|
||||
template<SameAs<OptionalNone> V>
|
||||
Optional(V) { }
|
||||
|
||||
template<SameAs<OptionalNone> V>
|
||||
Optional& operator=(V)
|
||||
{
|
||||
clear();
|
||||
return *this;
|
||||
}
|
||||
|
||||
#ifdef AK_HAS_CONDITIONALLY_TRIVIAL
|
||||
Optional(Optional const& other)
|
||||
requires(!IsCopyConstructible<T>)
|
||||
|
@ -115,6 +129,7 @@ public:
|
|||
}
|
||||
|
||||
template<typename U = T>
|
||||
requires(!IsSame<OptionalNone, RemoveCVReference<U>>)
|
||||
ALWAYS_INLINE explicit(!IsConvertible<U&&, T>) Optional(U&& value)
|
||||
requires(!IsSame<RemoveCVReference<U>, Optional<T>> && IsConstructible<T, U &&>)
|
||||
: m_has_value(true)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue