[map] Make .has() optionally return value

This commit is contained in:
Behdad Esfahbod 2019-05-08 12:11:52 -07:00
parent 750d5af48e
commit bad1606639
1 changed files with 6 additions and 1 deletions

View File

@ -181,7 +181,12 @@ struct hb_hashmap_t
static constexpr V SENTINEL = vINVALID;
typedef V value_t;
value_t operator [] (K k) const { return get (k); }
bool has (K k) const { return (*this)[k] != SENTINEL; }
bool has (K k, V *vp = nullptr) const
{
V v = (*this)[k];
if (vp) *vp = v;
return v != SENTINEL;
}
/* Projection. */
V operator () (K k) const { return get (k); }