From c335bf469f5f1103d5ddf76716f356d026cc30c0 Mon Sep 17 00:00:00 2001 From: Qunxin Liu Date: Mon, 26 Sep 2022 13:01:20 -0700 Subject: [PATCH] support dereferencing shared_ptrs and unique_ptrs --- src/hb-meta.hh | 12 ++++++++++++ src/test-map.cc | 17 +++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/hb-meta.hh b/src/hb-meta.hh index 1921ccbb6..52a6791e3 100644 --- a/src/hb-meta.hh +++ b/src/hb-meta.hh @@ -133,6 +133,18 @@ struct template constexpr auto operator () (T *v) const HB_AUTO_RETURN (*v) + + template constexpr auto + operator () (const hb::shared_ptr& v) const HB_AUTO_RETURN (*v) + + template constexpr auto + operator () (hb::shared_ptr& v) const HB_AUTO_RETURN (*v) + + template constexpr auto + operator () (const hb::unique_ptr& v) const HB_AUTO_RETURN (*v) + + template constexpr auto + operator () (hb::unique_ptr& v) const HB_AUTO_RETURN (*v) } HB_FUNCOBJ (hb_deref); diff --git a/src/test-map.cc b/src/test-map.cc index 473e8f4f6..357a8b01b 100644 --- a/src/test-map.cc +++ b/src/test-map.cc @@ -222,6 +222,23 @@ main (int argc, char **argv) hb::unique_ptr> *v2; m.has (0, &v2); } + /* Test hashmap with complex shared_ptrs as keys. */ + { + hb_hashmap_t, unsigned> m; + hb_map_t *m1 = hb_map_create (); + hb_map_t *m2 = hb_map_create (); + m1->set (1,3); + m2->set (1,3); + + hb::shared_ptr p1 {m1}; + hb::shared_ptr p2 {m2}; + m.set (p1,1); + + assert (m.has (p2)); + + m1->set (2,4); + assert (!m.has (p2)); + } return 0; }