From e198da5946b74cc6ad430ae5541b0d83b2b6be96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Thu, 4 Jun 2015 11:42:47 +0200 Subject: [PATCH] Use Intrusive's tree_value_compare class instead of duplicating code --- .../container/detail/node_alloc_holder.hpp | 4 +- include/boost/container/detail/tree.hpp | 53 ++----------------- 2 files changed, 6 insertions(+), 51 deletions(-) diff --git a/include/boost/container/detail/node_alloc_holder.hpp b/include/boost/container/detail/node_alloc_holder.hpp index a95184c..0d4e273 100644 --- a/include/boost/container/detail/node_alloc_holder.hpp +++ b/include/boost/container/detail/node_alloc_holder.hpp @@ -415,12 +415,12 @@ struct node_alloc_holder template members_holder(BOOST_FWD_REF(ConvertibleToAlloc) c2alloc, const value_compare &c) : NodeAlloc(boost::forward(c2alloc)) - , m_icont(typename ICont::value_compare(c)) + , m_icont(typename ICont::key_compare(c)) {} explicit members_holder(const value_compare &c) : NodeAlloc() - , m_icont(typename ICont::value_compare(c)) + , m_icont(typename ICont::key_compare(c)) {} //The intrusive container diff --git a/include/boost/container/detail/tree.hpp b/include/boost/container/detail/tree.hpp index 365e85a..c902029 100644 --- a/include/boost/container/detail/tree.hpp +++ b/include/boost/container/detail/tree.hpp @@ -43,6 +43,7 @@ #include // intrusive/detail #include //pair +#include //tree_value_compare // move #include // move/detail @@ -60,53 +61,7 @@ namespace boost { namespace container { namespace container_detail { -template -struct tree_value_compare - : public Compare -{ - typedef T value_type; - typedef Compare key_compare; - typedef KeyOfValue key_of_value; - typedef Key key_type; - - explicit tree_value_compare(const key_compare &kcomp) - : Compare(kcomp) - {} - - tree_value_compare() - : Compare() - {} - - const key_compare &key_comp() const - { return static_cast(*this); } - - key_compare &key_comp() - { return static_cast(*this); } - - template - struct is_key - { - static const bool value = is_same::value; - }; - - template - typename enable_if_c::value, const key_type &>::type - key_forward(const U &key) const - { return key; } - - template - typename enable_if_c::value, const key_type &>::type - key_forward(const U &key) const - { return KeyOfValue()(key); } - - template - bool operator()(const KeyType &key1, const KeyType2 &key2) const - { return key_compare::operator()(this->key_forward(key1), this->key_forward(key2)); } - - template - bool operator()(const KeyType &key1, const KeyType2 &key2) - { return key_compare::operator()(this->key_forward(key1), this->key_forward(key2)); } -}; +using boost::intrusive::tree_value_compare; template struct intrusive_tree_hook; @@ -671,7 +626,7 @@ class tree } else{ this->icont().clone_from - (x.icont(), typename AllocHolder::move_cloner(*this), Destroyer(this->node_alloc())); + (boost::move(x.icont()), typename AllocHolder::move_cloner(*this), Destroyer(this->node_alloc())); } } @@ -738,7 +693,7 @@ class tree //Now recreate the source tree reusing nodes stored by other_tree this->icont().clone_from - (x.icont() + (::boost::move(x.icont()) , RecyclingCloner(*this, other_tree) , Destroyer(this->node_alloc()));