From f99e6507eec954f72496b799f4b2150f74f94ff2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?kleines=20Filmr=C3=B6llchen?= Date: Thu, 19 Aug 2021 14:46:05 +0200 Subject: [PATCH] AK: Add Traits for Enums Enums can be hashed as their underlying integral type. This allows enum keys in hash maps etc. --- AK/Traits.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/AK/Traits.h b/AK/Traits.h index e6a973ae649..6d90fb0733b 100644 --- a/AK/Traits.h +++ b/AK/Traits.h @@ -6,6 +6,7 @@ #pragma once +#include #include #include @@ -41,6 +42,12 @@ requires(IsPointer) struct Traits : public GenericTraits { static constexpr bool is_trivial() { return true; } }; +template +struct Traits : public GenericTraits { + static unsigned hash(T value) { return Traits>::hash(to_underlying(value)); } + static constexpr bool is_trivial() { return Traits>::is_trivial(); } +}; + } using AK::GenericTraits;