mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 03:55:24 +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
Notes:
sideshowbarker
2024-07-18 18:30:43 +09:00
Author: https://github.com/itamar8910 Commit: https://github.com/SerenityOS/serenity/commit/484823e9d52 Pull-request: https://github.com/SerenityOS/serenity/pull/6944 Reviewed-by: https://github.com/alimpfard
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); }
|
||||
|
||||
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…
Add table
Reference in a new issue