AK: Make it possible to use HashMap<K, NonnullOwnPtr>::get()

Add the concept of a PeekType to Traits<T>. This is the type we'll
return (wrapped in an Optional) from HashMap::get().

The PeekType for OwnPtr<T> and NonnullOwnPtr<T> is const T*,
which means that HashMap::get() will return an Optional<const T*> for
maps-of-those.
This commit is contained in:
Andreas Kling 2019-08-14 11:47:38 +02:00
commit fdcff7d15e
Notes: sideshowbarker 2024-07-19 12:41:35 +09:00
6 changed files with 40 additions and 2 deletions

View file

@ -7,6 +7,7 @@ namespace AK {
template<typename T>
struct GenericTraits {
using PeekType = T;
static constexpr bool is_trivial() { return false; }
static bool equals(const T& a, const T& b) { return a == b; }
};
@ -44,7 +45,7 @@ struct Traits<char> : public GenericTraits<char> {
};
template<typename T>
struct Traits<T*> {
struct Traits<T*> : public GenericTraits<T*> {
static unsigned hash(const T* p)
{
return int_hash((unsigned)(__PTRDIFF_TYPE__)p);