From 94ef1ac3916d2bc1296efc7dd4d1a50c859bfb68 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Mon, 17 Sep 2012 18:59:29 +0000 Subject: [PATCH] Unordered: Support empty containers in node_holder. [SVN r80562] --- include/boost/unordered/detail/buckets.hpp | 12 +++++++----- include/boost/unordered/detail/table.hpp | 9 +++------ 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/include/boost/unordered/detail/buckets.hpp b/include/boost/unordered/detail/buckets.hpp index 4bfae1c9..def5c7c7 100644 --- a/include/boost/unordered/detail/buckets.hpp +++ b/include/boost/unordered/detail/buckets.hpp @@ -444,10 +444,12 @@ namespace boost { namespace unordered { namespace detail { base(b.node_alloc()), nodes_() { - typename Table::previous_pointer prev = b.get_previous_start(); - nodes_ = static_cast(prev->next_); - prev->next_ = link_pointer(); - b.size_ = 0; + if (b.size_) { + typename Table::previous_pointer prev = b.get_previous_start(); + nodes_ = static_cast(prev->next_); + prev->next_ = link_pointer(); + b.size_ = 0; + } } ~node_holder(); @@ -508,7 +510,7 @@ namespace boost { namespace unordered { namespace detail { } } - iterator get_start() const + iterator begin() const { return iterator(nodes_); } diff --git a/include/boost/unordered/detail/table.hpp b/include/boost/unordered/detail/table.hpp index 3713d063..a1c4dd69 100644 --- a/include/boost/unordered/detail/table.hpp +++ b/include/boost/unordered/detail/table.hpp @@ -400,7 +400,7 @@ namespace boost { namespace unordered { namespace detail { move_nodes move(node_alloc()); node_holder nodes(x); - table_impl::fill_buckets(nodes.get_start(), *this, move); + table_impl::fill_buckets(nodes.begin(), *this, move); } } @@ -765,11 +765,8 @@ namespace boost { namespace unordered { namespace detail { // elements, assigning to them if possible, and deleting // any that are left over. move_assign_nodes assign(*this); - - if (x.size_) { - node_holder nodes(x); - table_impl::fill_buckets(nodes.get_start(), *this, assign); - } + node_holder nodes(x); + table_impl::fill_buckets(nodes.begin(), *this, assign); } }