diff --git a/src/hb-map.hh b/src/hb-map.hh index d7b20f3e2..45bd3cb36 100644 --- a/src/hb-map.hh +++ b/src/hb-map.hh @@ -47,6 +47,12 @@ struct hb_hashmap_t hb_hashmap_t& operator= (const hb_hashmap_t&& o) { hb_copy (o, *this); return *this; } hb_hashmap_t& operator= (hb_hashmap_t&& o) { hb_swap (*this, o); return *this; } + hb_hashmap_t (std::initializer_list> lst) : hb_hashmap_t () + { + for (auto&& item : lst) + set (item.first, item.second); + } + static_assert (hb_is_integral (K) || hb_is_pointer (K), ""); static_assert (hb_is_integral (V) || hb_is_pointer (V), ""); @@ -336,7 +342,22 @@ struct hb_hashmap_t struct hb_map_t : hb_hashmap_t {}; + HB_MAP_VALUE_INVALID> +{ + using hashmap = hb_hashmap_t; + hb_map_t () = default; + ~hb_map_t () = default; + hb_map_t (hb_map_t& o) = default; + hb_map_t& operator= (const hb_map_t& other) = default; + hb_map_t& operator= (hb_map_t&& other) = default; + hb_map_t (std::initializer_list> lst) : hashmap (lst) {} + template + hb_map_t (const Iterable &o) : hashmap (o) {} +}; #endif /* HB_MAP_HH */ diff --git a/src/test-map.cc b/src/test-map.cc index b685530bd..2d0305809 100644 --- a/src/test-map.cc +++ b/src/test-map.cc @@ -64,5 +64,15 @@ main (int argc, char **argv) v = hb_map_t {}; } + /* Test initializing from initializer list and swapping. */ + { + using pair_t = hb_pair_t; + hb_map_t v1 {pair_t{1,2}, pair_t{4,5}}; + hb_map_t v2 {pair_t{3,4}}; + hb_swap (v1, v2); + assert (v1.get_population () == 1); + assert (v2.get_population () == 2); + } + return 0; } diff --git a/src/test-set.cc b/src/test-set.cc index 5c28beb34..286f1a997 100644 --- a/src/test-set.cc +++ b/src/test-set.cc @@ -60,7 +60,7 @@ main (int argc, char **argv) assert (v.get_population () == 2); } - /* Test initializing set from iterable. */ + /* Test initializing from iterable. */ { hb_set_t s; @@ -72,7 +72,7 @@ main (int argc, char **argv) assert (v.get_population () == 2); } - /* Test initializing set from iterator. */ + /* Test initializing from iterator. */ { hb_set_t s; @@ -84,7 +84,7 @@ main (int argc, char **argv) assert (v.get_population () == 2); } - /* Test initializing set from initializer list and swapping. */ + /* Test initializing from initializer list and swapping. */ { hb_set_t v1 {1, 2, 3}; hb_set_t v2 {4, 5};