mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
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.
This commit is contained in:
parent
77d462426b
commit
b816bd0806
Notes:
sideshowbarker
2024-07-18 18:30:47 +09:00
Author: https://github.com/itamar8910 Commit: https://github.com/SerenityOS/serenity/commit/b816bd08066 Pull-request: https://github.com/SerenityOS/serenity/pull/6944 Reviewed-by: https://github.com/alimpfard
4 changed files with 7 additions and 3 deletions
|
@ -158,7 +158,8 @@ make(Args&&... args)
|
|||
|
||||
template<typename T>
|
||||
struct Traits<NonnullOwnPtr<T>> : public GenericTraits<NonnullOwnPtr<T>> {
|
||||
using PeekType = const T*;
|
||||
using PeekType = T*;
|
||||
using ConstPeekType = const T*;
|
||||
static unsigned hash(const NonnullOwnPtr<T>& p) { return int_hash((u32)p.ptr()); }
|
||||
static bool equals(const NonnullOwnPtr<T>& a, const NonnullOwnPtr<T>& b) { return a.ptr() == b.ptr(); }
|
||||
};
|
||||
|
|
|
@ -193,7 +193,8 @@ inline void swap(OwnPtr<T>& a, OwnPtr<U>& b)
|
|||
|
||||
template<typename T>
|
||||
struct Traits<OwnPtr<T>> : public GenericTraits<OwnPtr<T>> {
|
||||
using PeekType = const T*;
|
||||
using PeekType = T*;
|
||||
using ConstPeekType = const T*;
|
||||
static unsigned hash(const OwnPtr<T>& p) { return ptr_hash(p.ptr()); }
|
||||
static bool equals(const OwnPtr<T>& a, const OwnPtr<T>& b) { return a.ptr() == b.ptr(); }
|
||||
};
|
||||
|
|
|
@ -451,7 +451,8 @@ struct Formatter<RefPtr<T>> : Formatter<const T*> {
|
|||
|
||||
template<typename T>
|
||||
struct Traits<RefPtr<T>> : public GenericTraits<RefPtr<T>> {
|
||||
using PeekType = const T*;
|
||||
using PeekType = T*;
|
||||
using ConstPeekType = const T*;
|
||||
static unsigned hash(const RefPtr<T>& p) { return ptr_hash(p.ptr()); }
|
||||
static bool equals(const RefPtr<T>& a, const RefPtr<T>& b) { return a.ptr() == b.ptr(); }
|
||||
};
|
||||
|
|
|
@ -14,6 +14,7 @@ namespace AK {
|
|||
template<typename T>
|
||||
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; }
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue