From f05c0509c379b2486b36c748603d9859b37540e8 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Thu, 13 Mar 2025 18:29:59 +1300 Subject: [PATCH] AK: Add ability to check Optional equality with an OptionalNone While we don't want to be writing this type of code in 'normal' code this is useful to do in tests as: EXPECT_EQ(my_optional, OptionalNone {}); Has a much better error on assertion failure when compared with: EXPECT(!my_optional.has_value()); --- AK/Optional.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/AK/Optional.h b/AK/Optional.h index 174232f4a12..97aa5523aff 100644 --- a/AK/Optional.h +++ b/AK/Optional.h @@ -570,6 +570,12 @@ ALWAYS_INLINE bool operator==(Optional const& first, T2 const& second) return first.has_value() && first.value() == second; } +template +ALWAYS_INLINE bool operator==(Optional const& first, OptionalNone) +{ + return !first.has_value(); +} + } #if USING_AK_GLOBALLY