[map] Fix copy-assignment operator

Ouch!
This commit is contained in:
Behdad Esfahbod 2022-11-17 15:19:29 -07:00
parent 41f4bdac35
commit 7595fa2d9a
2 changed files with 13 additions and 2 deletions

View File

@ -45,7 +45,7 @@ struct hb_hashmap_t
hb_hashmap_t (const hb_hashmap_t& o) : hb_hashmap_t () { resize (o.population); hb_copy (o, *this); } hb_hashmap_t (const hb_hashmap_t& o) : hb_hashmap_t () { resize (o.population); hb_copy (o, *this); }
hb_hashmap_t (hb_hashmap_t&& o) : hb_hashmap_t () { hb_swap (*this, o); } hb_hashmap_t (hb_hashmap_t&& o) : hb_hashmap_t () { hb_swap (*this, o); }
hb_hashmap_t& operator= (const hb_hashmap_t& o) { resize (o.population); hb_copy (o, *this); return *this; } hb_hashmap_t& operator= (const hb_hashmap_t& o) { reset (); resize (o.population); hb_copy (o, *this); return *this; }
hb_hashmap_t& operator= (hb_hashmap_t&& o) { hb_swap (*this, o); return *this; } hb_hashmap_t& operator= (hb_hashmap_t&& o) { hb_swap (*this, o); return *this; }
hb_hashmap_t (std::initializer_list<hb_pair_t<K, V>> lst) : hb_hashmap_t () hb_hashmap_t (std::initializer_list<hb_pair_t<K, V>> lst) : hb_hashmap_t ()

View File

@ -249,15 +249,26 @@ main (int argc, char **argv)
m.set (1, bytes); m.set (1, bytes);
assert (m.has (1)); assert (m.has (1));
} }
/* Test equality. */ /* Test operators. */
{ {
hb_map_t m1, m2, m3; hb_map_t m1, m2, m3;
m1.set (1, 2); m1.set (1, 2);
m1.set (2, 4);
m2.set (1, 2); m2.set (1, 2);
m2.set (2, 4);
m3.set (1, 3); m3.set (1, 3);
m3.set (3, 5);
assert (m1 == m2); assert (m1 == m2);
assert (m1 != m3); assert (m1 != m3);
assert (!(m2 == m3)); assert (!(m2 == m3));
m2 = m3;
assert (m2.has (1));
assert (!m2.has (2));
assert (m2.has (3));
assert (m3.has (3));
} }
return 0; return 0;