From 8e5ffbbe6cfa62d8d9842390dc95d5047ec8dabb Mon Sep 17 00:00:00 2001 From: Daniel James Date: Mon, 3 Sep 2012 20:05:39 +0000 Subject: [PATCH] Unordered: Clean up swap. [SVN r80389] --- include/boost/unordered/detail/table.hpp | 78 +++++++++--------------- 1 file changed, 29 insertions(+), 49 deletions(-) diff --git a/include/boost/unordered/detail/table.hpp b/include/boost/unordered/detail/table.hpp index 7b56bed2..aedab96a 100644 --- a/include/boost/unordered/detail/table.hpp +++ b/include/boost/unordered/detail/table.hpp @@ -436,20 +436,41 @@ namespace boost { namespace unordered { namespace detail { //////////////////////////////////////////////////////////////////////// // Swap and Move - void swap_buckets(table& other, false_type = false_type()) + void swap_allocators(table& other, false_type) { + // According to 23.2.1.8, if propagate_on_container_swap is + // false the behaviour is undefined unless the allocators + // are equal. BOOST_ASSERT(node_alloc() == other.node_alloc()); - boost::swap(buckets_, other.buckets_); - boost::swap(bucket_count_, other.bucket_count_); - boost::swap(size_, other.size_); } - void swap_buckets(table& other, true_type) + void swap_allocators(table& other, true_type) { allocators_.swap(other.allocators_); - boost::swap(buckets_, other.buckets_); - boost::swap(bucket_count_, other.bucket_count_); - boost::swap(size_, other.size_); + } + + // Only swaps the allocators if propagate_on_container_swap + void swap(table& x) + { + boost::unordered::detail::set_hash_functions + op1(*this, x); + boost::unordered::detail::set_hash_functions + op2(x, *this); + + // I think swap can throw if Propagate::value, + // since the allocators' swap can throw. Not sure though. + swap_allocators(x, + boost::unordered::detail::integral_constant:: + propagate_on_container_swap::value>()); + + boost::swap(buckets_, x.buckets_); + boost::swap(bucket_count_, x.bucket_count_); + boost::swap(size_, x.size_); + std::swap(mlf_, x.mlf_); + std::swap(max_load_, x.max_load_); + op1.commit(); + op2.commit(); } void move_buckets_from(table& other) @@ -773,47 +794,6 @@ namespace boost { namespace unordered { namespace detail { new_func_this.commit(); } - //////////////////////////////////////////////////////////////////////// - // Swap & Move - - void swap(table& x) - { - swap(x, - boost::unordered::detail::integral_constant:: - propagate_on_container_swap::value>()); - } - - // Only swaps the allocators if Propagate::value - template - void swap(table& x, Propagate p) - { - // According to 23.2.1.8, if propagate_on_container_swap is - // false the behaviour is undefined unless the allocators - // are equal. - BOOST_ASSERT(p.value || node_alloc() == x.node_alloc()); - - boost::unordered::detail::set_hash_functions - op1(*this, x); - boost::unordered::detail::set_hash_functions - op2(x, *this); - // I think swap can throw if Propagate::value, - // since the allocators' swap can throw. Not sure though. - swap_buckets(x, p); - std::swap(mlf_, x.mlf_); - std::swap(max_load_, x.max_load_); - op1.commit(); - op2.commit(); - } - - // Swap everything but the allocators, and the functions objects. - void swap_contents(table& x) - { - swap_buckets(x, false_type()); - std::swap(mlf_, x.mlf_); - std::swap(max_load_, x.max_load_); - } - // Accessors key_type const& get_key(value_type const& x) const