AK: Allow Optional<T> to be constructed by OptionalNone()

This is needed by the Jakt runtime too.
This commit is contained in:
Ali Mohammad Pur 2022-12-09 23:14:40 +03:30 committed by Ali Mohammad Pur
parent 12e4cd3b77
commit cc0b970d81
Notes: sideshowbarker 2024-07-17 08:27:05 +09:00

View file

@ -44,6 +44,10 @@ using ConditionallyResultType = typename Detail::ConditionallyResultType<conditi
template<typename> template<typename>
class Optional; class Optional;
struct OptionalNone {
explicit OptionalNone() = default;
};
template<typename T> template<typename T>
requires(!IsLvalueReference<T>) class [[nodiscard]] Optional<T> { requires(!IsLvalueReference<T>) class [[nodiscard]] Optional<T> {
template<typename U> template<typename U>
@ -56,6 +60,16 @@ public:
ALWAYS_INLINE Optional() = default; 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 #ifdef AK_HAS_CONDITIONALLY_TRIVIAL
Optional(Optional const& other) Optional(Optional const& other)
requires(!IsCopyConstructible<T>) requires(!IsCopyConstructible<T>)
@ -115,6 +129,7 @@ public:
} }
template<typename U = T> template<typename U = T>
requires(!IsSame<OptionalNone, RemoveCVReference<U>>)
ALWAYS_INLINE explicit(!IsConvertible<U&&, T>) Optional(U&& value) ALWAYS_INLINE explicit(!IsConvertible<U&&, T>) Optional(U&& value)
requires(!IsSame<RemoveCVReference<U>, Optional<T>> && IsConstructible<T, U &&>) requires(!IsSame<RemoveCVReference<U>, Optional<T>> && IsConstructible<T, U &&>)
: m_has_value(true) : m_has_value(true)