From aaf54f8cf81cfdfd04771ad3b9ce5c21c819eef4 Mon Sep 17 00:00:00 2001 From: Lucas CHOLLET Date: Tue, 28 Nov 2023 00:22:46 -0500 Subject: [PATCH] AK: Allow `Optional` to be constructed by `OptionalNone()` This is an extension of cc0b970d but for the reference-handling specialization of Optional. This basically allow us to write code like: ```cpp Optional opt; opt = OptionalNone{}; ``` --- AK/Optional.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/AK/Optional.h b/AK/Optional.h index 633b0655ed0..7f96e3a831b 100644 --- a/AK/Optional.h +++ b/AK/Optional.h @@ -339,6 +339,16 @@ public: ALWAYS_INLINE Optional() = default; + template V> + Optional(V) { } + + template V> + Optional& operator=(V) + { + clear(); + return *this; + } + template ALWAYS_INLINE Optional(U& value) requires(CanBePlacedInOptional) @@ -409,6 +419,7 @@ public: // Note: Disallows assignment from a temporary as this does not do any lifetime extension. template + requires(!IsSame>) ALWAYS_INLINE Optional& operator=(U&& value) requires(CanBePlacedInOptional && IsLvalueReference) {