[map] Destruct objects

This commit is contained in:
Behdad Esfahbod 2022-01-13 15:06:58 -07:00
parent 726b1a8b2d
commit 956e0a4d13
2 changed files with 8 additions and 5 deletions

View File

@ -61,9 +61,6 @@ struct hb_hashmap_t
hb_copy (o, *this);
}
static_assert (std::is_trivially_destructible<K>::value, "");
static_assert (std::is_trivially_destructible<V>::value, "");
struct item_t
{
K key;
@ -134,6 +131,9 @@ struct hb_hashmap_t
}
void fini_shallow ()
{
unsigned size = mask + 1;
for (unsigned i = 0; i < size; i++)
items[i].~item_t ();
hb_free (items);
items = nullptr;
population = occupancy = 0;
@ -179,10 +179,15 @@ struct hb_hashmap_t
/* Insert back old items. */
if (old_items)
for (unsigned int i = 0; i < old_size; i++)
{
if (old_items[i].is_real ())
{
set_with_hash (old_items[i].key,
old_items[i].hash,
std::move (old_items[i].value));
}
old_items[i].~item_t ();
}
hb_free (old_items);

View File

@ -110,7 +110,6 @@ main (int argc, char **argv)
assert (m3.get_population () == 0);
}
#if 0
{
hb_hashmap_t<int, int, int, int, 0, 0> m0;
hb_hashmap_t<std::string, int, const std::string*, int, &invalid, 0> m1;
@ -127,7 +126,6 @@ main (int argc, char **argv)
m3.set (s, s);
}
}
#endif
return 0;
}