forked from boostorg/container
Refactor node implemenations from 3 (slist_node, list_node and tree_node) to a single base_node:
- To avoid unneeded includes, is_pair is factored out from pair.hpp implementation - Fixed bug where value_types inside nodes were not allocator-ware destructed. - Changed scoped utilities to handle new clases
This commit is contained in:
1 parent
30a4508371
commit
15d61d6d26
13 files changed
+358
-388
No files matched your search
@@ -121,104 +121,9 @@ struct tree_internal_data_type< std::pair<T1, T2> >
|
||||
typedef pair<typename boost::move_detail::remove_const<T1>::type, T2> type;
|
||||
};
|
||||
|
||||
//The node to be store in the tree
|
||||
template <class T, class VoidPointer, boost::container::tree_type_enum tree_type_value, bool OptimizeSize>
|
||||
struct tree_node
|
||||
: public intrusive_tree_hook<VoidPointer, tree_type_value, OptimizeSize>::type
|
||||
struct iiterator_node_value_type< base_node<T, intrusive_tree_hook<VoidPointer, tree_type_value, OptimizeSize> > >
|
||||
{
|
||||
public:
|
||||
typedef typename intrusive_tree_hook
|
||||
<VoidPointer, tree_type_value, OptimizeSize>::type hook_type;
|
||||
typedef T value_type;
|
||||
typedef typename tree_internal_data_type<T>::type internal_type;
|
||||
|
||||
typedef tree_node< T, VoidPointer
|
||||
, tree_type_value, OptimizeSize> node_t;
|
||||
|
||||
typedef typename boost::container::dtl::aligned_storage
|
||||
<sizeof(T), boost::container::dtl::alignment_of<T>::value>::type storage_t;
|
||||
storage_t m_storage;
|
||||
|
||||
#if defined(BOOST_GCC) && (BOOST_GCC >= 40600) && (BOOST_GCC < 80000)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
|
||||
#define BOOST_CONTAINER_DISABLE_ALIASING_WARNING
|
||||
# endif
|
||||
|
||||
BOOST_CONTAINER_FORCEINLINE T &get_data()
|
||||
{ return *move_detail::force_ptr<T*>(this->m_storage.data); }
|
||||
|
||||
BOOST_CONTAINER_FORCEINLINE const T &get_data() const
|
||||
{ return *move_detail::force_ptr<const T*>(this->m_storage.data); }
|
||||
|
||||
BOOST_CONTAINER_FORCEINLINE T *get_data_ptr()
|
||||
{ return move_detail::force_ptr<T*>(this->m_storage.data); }
|
||||
|
||||
BOOST_CONTAINER_FORCEINLINE const T *get_data_ptr() const
|
||||
{ return move_detail::force_ptr<T*>(this->m_storage.data); }
|
||||
|
||||
BOOST_CONTAINER_FORCEINLINE internal_type &get_real_data()
|
||||
{ return *move_detail::force_ptr<internal_type*>(this->m_storage.data); }
|
||||
|
||||
BOOST_CONTAINER_FORCEINLINE const internal_type &get_real_data() const
|
||||
{ return *move_detail::force_ptr<const internal_type*>(this->m_storage.data); }
|
||||
|
||||
BOOST_CONTAINER_FORCEINLINE internal_type *get_real_data_ptr()
|
||||
{ return move_detail::force_ptr<internal_type*>(this->m_storage.data); }
|
||||
|
||||
BOOST_CONTAINER_FORCEINLINE const internal_type *get_real_data_ptr() const
|
||||
{ return move_detail::force_ptr<internal_type*>(this->m_storage.data); }
|
||||
|
||||
BOOST_CONTAINER_FORCEINLINE ~tree_node()
|
||||
{ move_detail::force_ptr<internal_type*>(this->m_storage.data)->~internal_type(); }
|
||||
|
||||
#if defined(BOOST_CONTAINER_DISABLE_ALIASING_WARNING)
|
||||
#pragma GCC diagnostic pop
|
||||
#undef BOOST_CONTAINER_DISABLE_ALIASING_WARNING
|
||||
# endif
|
||||
|
||||
BOOST_CONTAINER_FORCEINLINE void destroy_header()
|
||||
{ static_cast<hook_type*>(this)->~hook_type(); }
|
||||
|
||||
template<class T1, class T2>
|
||||
BOOST_CONTAINER_FORCEINLINE void do_assign(const std::pair<const T1, T2> &p)
|
||||
{
|
||||
const_cast<T1&>(this->get_real_data().first) = p.first;
|
||||
this->get_real_data().second = p.second;
|
||||
}
|
||||
|
||||
template<class T1, class T2>
|
||||
BOOST_CONTAINER_FORCEINLINE void do_assign(const pair<const T1, T2> &p)
|
||||
{
|
||||
const_cast<T1&>(this->get_real_data().first) = p.first;
|
||||
this->get_real_data().second = p.second;
|
||||
}
|
||||
|
||||
template<class V>
|
||||
BOOST_CONTAINER_FORCEINLINE void do_assign(const V &v)
|
||||
{ this->get_real_data() = v; }
|
||||
|
||||
template<class T1, class T2>
|
||||
BOOST_CONTAINER_FORCEINLINE void do_move_assign(std::pair<const T1, T2> &p)
|
||||
{
|
||||
const_cast<T1&>(this->get_real_data().first) = ::boost::move(p.first);
|
||||
this->get_real_data().second = ::boost::move(p.second);
|
||||
}
|
||||
|
||||
template<class T1, class T2>
|
||||
BOOST_CONTAINER_FORCEINLINE void do_move_assign(pair<const T1, T2> &p)
|
||||
{
|
||||
const_cast<T1&>(this->get_real_data().first) = ::boost::move(p.first);
|
||||
this->get_real_data().second = ::boost::move(p.second);
|
||||
}
|
||||
|
||||
template<class V>
|
||||
BOOST_CONTAINER_FORCEINLINE void do_move_assign(V &v)
|
||||
{ this->get_real_data() = ::boost::move(v); }
|
||||
};
|
||||
|
||||
template <class T, class VoidPointer, boost::container::tree_type_enum tree_type_value, bool OptimizeSize>
|
||||
struct iiterator_node_value_type< tree_node<T, VoidPointer, tree_type_value, OptimizeSize> > {
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
@@ -321,9 +226,8 @@ struct intrusive_tree_type
|
||||
allocator_traits<Allocator>::void_pointer void_pointer;
|
||||
typedef typename boost::container::
|
||||
allocator_traits<Allocator>::size_type size_type;
|
||||
typedef typename dtl::tree_node
|
||||
< value_type, void_pointer
|
||||
, tree_type_value, OptimizeSize> node_t;
|
||||
typedef base_node<value_type, intrusive_tree_hook
|
||||
<void_pointer, tree_type_value, OptimizeSize> > node_t;
|
||||
typedef value_to_node_compare
|
||||
<node_t, ValueCompare> node_compare_type;
|
||||
//Deducing the hook type from node_t (e.g. node_t::hook_type) would
|
||||
@@ -388,10 +292,10 @@ class RecyclingCloner
|
||||
: m_holder(holder), m_icont(itree)
|
||||
{}
|
||||
|
||||
BOOST_CONTAINER_FORCEINLINE static void do_assign(node_ptr_type &p, node_t &other, bool_<true>)
|
||||
BOOST_CONTAINER_FORCEINLINE static void do_assign(node_ptr_type p, node_t &other, bool_<true>)
|
||||
{ p->do_move_assign(other.get_real_data()); }
|
||||
|
||||
BOOST_CONTAINER_FORCEINLINE static void do_assign(node_ptr_type &p, const node_t &other, bool_<false>)
|
||||
BOOST_CONTAINER_FORCEINLINE static void do_assign(node_ptr_type p, const node_t &other, bool_<false>)
|
||||
{ p->do_assign(other.get_real_data()); }
|
||||
|
||||
node_ptr_type operator()
|
||||
@@ -440,7 +344,7 @@ struct key_node_compare
|
||||
|
||||
template <class T, class VoidPointer, boost::container::tree_type_enum tree_type_value, bool OptimizeSize>
|
||||
BOOST_CONTAINER_FORCEINLINE static const key_type &
|
||||
key_from(const tree_node<T, VoidPointer, tree_type_value, OptimizeSize> &n)
|
||||
key_from(const base_node<T, intrusive_tree_hook<VoidPointer, tree_type_value, OptimizeSize> > &n)
|
||||
{
|
||||
return key_of_value()(n.get_data());
|
||||
}
|
||||
@@ -505,7 +409,7 @@ struct real_key_of_value<std::pair<T1, T2>, int>
|
||||
};
|
||||
|
||||
template<class T1, class T2>
|
||||
struct real_key_of_value<boost::container::pair<T1, T2>, int>
|
||||
struct real_key_of_value<boost::container::dtl::pair<T1, T2>, int>
|
||||
{
|
||||
typedef dtl::select1st<T1> type;
|
||||
};
|
||||
@@ -552,7 +456,7 @@ class tree
|
||||
typedef typename AllocHolder::Node Node;
|
||||
typedef typename Icont::iterator iiterator;
|
||||
typedef typename Icont::const_iterator iconst_iterator;
|
||||
typedef dtl::allocator_destroyer<NodeAlloc> Destroyer;
|
||||
typedef dtl::allocator_node_destroyer<NodeAlloc> Destroyer;
|
||||
typedef typename AllocHolder::alloc_version alloc_version;
|
||||
typedef intrusive_tree_proxy<options_type::tree_type> intrusive_tree_proxy_t;
|
||||
|
||||
@@ -1000,7 +904,7 @@ class tree
|
||||
(BOOST_FWD_REF(MovableConvertible) v, insert_commit_data &data)
|
||||
{
|
||||
NodePtr tmp = AllocHolder::create_node(boost::forward<MovableConvertible>(v));
|
||||
scoped_destroy_deallocator<NodeAlloc> destroy_deallocator(tmp, this->node_alloc());
|
||||
scoped_node_destroy_deallocator<NodeAlloc> destroy_deallocator(tmp, this->node_alloc());
|
||||
iterator ret(this->icont().insert_unique_commit(*tmp, data));
|
||||
destroy_deallocator.release();
|
||||
return ret;
|
||||
@@ -1038,7 +942,7 @@ class tree
|
||||
(BOOST_FWD_REF(KeyConvertible) key, BOOST_FWD_REF(M) obj, insert_commit_data &data)
|
||||
{
|
||||
NodePtr tmp = AllocHolder::create_node(boost::forward<KeyConvertible>(key), boost::forward<M>(obj));
|
||||
scoped_destroy_deallocator<NodeAlloc> destroy_deallocator(tmp, this->node_alloc());
|
||||
scoped_node_destroy_deallocator<NodeAlloc> destroy_deallocator(tmp, this->node_alloc());
|
||||
iiterator ret(this->icont().insert_unique_commit(*tmp, data));
|
||||
destroy_deallocator.release();
|
||||
return ret;
|
||||
@@ -1065,7 +969,7 @@ class tree
|
||||
{
|
||||
value_type &v = p->get_data();
|
||||
insert_commit_data data;
|
||||
scoped_destroy_deallocator<NodeAlloc> destroy_deallocator(p, this->node_alloc());
|
||||
scoped_node_destroy_deallocator<NodeAlloc> destroy_deallocator(p, this->node_alloc());
|
||||
std::pair<iterator,bool> ret =
|
||||
this->insert_unique_check(key_of_value_t()(v), data);
|
||||
if(!ret.second){
|
||||
@@ -1109,7 +1013,7 @@ class tree
|
||||
iterator emplace_equal(BOOST_FWD_REF(Args)... args)
|
||||
{
|
||||
NodePtr tmp(AllocHolder::create_node(boost::forward<Args>(args)...));
|
||||
scoped_destroy_deallocator<NodeAlloc> destroy_deallocator(tmp, this->node_alloc());
|
||||
scoped_node_destroy_deallocator<NodeAlloc> destroy_deallocator(tmp, this->node_alloc());
|
||||
iterator ret(this->icont().insert_equal(this->icont().end(), *tmp));
|
||||
destroy_deallocator.release();
|
||||
return ret;
|
||||
@@ -1120,7 +1024,7 @@ class tree
|
||||
{
|
||||
BOOST_ASSERT((priv_is_linked)(hint));
|
||||
NodePtr tmp(AllocHolder::create_node(boost::forward<Args>(args)...));
|
||||
scoped_destroy_deallocator<NodeAlloc> destroy_deallocator(tmp, this->node_alloc());
|
||||
scoped_node_destroy_deallocator<NodeAlloc> destroy_deallocator(tmp, this->node_alloc());
|
||||
iterator ret(this->icont().insert_equal(hint.get(), *tmp));
|
||||
destroy_deallocator.release();
|
||||
return ret;
|
||||
@@ -1157,7 +1061,7 @@ class tree
|
||||
iterator emplace_equal(BOOST_MOVE_UREF##N)\
|
||||
{\
|
||||
NodePtr tmp(AllocHolder::create_node(BOOST_MOVE_FWD##N));\
|
||||
scoped_destroy_deallocator<NodeAlloc> destroy_deallocator(tmp, this->node_alloc());\
|
||||
scoped_node_destroy_deallocator<NodeAlloc> destroy_deallocator(tmp, this->node_alloc());\
|
||||
iterator ret(this->icont().insert_equal(this->icont().end(), *tmp));\
|
||||
destroy_deallocator.release();\
|
||||
return ret;\
|
||||
@@ -1168,7 +1072,7 @@ class tree
|
||||
{\
|
||||
BOOST_ASSERT((priv_is_linked)(hint));\
|
||||
NodePtr tmp(AllocHolder::create_node(BOOST_MOVE_FWD##N));\
|
||||
scoped_destroy_deallocator<NodeAlloc> destroy_deallocator(tmp, this->node_alloc());\
|
||||
scoped_node_destroy_deallocator<NodeAlloc> destroy_deallocator(tmp, this->node_alloc());\
|
||||
iterator ret(this->icont().insert_equal(hint.get(), *tmp));\
|
||||
destroy_deallocator.release();\
|
||||
return ret;\
|
||||
@@ -1208,7 +1112,7 @@ class tree
|
||||
iterator insert_equal_convertible(BOOST_FWD_REF(MovableConvertible) v)
|
||||
{
|
||||
NodePtr tmp(AllocHolder::create_node(boost::forward<MovableConvertible>(v)));
|
||||
scoped_destroy_deallocator<NodeAlloc> destroy_deallocator(tmp, this->node_alloc());
|
||||
scoped_node_destroy_deallocator<NodeAlloc> destroy_deallocator(tmp, this->node_alloc());
|
||||
iterator ret(this->icont().insert_equal(this->icont().end(), *tmp));
|
||||
destroy_deallocator.release();
|
||||
return ret;
|
||||
@@ -1219,7 +1123,7 @@ class tree
|
||||
{
|
||||
BOOST_ASSERT((priv_is_linked)(hint));
|
||||
NodePtr tmp(AllocHolder::create_node(boost::forward<MovableConvertible>(v)));
|
||||
scoped_destroy_deallocator<NodeAlloc> destroy_deallocator(tmp, this->node_alloc());
|
||||
scoped_node_destroy_deallocator<NodeAlloc> destroy_deallocator(tmp, this->node_alloc());
|
||||
iterator ret(this->icont().insert_equal(hint.get(), *tmp));
|
||||
destroy_deallocator.release();
|
||||
return ret;
|
||||
|
||||
Reference in new issue
Block a user