From c68537271ca4430baa27f677511637e8648502c1 Mon Sep 17 00:00:00 2001 From: Peter Elliott Date: Sat, 22 Aug 2020 15:57:34 -0600 Subject: [PATCH] AK: Add operator== to AK::Optional The semantics: - two Optionals are equal if they are both None - two Optionals are equal if they are both Some, and their values are operator== --- AK/Optional.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/AK/Optional.h b/AK/Optional.h index ccc0986d20..ac7d04d6e5 100644 --- a/AK/Optional.h +++ b/AK/Optional.h @@ -97,6 +97,12 @@ public: return *this; } + template + bool operator==(const Optional& other) const + { + return has_value() == other.has_value() && (!has_value() || value() == other.value()); + } + ALWAYS_INLINE ~Optional() { clear();