From 9ea82441c277439479333813e11757a2f74196e7 Mon Sep 17 00:00:00 2001 From: Simon Giraudot Date: Wed, 5 Aug 2020 10:06:49 +0200 Subject: [PATCH] Use unique_ptr and add copy/move semantics --- .../include/CGAL/Small_unordered_set.h | 43 ++++++++++++++++++- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/STL_Extension/include/CGAL/Small_unordered_set.h b/STL_Extension/include/CGAL/Small_unordered_set.h index b55d10c2ac6..86b2f524df4 100644 --- a/STL_Extension/include/CGAL/Small_unordered_set.h +++ b/STL_Extension/include/CGAL/Small_unordered_set.h @@ -50,11 +50,50 @@ class Small_unordered_set using Set = std::unordered_set; Array m_array; - std::shared_ptr m_set; + std::unique_ptr m_set; std::size_t m_size = 0; public: + Small_unordered_set() { } + + ~Small_unordered_set() { } + + Small_unordered_set (const Small_unordered_set& other) + : m_size (other.m_size) + { + if (other.m_set) + m_set = std::make_unique(*other.m_set); + else + m_array = other.m_array; + } + + Small_unordered_set (Small_unordered_set&& other) + : m_size (other.m_size) + { + if (other.m_set) + m_set = std::move(other.m_set); + else + m_array = std::move(other.m_array); + } + + Small_unordered_set& operator= (const Small_unordered_set& other) + { + m_size = other.m_size; + if (other.m_set) + m_set = std::make_unique(*other.m_set); + else + m_array = other.m_array; + } + + Small_unordered_set& operator= (Small_unordered_set&& other) + { + if (other.m_set) + m_set = std::move(other.m_set); + else + m_array = std::move(other.m_array); + } + bool insert (const Key& key) { if (m_size != MaxSize) @@ -68,7 +107,7 @@ public: if (!m_set) { - m_set = std::make_shared(); + m_set = std::make_unique(); m_set->reserve (MaxSize + 1); for (const Key& a : m_array) m_set->insert(a);