[map] Add iterable constructor
diff --git a/src/hb-map.hh b/src/hb-map.hh
index 45bd3cb..e4b7910 100644
--- a/src/hb-map.hh
+++ b/src/hb-map.hh
@@ -52,6 +52,12 @@
for (auto&& item : lst)
set (item.first, item.second);
}
+ template <typename Iterable,
+ hb_requires (hb_is_iterable (Iterable))>
+ 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 2d03058..5761cc8 100644
--- a/src/test-map.cc
+++ b/src/test-map.cc
@@ -64,6 +64,30 @@
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<hb_codepoint_t, hb_codepoint_t>;