aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@behdad.org>2021-11-01 22:47:26 -0600
committerBehdad Esfahbod <behdad@behdad.org>2021-11-01 22:47:26 -0600
commit94158316d9ba69315497a200ec63d13cb6959363 (patch)
tree392f5ab5cfc6172a561a5cccf1c23a88433c9c03
parenta03b9b14c988aa04ba3ee1e5d187b65e7b24015a (diff)
downloadharfbuzz_ng-94158316d9ba69315497a200ec63d13cb6959363.tar.gz
[map] Add iterable constructor
-rw-r--r--src/hb-map.hh6
-rw-r--r--src/test-map.cc24
2 files changed, 30 insertions, 0 deletions
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 <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 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<hb_codepoint_t, hb_codepoint_t>;