[map] Fix map copy/move constructors to actually work

Ouch!
This commit is contained in:
Behdad Esfahbod 2022-05-12 13:05:32 -06:00
parent a09dd87ca3
commit 7fa580bc4f
4 changed files with 25 additions and 9 deletions

View File

@ -389,9 +389,10 @@ struct hb_map_t : hb_hashmap_t<hb_codepoint_t,
HB_MAP_VALUE_INVALID,
HB_MAP_VALUE_INVALID>;
hb_map_t () = default;
~hb_map_t () = default;
hb_map_t (hb_map_t&) = default;
hb_map_t () : hashmap () {}
hb_map_t (const hb_map_t &o) : hashmap ((hashmap &) o) {}
hb_map_t (hb_map_t &&o) : hashmap (std::move ((hashmap &) o)) {}
hb_map_t& operator= (const hb_map_t&) = default;
hb_map_t& operator= (hb_map_t&&) = default;
hb_map_t (std::initializer_list<hb_pair_t<hb_codepoint_t, hb_codepoint_t>> lst) : hashmap (lst) {}

View File

@ -168,8 +168,7 @@ struct hb_set_t : hb_sparseset_t<hb_bit_set_invertible_t>
hb_set_t& operator= (hb_set_t&&) = default;
hb_set_t (std::initializer_list<hb_codepoint_t> lst) : sparseset (lst) {}
template <typename Iterable,
hb_requires (hb_is_iterable (Iterable) &&
!hb_is_same (hb_decay<Iterable>, hb_set_t))>
hb_requires (hb_is_iterable (Iterable))>
hb_set_t (const Iterable &o) : sparseset (o) {}
};

View File

@ -57,13 +57,21 @@ main (int argc, char **argv)
/* Test move constructor. */
{
hb_map_t v {hb_map_t {}};
hb_map_t s {};
s.set (1, 2);
hb_map_t v (std::move (s));
assert (s.get_population () == 0);
assert (v.get_population () == 1);
}
/* Test move assignment. */
{
hb_map_t s {};
s.set (1, 2);
hb_map_t v;
v = hb_map_t {};
v = std::move (s);
assert (s.get_population () == 0);
assert (v.get_population () == 1);
}
/* Test initializing from iterable. */
@ -73,9 +81,15 @@ main (int argc, char **argv)
s.set (1, 2);
s.set (3, 4);
hb_map_t v (s);
hb_vector_t<hb_pair_t<hb_codepoint_t, hb_codepoint_t>> v (s);
hb_map_t v0 (v);
hb_map_t v1 (s);
hb_map_t v2 (std::move (s));
assert (v.get_population () == 2);
assert (s.get_population () == 0);
assert (v0.get_population () == 2);
assert (v1.get_population () == 2);
assert (v2.get_population () == 2);
}
/* Test call fini() twice. */

View File

@ -50,7 +50,9 @@ main (int argc, char **argv)
/* Test move constructor. */
{
hb_set_t v (hb_set_t {1, 2});
hb_set_t s {1, 2};
hb_set_t v (std::move (s));
assert (s.get_population () == 0);
assert (v.get_population () == 2);
}