Browse Source

AK: Return Optional<ConstPeekType> for HashMap::get() const

While the previous implementation always copied the object, returning a
non-const reference to a const object is not valid.
Ali Mohammad Pur 3 years ago
parent
commit
1a74895680
1 changed files with 1 additions and 1 deletions
  1. 1 1
      AK/HashMap.h

+ 1 - 1
AK/HashMap.h

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