From ad328f852b8e366f29ca481ef4699703204ad799 Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Mon, 12 Jul 2021 22:38:03 +0430 Subject: [PATCH] AK: Replace all explicit specialisations of Traits with a single one This commit un-confuses the many specialisations of AK::Traits, and makes it work correctly for all integral types. Prior to this, `AK::Traits` would've been instantiating the base Traits implementation, not `Traits` or `Traits`. --- AK/Traits.h | 54 +++++++++-------------------------------------------- 1 file changed, 9 insertions(+), 45 deletions(-) diff --git a/AK/Traits.h b/AK/Traits.h index 19cc078122f..2f20cb82a99 100644 --- a/AK/Traits.h +++ b/AK/Traits.h @@ -23,52 +23,16 @@ template struct Traits : public GenericTraits { }; -template<> -struct Traits : public GenericTraits { +template +requires(IsIntegral) struct Traits : public GenericTraits { static constexpr bool is_trivial() { return true; } - static unsigned hash(int i) { return int_hash(i); } -}; - -template<> -struct Traits : public GenericTraits { - static constexpr bool is_trivial() { return true; } - static unsigned hash(char c) { return int_hash(c); } -}; - -template<> -struct Traits : public GenericTraits { - static constexpr bool is_trivial() { return true; } - static unsigned hash(i16 i) { return int_hash(i); } -}; - -template<> -struct Traits : public GenericTraits { - static constexpr bool is_trivial() { return true; } - static unsigned hash(i64 i) { return u64_hash(i); } -}; - -template<> -struct Traits : public GenericTraits { - static constexpr bool is_trivial() { return true; } - static unsigned hash(unsigned u) { return int_hash(u); } -}; - -template<> -struct Traits : public GenericTraits { - static constexpr bool is_trivial() { return true; } - static unsigned hash(u8 u) { return int_hash(u); } -}; - -template<> -struct Traits : public GenericTraits { - static constexpr bool is_trivial() { return true; } - static unsigned hash(u16 u) { return int_hash(u); } -}; - -template<> -struct Traits : public GenericTraits { - static constexpr bool is_trivial() { return true; } - static unsigned hash(u64 u) { return u64_hash(u); } + static constexpr unsigned hash(T value) + { + if constexpr (sizeof(T) < 8) + return int_hash(value); + else + return u64_hash(value); + } }; template