From bad16066392e4dbdd8490a4b1c70d1dcddcc8ec8 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 8 May 2019 12:11:52 -0700 Subject: [PATCH] [map] Make .has() optionally return value --- src/hb-map.hh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/hb-map.hh b/src/hb-map.hh index f27ca9c..13099af 100644 --- a/src/hb-map.hh +++ b/src/hb-map.hh @@ -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); } -- 2.7.4