diff --git a/AK/Optional.h b/AK/Optional.h index fe00c10b52..1100d2ba97 100644 --- a/AK/Optional.h +++ b/AK/Optional.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -656,6 +657,18 @@ ALWAYS_INLINE constexpr bool operator==(Optional const& first, OptionalNone) return !first.has_value(); } +template +struct Traits> : public DefaultTraits> { + static unsigned hash(Optional const& optional) + { + // Arbitrary-ish value for an empty optional, but not 0 as that is a common 'hash' for many T's. + if (!optional.has_value()) + return 13; + + return Traits::hash(optional.value()); + } +}; + } #if USING_AK_GLOBALLY