diff options
author | Ali Mohammad Pur <ali.mpfard@gmail.com> | 2021-07-12 22:38:03 +0430 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2021-07-12 23:49:59 +0430 |
commit | ad328f852b8e366f29ca481ef4699703204ad799 (patch) | |
tree | ec09d3b8f4f9229f856a041fdb4079286c286c1a | |
parent | 84b028bd71bee672421ba86766ec954434ce4431 (diff) | |
download | serenity-ad328f852b8e366f29ca481ef4699703204ad799.zip |
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<size_t>` would've been instantiating the
base Traits implementation, not `Traits<u32>` or `Traits<u64>`.
-rw-r--r-- | AK/Traits.h | 54 |
1 files changed, 9 insertions, 45 deletions
diff --git a/AK/Traits.h b/AK/Traits.h index 19cc078122..2f20cb82a9 100644 --- a/AK/Traits.h +++ b/AK/Traits.h @@ -23,52 +23,16 @@ template<typename T> struct Traits : public GenericTraits<T> { }; -template<> -struct Traits<int> : public GenericTraits<int> { - static constexpr bool is_trivial() { return true; } - static unsigned hash(int i) { return int_hash(i); } -}; - -template<> -struct Traits<char> : public GenericTraits<char> { - static constexpr bool is_trivial() { return true; } - static unsigned hash(char c) { return int_hash(c); } -}; - -template<> -struct Traits<i16> : public GenericTraits<i16> { - static constexpr bool is_trivial() { return true; } - static unsigned hash(i16 i) { return int_hash(i); } -}; - -template<> -struct Traits<i64> : public GenericTraits<i64> { - static constexpr bool is_trivial() { return true; } - static unsigned hash(i64 i) { return u64_hash(i); } -}; - -template<> -struct Traits<unsigned> : public GenericTraits<unsigned> { - static constexpr bool is_trivial() { return true; } - static unsigned hash(unsigned u) { return int_hash(u); } -}; - -template<> -struct Traits<u8> : public GenericTraits<u8> { - static constexpr bool is_trivial() { return true; } - static unsigned hash(u8 u) { return int_hash(u); } -}; - -template<> -struct Traits<u16> : public GenericTraits<u16> { - static constexpr bool is_trivial() { return true; } - static unsigned hash(u16 u) { return int_hash(u); } -}; - -template<> -struct Traits<u64> : public GenericTraits<u64> { +template<typename T> +requires(IsIntegral<T>) struct Traits<T> : public GenericTraits<T> { 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<typename T> |