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:
Ion Gaztañaga
2022-01-04 00:41:34 +01:00
parent 30a4508371
commit 15d61d6d26
13 changed files with 358 additions and 388 deletions
+27 -83
View File
@@ -72,64 +72,9 @@ struct slist_hook
<dtl::bi::void_pointer<VoidPointer>, dtl::bi::link_mode<dtl::bi::normal_link> >::type type;
};
template <class T, class VoidPointer>
struct slist_node
: public slist_hook<VoidPointer>::type
struct iiterator_node_value_type< base_node<T, slist_hook<VoidPointer> > >
{
public:
typedef T value_type;
typedef T internal_type;
typedef typename slist_hook<VoidPointer>::type hook_type;
typedef typename dtl::aligned_storage<sizeof(T), 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 ~slist_node()
{ move_detail::force_ptr<T*>(this->m_storage.data)->~T(); }
#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 T, class VoidPointer>
struct iiterator_node_value_type< slist_node<T,VoidPointer> > {
typedef T type;
};
@@ -142,8 +87,7 @@ struct intrusive_slist_type
<typename allocator_traits_type::pointer>::template
rebind_pointer<void>::type
void_pointer;
typedef typename dtl::slist_node
<value_type, void_pointer> node_type;
typedef base_node<value_type, slist_hook<void_pointer> > node_type;
typedef typename dtl::bi::make_slist
<node_type
@@ -214,7 +158,7 @@ class slist
typedef typename AllocHolder::NodeAlloc NodeAlloc;
typedef typename AllocHolder::ValAlloc ValAlloc;
typedef typename AllocHolder::Node Node;
typedef dtl::allocator_destroyer<NodeAlloc> Destroyer;
typedef dtl::allocator_node_destroyer<NodeAlloc> Destroyer;
typedef typename AllocHolder::alloc_version alloc_version;
typedef boost::container::
allocator_traits<ValueAllocator> allocator_traits_type;
@@ -249,7 +193,7 @@ class slist
//////////////////////////////////////////////
//
// construct/copy/destroy
// constructFr/copy/destroy
//
//////////////////////////////////////////////
@@ -369,11 +313,12 @@ class slist
slist(BOOST_RV_REF(slist) x, const allocator_type &a)
: AllocHolder(a)
{
if(this->node_alloc() == x.node_alloc()){
this->icont().swap(x.icont());
slist & sr = x;
if(this->node_alloc() == sr.node_alloc()){
this->icont().swap(sr.icont());
}
else{
this->insert_after(this->cbefore_begin(), boost::make_move_iterator(x.begin()), boost::make_move_iterator(x.end()));
this->insert_after(this->cbefore_begin(), boost::make_move_iterator(sr.begin()), boost::make_move_iterator(sr.end()));
}
}
@@ -425,9 +370,10 @@ class slist
BOOST_NOEXCEPT_IF(allocator_traits_type::propagate_on_container_move_assignment::value
|| allocator_traits_type::is_always_equal::value)
{
if (BOOST_LIKELY(this != &x)) {
slist & sr = x;
if (BOOST_LIKELY(this != &sr)) {
NodeAlloc &this_alloc = this->node_alloc();
NodeAlloc &x_alloc = x.node_alloc();
NodeAlloc &x_alloc = sr.node_alloc();
const bool propagate_alloc = allocator_traits_type::
propagate_on_container_move_assignment::value;
const bool allocators_equal = this_alloc == x_alloc; (void)allocators_equal;
@@ -437,14 +383,14 @@ class slist
//Destroy
this->clear();
//Move allocator if needed
this->AllocHolder::move_assign_alloc(x);
this->AllocHolder::move_assign_alloc(sr);
//Obtain resources
this->icont() = boost::move(x.icont());
this->icont() = boost::move(sr.icont());
}
//Else do a one by one move
else{
this->assign( boost::make_move_iterator(x.begin())
, boost::make_move_iterator(x.end()));
this->assign( boost::make_move_iterator(sr.begin())
, boost::make_move_iterator(sr.end()));
}
}
return *this;
@@ -1067,7 +1013,7 @@ class slist
//! <b>Note</b>: Iterators of values obtained from list x now point to elements of
//! this list. Iterators of this list and all the references are not invalidated.
void splice_after(const_iterator prev_p, BOOST_RV_REF(slist) x) BOOST_NOEXCEPT_OR_NOTHROW
{ this->splice_after(prev_p, static_cast<slist&>(x)); }
{ this->splice_after(prev_p, BOOST_MOVE_TO_LV(x)); }
//! <b>Requires</b>: prev_p must be a valid iterator of this.
//! i must point to an element contained in list x.
@@ -1104,7 +1050,7 @@ class slist
//! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
//! list. Iterators of this list and all the references are not invalidated.
void splice_after(const_iterator prev_p, BOOST_RV_REF(slist) x, const_iterator prev) BOOST_NOEXCEPT_OR_NOTHROW
{ this->splice_after(prev_p, static_cast<slist&>(x), prev); }
{ this->splice_after(prev_p, BOOST_MOVE_TO_LV(x), prev); }
//! <b>Requires</b>: prev_p must be a valid iterator of this.
//! before_first and before_last must be valid iterators of x.
@@ -1144,7 +1090,7 @@ class slist
//! list. Iterators of this list and all the references are not invalidated.
void splice_after(const_iterator prev_p, BOOST_RV_REF(slist) x,
const_iterator before_first, const_iterator before_last) BOOST_NOEXCEPT_OR_NOTHROW
{ this->splice_after(prev_p, static_cast<slist&>(x), before_first, before_last); }
{ this->splice_after(prev_p, BOOST_MOVE_TO_LV(x), before_first, before_last); }
//! <b>Requires</b>: prev_p must be a valid iterator of this.
//! before_first and before_last must be valid iterators of x.
@@ -1188,7 +1134,7 @@ class slist
void splice_after(const_iterator prev_p, BOOST_RV_REF(slist) x,
const_iterator before_first, const_iterator before_last,
size_type n) BOOST_NOEXCEPT_OR_NOTHROW
{ this->splice_after(prev_p, static_cast<slist&>(x), before_first, before_last, n); }
{ this->splice_after(prev_p, BOOST_MOVE_TO_LV(x), before_first, before_last, n); }
//! <b>Effects</b>: Removes all the elements that compare equal to value.
//!
@@ -1271,7 +1217,7 @@ class slist
//! <b>Complexity</b>: This function is linear time: it performs at most
//! size() + x.size() - 1 comparisons.
void merge(BOOST_RV_REF(slist) x)
{ this->merge(static_cast<slist&>(x)); }
{ this->merge(BOOST_MOVE_TO_LV(x)); }
//! <b>Requires</b>: p must be a comparison function that induces a strict weak
//! ordering and both *this and x must be sorted according to that ordering
@@ -1311,7 +1257,7 @@ class slist
//! <b>Note</b>: Iterators and references to *this are not invalidated.
template <class StrictWeakOrdering>
void merge(BOOST_RV_REF(slist) x, StrictWeakOrdering comp)
{ this->merge(static_cast<slist&>(x), comp); }
{ this->merge(BOOST_MOVE_TO_LV(x), comp); }
//! <b>Effects</b>: This function sorts the list *this according to std::less<value_type>.
//! The sort is stable, that is, the relative order of equivalent elements is preserved.
@@ -1515,7 +1461,7 @@ class slist
//! <b>Note</b>: Iterators of values obtained from list x now point to elements of
//! this list. Iterators of this list and all the references are not invalidated.
void splice(const_iterator p, BOOST_RV_REF(slist) x) BOOST_NOEXCEPT_OR_NOTHROW
{ this->splice(p, static_cast<slist&>(x)); }
{ this->splice(p, BOOST_MOVE_TO_LV(x)); }
//! <b>Requires</b>: p must point to an element contained
//! by this list. i must point to an element contained in list x.
@@ -1549,7 +1495,7 @@ class slist
//! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
//! list. Iterators of this list and all the references are not invalidated.
void splice(const_iterator p, BOOST_RV_REF(slist) x, const_iterator i) BOOST_NOEXCEPT_OR_NOTHROW
{ this->splice(p, static_cast<slist&>(x), i); }
{ this->splice(p, BOOST_MOVE_TO_LV(x), i); }
//! <b>Requires</b>: p must point to an element contained
//! by this list. first and last must point to elements contained in list x.
@@ -1583,7 +1529,7 @@ class slist
//! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
//! list. Iterators of this list and all the references are not invalidated.
void splice(const_iterator p, BOOST_RV_REF(slist) x, const_iterator first, const_iterator last) BOOST_NOEXCEPT_OR_NOTHROW
{ this->splice(p, static_cast<slist&>(x), first, last); }
{ this->splice(p, BOOST_MOVE_TO_LV(x), first, last); }
//! <b>Effects</b>: Returns true if x and y are equal
//!
@@ -1636,11 +1582,9 @@ class slist
#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
private:
void priv_push_front (const T &x)
{ this->insert_after(this->cbefore_begin(), x); }
void priv_push_front (BOOST_RV_REF(T) x)
{ this->insert_after(this->cbefore_begin(), ::boost::move(x)); }
template<class U>
void priv_push_front(BOOST_FWD_REF(U) x)
{ this->icont().push_front(*this->create_node(::boost::forward<U>(x))); }
bool priv_try_shrink(size_type new_size, const_iterator &last_pos)
{