[map] Allow geting non-const value pointer out with has()

This commit is contained in:
Behdad Esfahbod 2022-07-20 14:43:58 -06:00
parent 00cfc5c17d
commit 61c0438425
2 changed files with 6 additions and 1 deletions

View File

@ -219,7 +219,8 @@ struct hb_hashmap_t
/* Has interface. */ /* Has interface. */
typedef const V& value_t; typedef const V& value_t;
value_t operator [] (K k) const { return get (k); } value_t operator [] (K k) const { return get (k); }
bool has (K key, const V **vp = nullptr) const template <typename VV=V>
bool has (K key, VV **vp = nullptr) const
{ {
if (unlikely (!items)) if (unlikely (!items))
return false; return false;

View File

@ -217,6 +217,10 @@ main (int argc, char **argv)
hb_hashmap_t<int, hb::unique_ptr<hb_hashmap_t<int, int>>> m; hb_hashmap_t<int, hb::unique_ptr<hb_hashmap_t<int, int>>> m;
m.get (0); m.get (0);
const hb::unique_ptr<hb_hashmap_t<int, int>> *v1;
m.has (0, &v1);
hb::unique_ptr<hb_hashmap_t<int, int>> *v2;
m.has (0, &v2);
} }
return 0; return 0;