From 0221f1a9bd2cac984e21575b9c1246da23b952ab Mon Sep 17 00:00:00 2001 From: Daniel James Date: Sun, 27 Jan 2013 23:10:29 +0000 Subject: [PATCH] Unordered: Merge assign fix. [SVN r82651] --- include/boost/unordered/detail/buckets.hpp | 68 +++++++++++----------- 1 file changed, 33 insertions(+), 35 deletions(-) diff --git a/include/boost/unordered/detail/buckets.hpp b/include/boost/unordered/detail/buckets.hpp index 39f7df0f..f3602339 100644 --- a/include/boost/unordered/detail/buckets.hpp +++ b/include/boost/unordered/detail/buckets.hpp @@ -321,9 +321,6 @@ namespace boost { namespace unordered { namespace detail { protected: node_allocator& alloc_; - - private: - node_pointer node_; bool node_constructed_; bool value_constructed_; @@ -464,60 +461,61 @@ namespace boost { namespace unordered { namespace detail { ~node_holder(); + void node_for_assignment() + { + if (!this->node_ && nodes_) { + this->node_ = nodes_; + nodes_ = static_cast(nodes_->next_); + this->node_->init(this->node_); + this->node_->next_ = link_pointer(); + + this->node_constructed_ = true; + this->value_constructed_ = true; + } + } + template inline void assign_impl(T const& v) { - nodes_->value() = v; + if (this->node_ && this->value_constructed_) { + this->node_->value() = v; + } + else { + this->construct_with_value2(v); + } } template inline void assign_impl(std::pair const& v) { - const_cast(nodes_->value().first) = v.first; - nodes_->value().second = v.second; + this->construct_with_value2(v); } template inline void move_assign_impl(T& v) { - nodes_->value() = boost::move(v); + if (this->node_ && this->value_constructed_) { + this->node_->value() = boost::move(v); + } + else { + this->construct_with_value2(boost::move(v)); + } } template inline void move_assign_impl(std::pair& v) { - // TODO: Move key as well? - const_cast(nodes_->value().first) = - boost::move(const_cast(v.first)); - nodes_->value().second = boost::move(v.second); + this->construct_with_value2(boost::move(v)); } node_pointer copy_of(value_type const& v) { - if (nodes_) { - assign_impl(v); - node_pointer p = nodes_; - nodes_ = static_cast(p->next_); - p->init(p); - p->next_ = link_pointer(); - return p; - } - else { - this->construct_with_value2(v); - return base::release(); - } + node_for_assignment(); + assign_impl(v); + return base::release(); } node_pointer move_copy_of(value_type& v) { - if (nodes_) { - move_assign_impl(v); - node_pointer p = nodes_; - nodes_ = static_cast(p->next_); - p->init(p); - p->next_ = link_pointer(); - return p; - } - else { - this->construct_with_value2(boost::move(v)); - return base::release(); - } + node_for_assignment(); + move_assign_impl(v); + return base::release(); } iterator begin() const