mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-15 04:13:11 +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
18
AK/HashMap.h
18
AK/HashMap.h
|
@ -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())
|
||||
|
|
Loading…
Reference in a new issue