re-engineered random_access_index::splice(position,x,first,last)

the same way as done with sequenced_index
This commit is contained in:
joaquintides 2021-08-09 10:04:58 +02:00
parent 1bd4450884
commit cb6a581eda

View File

@ -541,7 +541,7 @@ public:
BOOST_MULTI_INDEX_CHECK_DIFFERENT_CONTAINER( BOOST_MULTI_INDEX_CHECK_DIFFERENT_CONTAINER(
this->final(*this),this->final(x)); this->final(*this),this->final(x));
BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT; BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT;
splice_impl(position,x,boost::is_copy_constructible<value_type>()); external_splice(position,x,boost::is_copy_constructible<value_type>());
} }
template<typename Index> template<typename Index>
@ -568,7 +568,8 @@ public:
if(pn!=in)relocate(pn,in); if(pn!=in)relocate(pn,in);
} }
else{ else{
splice_impl(position,x,i,boost::is_copy_constructible<value_type>()); external_splice(
position,x,i,boost::is_copy_constructible<value_type>());
} }
} }
@ -596,29 +597,25 @@ public:
BOOST_MULTI_INDEX_CHECK_IS_OWNER(last,x); BOOST_MULTI_INDEX_CHECK_IS_OWNER(last,x);
BOOST_MULTI_INDEX_CHECK_VALID_RANGE(first,last); BOOST_MULTI_INDEX_CHECK_VALID_RANGE(first,last);
BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT; BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT;
splice_impl( if(x.end().get_node()==this->header()){ /* same container */
position,x,first,last,boost::is_copy_constructible<value_type>()); BOOST_MULTI_INDEX_CHECK_OUTSIDE_RANGE(position,first,last);
} internal_splice(position,first,last);
}
void splice(
iterator position,random_access_index<SuperMeta,TagList>& x,
iterator first,iterator last)
{
BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(position);
BOOST_MULTI_INDEX_CHECK_IS_OWNER(position,*this);
BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(first);
BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(last);
BOOST_MULTI_INDEX_CHECK_IS_OWNER(first,x);
BOOST_MULTI_INDEX_CHECK_IS_OWNER(last,x);
BOOST_MULTI_INDEX_CHECK_VALID_RANGE(first,last);
BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT;
if(&x==this)relocate(position,first,last);
else{ else{
splice_impl( external_splice(
position,x,first,last,boost::is_copy_constructible<value_type>()); position,x,first,last,boost::is_copy_constructible<value_type>());
} }
} }
template<typename Index>
BOOST_MULTI_INDEX_ENABLE_IF_MERGEABLE(random_access_index,Index,void)
splice(
iterator position,BOOST_RV_REF(Index) x,
iterator first,iterator last)
{
splice(position,static_cast<Index&>(x),first,last);
}
void remove(value_param_type value) void remove(value_param_type value)
{ {
BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT; BOOST_MULTI_INDEX_RND_INDEX_CHECK_INVARIANT;
@ -1104,11 +1101,11 @@ private:
} }
template<typename Index> template<typename Index>
void splice_impl( void external_splice(
iterator position,Index& x,boost::true_type /* copy-constructible value */) iterator position,Index& x,boost::true_type /* copy-constructible value */)
{ {
if(get_allocator()==x.get_allocator()){ if(get_allocator()==x.get_allocator()){
splice_impl(position,x,boost::false_type()); external_splice(position,x,boost::false_type());
} }
else{ else{
/* backwards compatibility with old, non-transfer-based splice */ /* backwards compatibility with old, non-transfer-based splice */
@ -1131,7 +1128,7 @@ private:
} }
template<typename Index> template<typename Index>
void splice_impl( void external_splice(
iterator position,Index& x, iterator position,Index& x,
boost::false_type /* copy-constructible value */) boost::false_type /* copy-constructible value */)
{ {
@ -1148,12 +1145,12 @@ private:
} }
template<typename Index> template<typename Index>
void splice_impl( void external_splice(
iterator position,Index& x,BOOST_DEDUCED_TYPENAME Index::iterator i, iterator position,Index& x,BOOST_DEDUCED_TYPENAME Index::iterator i,
boost::true_type /* copy-constructible value */) boost::true_type /* copy-constructible value */)
{ {
if(get_allocator()==x.get_allocator()){ if(get_allocator()==x.get_allocator()){
splice_impl(position,x,i,boost::false_type()); external_splice(position,x,i,boost::false_type());
} }
else{ else{
/* backwards compatibility with old, non-transfer-based splice */ /* backwards compatibility with old, non-transfer-based splice */
@ -1176,7 +1173,7 @@ private:
} }
template<typename Index> template<typename Index>
void splice_impl( void external_splice(
iterator position,Index& x,BOOST_DEDUCED_TYPENAME Index::iterator i, iterator position,Index& x,BOOST_DEDUCED_TYPENAME Index::iterator i,
boost::false_type /* copy-constructible value */) boost::false_type /* copy-constructible value */)
{ {
@ -1188,15 +1185,32 @@ private:
} }
} }
template<typename Iterator>
void internal_splice(iterator position,Iterator first,Iterator last)
{
index_node_type* pn=position.get_node();
while(first!=last){
relocate(pn,static_cast<index_node_type*>((first++).get_node()));
}
}
void internal_splice(iterator position,iterator first,iterator last)
{
index_node_type* pn=position.get_node();
index_node_type* fn=static_cast<index_node_type*>(first.get_node());
index_node_type* ln=static_cast<index_node_type*>(last.get_node());
if(pn!=ln)relocate(pn,fn,ln);
}
template<typename Index> template<typename Index>
void splice_impl( void external_splice(
iterator position,Index& x, iterator position,Index& x,
BOOST_DEDUCED_TYPENAME Index::iterator first, BOOST_DEDUCED_TYPENAME Index::iterator first,
BOOST_DEDUCED_TYPENAME Index::iterator last, BOOST_DEDUCED_TYPENAME Index::iterator last,
boost::true_type /* copy-constructible value */) boost::true_type /* copy-constructible value */)
{ {
if(get_allocator()==x.get_allocator()){ if(get_allocator()==x.get_allocator()){
splice_impl(position,x,first,last,boost::false_type()); external_splice(position,x,first,last,boost::false_type());
} }
else{ else{
/* backwards compatibility with old, non-transfer-based splice */ /* backwards compatibility with old, non-transfer-based splice */
@ -1218,7 +1232,7 @@ private:
} }
template<typename Index> template<typename Index>
void splice_impl( void external_splice(
iterator position,Index& x, iterator position,Index& x,
BOOST_DEDUCED_TYPENAME Index::iterator first, BOOST_DEDUCED_TYPENAME Index::iterator first,
BOOST_DEDUCED_TYPENAME Index::iterator last, BOOST_DEDUCED_TYPENAME Index::iterator last,