diff --git a/include/util/deallocating_vector.hpp b/include/util/deallocating_vector.hpp index 1ab630792..3d8c49488 100644 --- a/include/util/deallocating_vector.hpp +++ b/include/util/deallocating_vector.hpp @@ -6,6 +6,7 @@ #include +#include #include #include #include @@ -254,9 +255,25 @@ template class DeallocatingVector bucket_list.emplace_back(new ElementT[ELEMENTS_PER_BLOCK]); } - // copying is not safe since this would only do a shallow copy - DeallocatingVector(DeallocatingVector &other) = delete; - DeallocatingVector &operator=(DeallocatingVector &other) = delete; + // Performs a deep copy of the buckets + DeallocatingVector(const DeallocatingVector &other) + { + bucket_list.resize(other.bucket_list.size()); + for (const auto index : util::irange(0, bucket_list.size())) + { + bucket_list[index] = new ElementT[ELEMENTS_PER_BLOCK]; + std::copy_n(other.bucket_list[index], ELEMENTS_PER_BLOCK, bucket_list[index]); + } + current_size = other.current_size; + } + // Note we capture other by value + DeallocatingVector &operator=(const DeallocatingVector &other) + { + auto copy_other = other; + swap(copy_other); + return *this; + } + // moving is fine DeallocatingVector(DeallocatingVector &&other) { swap(other); } DeallocatingVector &operator=(DeallocatingVector &&other) diff --git a/include/util/dynamic_graph.hpp b/include/util/dynamic_graph.hpp index 4f091c02b..f2eaa211d 100644 --- a/include/util/dynamic_graph.hpp +++ b/include/util/dynamic_graph.hpp @@ -120,6 +120,23 @@ template class DynamicGraph } } + DynamicGraph(const DynamicGraph &other) + { + number_of_nodes = other.number_of_nodes; + // atomics can't be moved this is why we need an own constructor + number_of_edges = static_cast(other.number_of_edges); + + node_array = other.node_array; + edge_list = other.edge_list; + } + + DynamicGraph&operator=(const DynamicGraph &other) + { + auto copy_other = other; + *this = std::move(other); + return *this; + } + DynamicGraph(DynamicGraph &&other) { number_of_nodes = other.number_of_nodes;