mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 02:07:35 +00:00
AK: Add missing GenericTraits<NonnullRefPtr>
This enables us to use keys of type NonnullRefPtr in HashMaps and HashTables. This commit also includes fixes in various places that used HashMap<T, NonnullRefPtr<U>>::get() and expected to get an Optional<NonnullRefPtr<U>> and now get an Optional<U*>.
This commit is contained in:
parent
1da0d402b7
commit
8a01167c7d
6 changed files with 20 additions and 7 deletions
|
@ -9,6 +9,7 @@
|
|||
#include <AK/Assertions.h>
|
||||
#include <AK/Atomic.h>
|
||||
#include <AK/Format.h>
|
||||
#include <AK/Traits.h>
|
||||
#include <AK/Types.h>
|
||||
#ifdef KERNEL
|
||||
# include <Kernel/Arch/x86/CPU.h>
|
||||
|
@ -335,5 +336,13 @@ inline void swap(NonnullRefPtr<T>& a, NonnullRefPtr<U>& b)
|
|||
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
struct Traits<NonnullRefPtr<T>> : public GenericTraits<NonnullRefPtr<T>> {
|
||||
using PeekType = T*;
|
||||
using ConstPeekType = const T*;
|
||||
static unsigned hash(const NonnullRefPtr<T>& p) { return ptr_hash(p.ptr()); }
|
||||
static bool equals(const NonnullRefPtr<T>& a, const NonnullRefPtr<T>& b) { return a.ptr() == b.ptr(); }
|
||||
};
|
||||
|
||||
using AK::adopt_ref;
|
||||
using AK::NonnullRefPtr;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue