From 6c6e917cf04fbd5fc4365c3899706e9a13043cdc Mon Sep 17 00:00:00 2001 From: Hendiadyoin1 Date: Sun, 7 Nov 2021 14:37:05 +0100 Subject: [PATCH] AK: Add dedicated Traits for c-strings --- AK/Traits.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/AK/Traits.h b/AK/Traits.h index 6d90fb0733b..b1d60f325f7 100644 --- a/AK/Traits.h +++ b/AK/Traits.h @@ -9,6 +9,8 @@ #include #include #include +#include +#include namespace AK { @@ -37,7 +39,7 @@ requires(IsIntegral) struct Traits : public GenericTraits { }; template -requires(IsPointer) struct Traits : public GenericTraits { +requires(IsPointer && !Detail::IsPointerOfType) struct Traits : public GenericTraits { static unsigned hash(T p) { return ptr_hash((FlatPtr)p); } static constexpr bool is_trivial() { return true; } }; @@ -48,6 +50,13 @@ struct Traits : public GenericTraits { static constexpr bool is_trivial() { return Traits>::is_trivial(); } }; +template +requires(Detail::IsPointerOfType) struct Traits : public GenericTraits { + static unsigned hash(T const value) { return string_hash(value, strlen(value)); } + static constexpr bool equals(T const a, T const b) { return strcmp(a, b); } + static constexpr bool is_trivial() { return true; } +}; + } using AK::GenericTraits;