mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 23:27:43 +00:00
AK: Add basic Traits for RefPtr
This allows RefPtr to be stored in a HashTable<RefPtr<T>> :^) It's unfortunate about the const_casts. We'll need to fix HashMap::get to play nice with non-const Traits<T>::PeekType at some point.
This commit is contained in:
parent
9794e18a20
commit
a6e69bda71
5 changed files with 13 additions and 6 deletions
|
@ -29,6 +29,7 @@
|
|||
#include <AK/LogStream.h>
|
||||
#include <AK/NonnullRefPtr.h>
|
||||
#include <AK/StdLibExtras.h>
|
||||
#include <AK/Traits.h>
|
||||
#include <AK/Types.h>
|
||||
|
||||
namespace AK {
|
||||
|
@ -274,6 +275,13 @@ inline const LogStream& operator<<(const LogStream& stream, const RefPtr<T>& val
|
|||
return stream << value.ptr();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
struct Traits<RefPtr<T>> : public GenericTraits<RefPtr<T>> {
|
||||
using PeekType = const T*;
|
||||
static unsigned hash(const RefPtr<T>& p) { return int_hash((u32)p.ptr()); }
|
||||
static bool equals(const RefPtr<T>& a, const RefPtr<T>& b) { return a.ptr() == b.ptr(); }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
using AK::RefPtr;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue