[map] Add iterable constructor
This commit is contained in:
parent
a03b9b14c9
commit
94158316d9
|
@ -52,6 +52,12 @@ struct hb_hashmap_t
|
||||||
for (auto&& item : lst)
|
for (auto&& item : lst)
|
||||||
set (item.first, item.second);
|
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 (K) || hb_is_pointer (K), "");
|
||||||
static_assert (hb_is_integral (V) || hb_is_pointer (V), "");
|
static_assert (hb_is_integral (V) || hb_is_pointer (V), "");
|
||||||
|
|
|
@ -64,6 +64,30 @@ main (int argc, char **argv)
|
||||||
v = hb_map_t {};
|
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. */
|
/* Test initializing from initializer list and swapping. */
|
||||||
{
|
{
|
||||||
using pair_t = hb_pair_t<hb_codepoint_t, hb_codepoint_t>;
|
using pair_t = hb_pair_t<hb_codepoint_t, hb_codepoint_t>;
|
||||||
|
|
Loading…
Reference in New Issue