From 8ea508ee20bb782b89d7423601f67646003aa269 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Sun, 29 Nov 2020 12:27:41 +0300 Subject: [PATCH] Fix flat_list: destructor hack should only compile for types with nontrivial destructor --- libs/util/include/psemek/util/flat_list.hpp | 38 +++++++++++---------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/libs/util/include/psemek/util/flat_list.hpp b/libs/util/include/psemek/util/flat_list.hpp index 3c8e9dec..6dd9587d 100644 --- a/libs/util/include/psemek/util/flat_list.hpp +++ b/libs/util/include/psemek/util/flat_list.hpp @@ -169,29 +169,31 @@ namespace psemek::util first_ = null; return; } - - if (size_ == 0) + else { + 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(); capacity_ = 0; + size_ = 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(); - capacity_ = 0; - size_ = 0; - first_ = null; } template