summaryrefslogtreecommitdiff
path: root/AK
diff options
context:
space:
mode:
authorPeter Elliott <pelliott@ualberta.ca>2020-08-22 15:57:34 -0600
committerAndreas Kling <kling@serenityos.org>2020-08-23 01:05:22 +0200
commitc68537271ca4430baa27f677511637e8648502c1 (patch)
tree045391abb64112776c6e49f0fd5cfad40903ff6d /AK
parentb0ffd4e94604c72b57568501ed5bff1a0054f4e2 (diff)
downloadserenity-c68537271ca4430baa27f677511637e8648502c1.zip
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==
Diffstat (limited to 'AK')
-rw-r--r--AK/Optional.h6
1 files changed, 6 insertions, 0 deletions
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<typename O>
+ bool operator==(const Optional<O>& other) const
+ {
+ return has_value() == other.has_value() && (!has_value() || value() == other.value());
+ }
+
ALWAYS_INLINE ~Optional()
{
clear();