diff --git a/src/hb-map.hh b/src/hb-map.hh index 45bd3cb36..e4b7910a7 100644 --- a/src/hb-map.hh +++ b/src/hb-map.hh @@ -52,6 +52,12 @@ struct hb_hashmap_t for (auto&& item : lst) set (item.first, item.second); } + template + hb_hashmap_t (const Iterable &o) : hb_hashmap_t () + { + hb_copy (o, *this); + } static_assert (hb_is_integral (K) || hb_is_pointer (K), ""); static_assert (hb_is_integral (V) || hb_is_pointer (V), ""); diff --git a/src/test-map.cc b/src/test-map.cc index 2d0305809..5761cc8d6 100644 --- a/src/test-map.cc +++ b/src/test-map.cc @@ -64,6 +64,30 @@ main (int argc, char **argv) v = hb_map_t {}; } + /* Test initializing from iterable. */ + { + hb_map_t s; + + s.set (1, 2); + s.set (3, 4); + + hb_map_t v (s); + + assert (v.get_population () == 2); + } + + /* Test initializing from iterator. */ + { + hb_map_t s; + + s.set (1, 2); + s.set (3, 4); + + hb_map_t v (hb_iter (s)); + + assert (v.get_population () == 2); + } + /* Test initializing from initializer list and swapping. */ { using pair_t = hb_pair_t;