summaryrefslogtreecommitdiff
path: root/AK/Traits.h
diff options
context:
space:
mode:
authorHendiadyoin1 <leon2002.la@gmail.com>2021-11-07 14:37:05 +0100
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2021-12-15 13:09:49 +0330
commit6c6e917cf04fbd5fc4365c3899706e9a13043cdc (patch)
tree0580c48d6782dbdd29f891ac474309300b58600e /AK/Traits.h
parentdea86f511ce685be9639c3002e8b3d5c904713f2 (diff)
downloadserenity-6c6e917cf04fbd5fc4365c3899706e9a13043cdc.zip
AK: Add dedicated Traits for c-strings
Diffstat (limited to 'AK/Traits.h')
-rw-r--r--AK/Traits.h11
1 files changed, 10 insertions, 1 deletions
diff --git a/AK/Traits.h b/AK/Traits.h
index 6d90fb0733..b1d60f325f 100644
--- a/AK/Traits.h
+++ b/AK/Traits.h
@@ -9,6 +9,8 @@
#include <AK/Concepts.h>
#include <AK/Forward.h>
#include <AK/HashFunctions.h>
+#include <AK/StringHash.h>
+#include <string.h>
namespace AK {
@@ -37,7 +39,7 @@ requires(IsIntegral<T>) struct Traits<T> : public GenericTraits<T> {
};
template<typename T>
-requires(IsPointer<T>) struct Traits<T> : public GenericTraits<T> {
+requires(IsPointer<T> && !Detail::IsPointerOfType<char, T>) struct Traits<T> : public GenericTraits<T> {
static unsigned hash(T p) { return ptr_hash((FlatPtr)p); }
static constexpr bool is_trivial() { return true; }
};
@@ -48,6 +50,13 @@ struct Traits<T> : public GenericTraits<T> {
static constexpr bool is_trivial() { return Traits<UnderlyingType<T>>::is_trivial(); }
};
+template<typename T>
+requires(Detail::IsPointerOfType<char, T>) struct Traits<T> : public GenericTraits<T> {
+ 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;