From 415763b1b3eea099c6e5af0c5b9f91d8d254f811 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Sun, 12 Dec 2021 17:42:19 -0500 Subject: [PATCH] LibUnicode: Define traits for a vector of integral/enum types Any generator which defines a unique storage instance for a list of numbers will need this. --- .../GenerateUnicodeNumberFormat.cpp | 14 ------------ .../CodeGenerators/LibUnicode/GeneratorUtil.h | 22 +++++++++++++++++++ 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeNumberFormat.cpp b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeNumberFormat.cpp index 153fa82c26..3508960e9b 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeNumberFormat.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GenerateUnicodeNumberFormat.cpp @@ -130,20 +130,6 @@ struct AK::Traits : public GenericTraits { }; using NumberFormatList = Vector; - -template<> -struct AK::Traits : public GenericTraits { - static unsigned hash(NumberFormatList const& formats) - { - auto hash = int_hash(static_cast(formats.size())); - - for (auto format : formats) - hash = pair_int_hash(hash, format); - - return hash; - } -}; - using NumericSymbolList = Vector; struct NumberSystem { diff --git a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GeneratorUtil.h b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GeneratorUtil.h index aff59fe3f1..74621fbbc2 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GeneratorUtil.h +++ b/Meta/Lagom/Tools/CodeGenerators/LibUnicode/GeneratorUtil.h @@ -7,6 +7,7 @@ #pragma once #include +#include #include #include #include @@ -14,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -25,6 +27,26 @@ inline constexpr bool StorageTypeIsList = false; template inline constexpr bool StorageTypeIsList> = true; +template +concept IntegralOrEnum = Integral || Enum; + +template +struct AK::Traits> : public GenericTraits> { + static unsigned hash(Vector const& list) + { + auto hash = int_hash(static_cast(list.size())); + + for (auto value : list) { + if constexpr (Enum) + hash = pair_int_hash(hash, to_underlying(value)); + else + hash = pair_int_hash(hash, value); + } + + return hash; + } +}; + template class UniqueStorage { public: