From b816bd08066a342c73a12848f0bdbdf61179b6ce Mon Sep 17 00:00:00 2001 From: Itamar Date: Sat, 8 May 2021 12:11:37 +0300 Subject: [PATCH] AK: Add ConstPeekType to Traits Also, the PeekType of smart pointers is now T* instead of const T*. Note: This commit doesn't compile, it breaks HashMap::get() for some types. Fixed in the next commit. --- AK/NonnullOwnPtr.h | 3 ++- AK/OwnPtr.h | 3 ++- AK/RefPtr.h | 3 ++- AK/Traits.h | 1 + 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/AK/NonnullOwnPtr.h b/AK/NonnullOwnPtr.h index 99405847a72b41..5fa314b927f70e 100644 --- a/AK/NonnullOwnPtr.h +++ b/AK/NonnullOwnPtr.h @@ -158,7 +158,8 @@ make(Args&&... args) template struct Traits> : public GenericTraits> { - using PeekType = const T*; + using PeekType = T*; + using ConstPeekType = const T*; static unsigned hash(const NonnullOwnPtr& p) { return int_hash((u32)p.ptr()); } static bool equals(const NonnullOwnPtr& a, const NonnullOwnPtr& b) { return a.ptr() == b.ptr(); } }; diff --git a/AK/OwnPtr.h b/AK/OwnPtr.h index 2ace9a4cea1c78..416af312e2b540 100644 --- a/AK/OwnPtr.h +++ b/AK/OwnPtr.h @@ -193,7 +193,8 @@ inline void swap(OwnPtr& a, OwnPtr& b) template struct Traits> : public GenericTraits> { - using PeekType = const T*; + using PeekType = T*; + using ConstPeekType = const T*; static unsigned hash(const OwnPtr& p) { return ptr_hash(p.ptr()); } static bool equals(const OwnPtr& a, const OwnPtr& b) { return a.ptr() == b.ptr(); } }; diff --git a/AK/RefPtr.h b/AK/RefPtr.h index e85ba1c93d49ce..687641836a4666 100644 --- a/AK/RefPtr.h +++ b/AK/RefPtr.h @@ -451,7 +451,8 @@ struct Formatter> : Formatter { template struct Traits> : public GenericTraits> { - using PeekType = const T*; + using PeekType = T*; + using ConstPeekType = const T*; static unsigned hash(const RefPtr& p) { return ptr_hash(p.ptr()); } static bool equals(const RefPtr& a, const RefPtr& b) { return a.ptr() == b.ptr(); } }; diff --git a/AK/Traits.h b/AK/Traits.h index aa0630c32ab6d2..19cc078122f8d1 100644 --- a/AK/Traits.h +++ b/AK/Traits.h @@ -14,6 +14,7 @@ namespace AK { template struct GenericTraits { using PeekType = T; + using ConstPeekType = T; static constexpr bool is_trivial() { return false; } static constexpr bool equals(const T& a, const T& b) { return a == b; } };