AK: Add a non-const overload to HapMap::get()

Additionally, the const version of get() returns Optional<ConstPeekType>
for smart pointers.

For example, if the value in the HashMap is OwnPtr<u32>,
HashMap::get() const returns Optional<const u32*>.
This commit is contained in:
Itamar 2021-05-08 12:12:32 +03:00 committed by Andreas Kling
parent b816bd0806
commit 484823e9d5

View file

@ -95,7 +95,23 @@ public:
void ensure_capacity(size_t capacity) { m_table.ensure_capacity(capacity); }
Optional<typename Traits<V>::PeekType> get(const K& key) const
Optional<typename Traits<V>::PeekType> get(const K& key) const requires(!IsPointer<typename Traits<V>::PeekType>)
{
auto it = find(key);
if (it == end())
return {};
return (*it).value;
}
Optional<typename Traits<V>::ConstPeekType> get(const K& key) const requires(IsPointer<typename Traits<V>::PeekType>)
{
auto it = find(key);
if (it == end())
return {};
return (*it).value;
}
Optional<typename Traits<V>::PeekType> get(const K& key) requires(!IsConst<typename Traits<V>::PeekType>)
{
auto it = find(key);
if (it == end())