From cc0b970d81c731cf1b9ec81a6f70774524c701c4 Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Fri, 9 Dec 2022 23:14:40 +0330 Subject: [PATCH] AK: Allow Optional to be constructed by OptionalNone() This is needed by the Jakt runtime too. --- AK/Optional.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/AK/Optional.h b/AK/Optional.h index 59b1dd1013..08f659dce4 100644 --- a/AK/Optional.h +++ b/AK/Optional.h @@ -44,6 +44,10 @@ using ConditionallyResultType = typename Detail::ConditionallyResultType class Optional; +struct OptionalNone { + explicit OptionalNone() = default; +}; + template requires(!IsLvalueReference) class [[nodiscard]] Optional { template @@ -56,6 +60,16 @@ public: ALWAYS_INLINE Optional() = default; + template V> + Optional(V) { } + + template V> + Optional& operator=(V) + { + clear(); + return *this; + } + #ifdef AK_HAS_CONDITIONALLY_TRIVIAL Optional(Optional const& other) requires(!IsCopyConstructible) @@ -115,6 +129,7 @@ public: } template + requires(!IsSame>) ALWAYS_INLINE explicit(!IsConvertible) Optional(U&& value) requires(!IsSame, Optional> && IsConstructible) : m_has_value(true)