From 0d912f754f0eac05f81f314a5f40eed8fa61645e Mon Sep 17 00:00:00 2001 From: greg7mdp Date: Sun, 11 Sep 2022 10:07:32 -0400 Subject: [PATCH] Allow swapping parallel hash maps/sets with different mutex types --- parallel_hashmap/phmap.h | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/parallel_hashmap/phmap.h b/parallel_hashmap/phmap.h index 3d11e0e..cf6789e 100644 --- a/parallel_hashmap/phmap.h +++ b/parallel_hashmap/phmap.h @@ -3473,14 +3473,19 @@ public: return it == end() ? node_type() : extract(const_iterator{it}); } - void swap(parallel_hash_set& that) noexcept( - IsNoThrowSwappable() && - (!AllocTraits::propagate_on_container_swap::value || - IsNoThrowSwappable())) { + template + void swap(parallel_hash_set& that) + noexcept(IsNoThrowSwappable() && + (!AllocTraits::propagate_on_container_swap::value || + IsNoThrowSwappable())) + { using std::swap; + using Lockable2 = phmap::LockableImpl; + for (size_t i=0; i friend void swap(parallel_hash_set& a, - parallel_hash_set& b) noexcept(noexcept(a.swap(b))) { + parallel_hash_set& b) + noexcept(noexcept(a.swap(b))) + { a.swap(b); } @@ -3700,14 +3708,16 @@ private: // TODO(alkis): Optimize this assuming *this and that don't overlap. // -------------------------------------------------------------------- - parallel_hash_set& move_assign(parallel_hash_set&& that, std::true_type) { - parallel_hash_set tmp(std::move(that)); + template + parallel_hash_set& move_assign(parallel_hash_set&& that, std::true_type) { + parallel_hash_set tmp(std::move(that)); swap(tmp); return *this; } - parallel_hash_set& move_assign(parallel_hash_set&& that, std::false_type) { - parallel_hash_set tmp(std::move(that), alloc_ref()); + template + parallel_hash_set& move_assign(parallel_hash_set&& that, std::false_type) { + parallel_hash_set tmp(std::move(that), alloc_ref()); swap(tmp); return *this; }