From c2ea5da716aecc0e5190c8cedc16826bcca58189 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Thu, 26 Feb 2015 00:22:23 +0100 Subject: [PATCH] Fix move constructors with unequal allocators and move/copy assignment of tree. --- include/boost/container/deque.hpp | 3 ++- .../boost/container/detail/node_alloc_holder.hpp | 14 +++++++++++++- include/boost/container/detail/tree.hpp | 6 +++--- include/boost/container/list.hpp | 2 +- include/boost/container/map.hpp | 2 +- include/boost/container/set.hpp | 3 +-- include/boost/container/slist.hpp | 7 +------ include/boost/container/stable_vector.hpp | 5 +++-- 8 files changed, 25 insertions(+), 17 deletions(-) diff --git a/include/boost/container/deque.hpp b/include/boost/container/deque.hpp index 632beb5..eb372a4 100644 --- a/include/boost/container/deque.hpp +++ b/include/boost/container/deque.hpp @@ -718,7 +718,8 @@ class deque : protected deque_base if(x.size()){ this->priv_initialize_map(x.size()); boost::container::uninitialized_copy_alloc - (this->alloc(), x.begin(), x.end(), this->members_.m_start); + ( this->alloc(), boost::make_move_iterator(x.begin()) + , boost::make_move_iterator(x.end()), this->members_.m_start); } } } diff --git a/include/boost/container/detail/node_alloc_holder.hpp b/include/boost/container/detail/node_alloc_holder.hpp index 9cf3cd0..98c8e62 100644 --- a/include/boost/container/detail/node_alloc_holder.hpp +++ b/include/boost/container/detail/node_alloc_holder.hpp @@ -370,7 +370,7 @@ struct node_alloc_holder protected: struct cloner { - cloner(node_alloc_holder &holder) + explicit cloner(node_alloc_holder &holder) : m_holder(holder) {} @@ -380,6 +380,18 @@ struct node_alloc_holder node_alloc_holder &m_holder; }; + struct move_cloner + { + move_cloner(node_alloc_holder &holder) + : m_holder(holder) + {} + + NodePtr operator()(Node &other) + { return m_holder.create_node(::boost::move(other.get_data())); } + + node_alloc_holder &m_holder; + }; + struct members_holder : public NodeAlloc { diff --git a/include/boost/container/detail/tree.hpp b/include/boost/container/detail/tree.hpp index e64c5aa..0f90b5a 100644 --- a/include/boost/container/detail/tree.hpp +++ b/include/boost/container/detail/tree.hpp @@ -400,10 +400,10 @@ class RecyclingCloner {} static void do_assign(node_ptr_type &p, const node_type &other, bool_) - { p->do_assign(other.m_data); } + { p->do_move_assign(const_cast(other).m_data); } static void do_assign(node_ptr_type &p, const node_type &other, bool_) - { p->do_move_assign(const_cast(other).m_data); } + { p->do_assign(other.m_data); } node_ptr_type operator()(const node_type &other) const { @@ -663,7 +663,7 @@ class tree } else{ this->icont().clone_from - (x.icont(), typename AllocHolder::cloner(*this), Destroyer(this->node_alloc())); + (x.icont(), typename AllocHolder::move_cloner(*this), Destroyer(this->node_alloc())); } } diff --git a/include/boost/container/list.hpp b/include/boost/container/list.hpp index b24c48f..54da6df 100644 --- a/include/boost/container/list.hpp +++ b/include/boost/container/list.hpp @@ -278,7 +278,7 @@ class list this->icont().swap(x.icont()); } else{ - this->insert(this->cbegin(), x.begin(), x.end()); + this->insert(this->cbegin(), boost::make_move_iterator(x.begin()), boost::make_move_iterator(x.end())); } } diff --git a/include/boost/container/map.hpp b/include/boost/container/map.hpp index bddfb1c..7889517 100644 --- a/include/boost/container/map.hpp +++ b/include/boost/container/map.hpp @@ -1449,5 +1449,5 @@ namespace container { #include -#endif /* BOOST_CONTAINER_MAP_HPP */ +#endif // BOOST_CONTAINER_MAP_HPP diff --git a/include/boost/container/set.hpp b/include/boost/container/set.hpp index f492608..b9e7749 100644 --- a/include/boost/container/set.hpp +++ b/include/boost/container/set.hpp @@ -1154,5 +1154,4 @@ namespace container { #include -#endif /* BOOST_CONTAINER_SET_HPP */ - +#endif // BOOST_CONTAINER_SET_HPP diff --git a/include/boost/container/slist.hpp b/include/boost/container/slist.hpp index b85a335..b0901ef 100644 --- a/include/boost/container/slist.hpp +++ b/include/boost/container/slist.hpp @@ -331,7 +331,7 @@ class slist this->icont().swap(x.icont()); } else{ - this->insert_after(this->cbefore_begin(), x.begin(), x.end()); + this->insert_after(this->cbefore_begin(), boost::make_move_iterator(x.begin()), boost::make_move_iterator(x.end())); } } @@ -1667,11 +1667,6 @@ namespace container { #define BOOST_CONTAINER_CLANG_INLINE_STD_NS #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wc++11-extensions" - #define BOOST_CONTAINER_STD_NS_BEG _LIBCPP_BEGIN_NAMESPACE_STD - #define BOOST_CONTAINER_STD_NS_END _LIBCPP_END_NAMESPACE_STD -#else - #define BOOST_CONTAINER_STD_NS_BEG namespace std{ - #define BOOST_CONTAINER_STD_NS_END } #endif BOOST_CONTAINER_STD_NS_BEG diff --git a/include/boost/container/stable_vector.hpp b/include/boost/container/stable_vector.hpp index 85a6b22..76c9e9f 100644 --- a/include/boost/container/stable_vector.hpp +++ b/include/boost/container/stable_vector.hpp @@ -728,11 +728,12 @@ class stable_vector : internal_data(a), index(a) { if(this->priv_node_alloc() == x.priv_node_alloc()){ + this->index.swap(x.index); this->priv_swap_members(x); } else{ stable_vector_detail::clear_on_destroy cod(*this); - this->insert(this->cend(), x.begin(), x.end()); + this->insert(this->cend(), boost::make_move_iterator(x.begin()), boost::make_move_iterator(x.end())); STABLE_VECTOR_CHECK_INVARIANT; cod.release(); } @@ -808,7 +809,7 @@ class stable_vector //Move allocator if needed container_detail::move_alloc(this_alloc, x_alloc, flag); //Take resources - this->index = boost::move(x.index); + this->index.swap(x.index); this->priv_swap_members(x); } //Else do a one by one move