mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:17:34 +00:00
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:
parent
b816bd0806
commit
484823e9d5
1 changed files with 17 additions and 1 deletions
18
AK/HashMap.h
18
AK/HashMap.h
|
@ -95,7 +95,23 @@ public:
|
||||||
|
|
||||||
void ensure_capacity(size_t capacity) { m_table.ensure_capacity(capacity); }
|
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);
|
auto it = find(key);
|
||||||
if (it == end())
|
if (it == end())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue