Fix flat_list: destructor hack should only compile for types with nontrivial destructor

This commit is contained in:
Nikita Lisitsa 2020-11-29 12:27:41 +03:00
parent 76c465903b
commit 8ea508ee20

View file

@ -169,29 +169,31 @@ namespace psemek::util
first_ = null; first_ = null;
return; return;
} }
else
if (size_ == 0)
{ {
if (size_ == 0)
{
nodes_.reset();
capacity_ = 0;
first_ = null;
return;
}
for (Handle h = first_; h != null;)
{
auto next = nodes_[h].next;
new (&nodes_[h].value) T;
h = next;
}
for (std::size_t i = 0; i < capacity_; ++i)
nodes_[i].value.~T();
nodes_.reset(); nodes_.reset();
capacity_ = 0; capacity_ = 0;
size_ = 0;
first_ = null; first_ = null;
return;
} }
for (Handle h = first_; h != null;)
{
auto next = nodes_[h].next;
new (&nodes_[h].value) T;
h = next;
}
for (std::size_t i = 0; i < capacity_; ++i)
nodes_[i].value.~T();
nodes_.reset();
capacity_ = 0;
size_ = 0;
first_ = null;
} }
template <typename T, typename Handle> template <typename T, typename Handle>