mirror of
https://github.com/boostorg/multi_index.git
synced 2025-05-11 13:24:04 +00:00
made pointwise splice return a pair<iterator,bool>
This commit is contained in:
parent
6f88f65d99
commit
4d15bf41fa
@ -182,11 +182,9 @@ private:
|
|||||||
typedef typename call_traits<
|
typedef typename call_traits<
|
||||||
value_type>::param_type value_param_type;
|
value_type>::param_type value_param_type;
|
||||||
|
|
||||||
/* Needed to avoid commas in BOOST_MULTI_INDEX_OVERLOADS_TO_VARTEMPL
|
/* needed to avoid commas in some macros */
|
||||||
* expansion.
|
|
||||||
*/
|
|
||||||
|
|
||||||
typedef std::pair<iterator,bool> emplace_return_type;
|
typedef std::pair<iterator,bool> insertion_return_type;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -332,7 +330,7 @@ public:
|
|||||||
/* modifiers */
|
/* modifiers */
|
||||||
|
|
||||||
BOOST_MULTI_INDEX_OVERLOADS_TO_VARTEMPL(
|
BOOST_MULTI_INDEX_OVERLOADS_TO_VARTEMPL(
|
||||||
emplace_return_type,emplace_front,emplace_front_impl)
|
insertion_return_type,emplace_front,emplace_front_impl)
|
||||||
|
|
||||||
std::pair<iterator,bool> push_front(const value_type& x)
|
std::pair<iterator,bool> push_front(const value_type& x)
|
||||||
{return insert(begin(),x);}
|
{return insert(begin(),x);}
|
||||||
@ -341,7 +339,7 @@ public:
|
|||||||
void pop_front(){erase(begin());}
|
void pop_front(){erase(begin());}
|
||||||
|
|
||||||
BOOST_MULTI_INDEX_OVERLOADS_TO_VARTEMPL(
|
BOOST_MULTI_INDEX_OVERLOADS_TO_VARTEMPL(
|
||||||
emplace_return_type,emplace_back,emplace_back_impl)
|
insertion_return_type,emplace_back,emplace_back_impl)
|
||||||
|
|
||||||
std::pair<iterator,bool> push_back(const value_type& x)
|
std::pair<iterator,bool> push_back(const value_type& x)
|
||||||
{return insert(end(),x);}
|
{return insert(end(),x);}
|
||||||
@ -350,7 +348,7 @@ public:
|
|||||||
void pop_back(){erase(--end());}
|
void pop_back(){erase(--end());}
|
||||||
|
|
||||||
BOOST_MULTI_INDEX_OVERLOADS_TO_VARTEMPL_EXTRA_ARG(
|
BOOST_MULTI_INDEX_OVERLOADS_TO_VARTEMPL_EXTRA_ARG(
|
||||||
emplace_return_type,emplace,emplace_impl,iterator,position)
|
insertion_return_type,emplace,emplace_impl,iterator,position)
|
||||||
|
|
||||||
std::pair<iterator,bool> insert(iterator position,const value_type& x)
|
std::pair<iterator,bool> insert(iterator position,const value_type& x)
|
||||||
{
|
{
|
||||||
@ -558,7 +556,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename Index>
|
template<typename Index>
|
||||||
BOOST_MULTI_INDEX_ENABLE_IF_MERGEABLE(random_access_index,Index,void)
|
BOOST_MULTI_INDEX_ENABLE_IF_MERGEABLE(
|
||||||
|
random_access_index,Index,insertion_return_type)
|
||||||
splice(
|
splice(
|
||||||
iterator position,Index& x,BOOST_DEDUCED_TYPENAME Index::iterator i)
|
iterator position,Index& x,BOOST_DEDUCED_TYPENAME Index::iterator i)
|
||||||
{
|
{
|
||||||
@ -572,20 +571,24 @@ public:
|
|||||||
index_node_type* pn=position.get_node();
|
index_node_type* pn=position.get_node();
|
||||||
index_node_type* in=static_cast<index_node_type*>(i.get_node());
|
index_node_type* in=static_cast<index_node_type*>(i.get_node());
|
||||||
if(pn!=in)relocate(pn,in);
|
if(pn!=in)relocate(pn,in);
|
||||||
|
return std::pair<iterator,bool>(make_iterator(in),true);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
external_splice(
|
std::pair<final_node_type*,bool> p=
|
||||||
position,x,i,boost::is_copy_constructible<value_type>());
|
external_splice(
|
||||||
|
position,x,i,boost::is_copy_constructible<value_type>());
|
||||||
|
return std::pair<iterator,bool>(make_iterator(p.first),p.second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Index>
|
template<typename Index>
|
||||||
BOOST_MULTI_INDEX_ENABLE_IF_MERGEABLE(random_access_index,Index,void)
|
BOOST_MULTI_INDEX_ENABLE_IF_MERGEABLE(
|
||||||
|
random_access_index,Index,insertion_return_type)
|
||||||
splice(
|
splice(
|
||||||
iterator position,BOOST_RV_REF(Index) x,
|
iterator position,BOOST_RV_REF(Index) x,
|
||||||
BOOST_DEDUCED_TYPENAME Index::iterator i)
|
BOOST_DEDUCED_TYPENAME Index::iterator i)
|
||||||
{
|
{
|
||||||
splice(position,static_cast<Index&>(x),i);
|
return splice(position,static_cast<Index&>(x),i);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Index>
|
template<typename Index>
|
||||||
@ -1107,17 +1110,18 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename Index>
|
template<typename Index>
|
||||||
void external_splice(
|
std::pair<final_node_type*,bool> 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()){
|
||||||
external_splice(position,x,i,boost::false_type());
|
return 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 */
|
||||||
|
|
||||||
if(insert(position,*i).second){
|
std::pair<iterator,bool> p=insert(position,*i);
|
||||||
|
if(p.second){
|
||||||
|
|
||||||
#if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
|
#if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
|
||||||
/* MSVC++ 6.0 optimizer has a hard time with safe mode, and the
|
/* MSVC++ 6.0 optimizer has a hard time with safe mode, and the
|
||||||
@ -1131,11 +1135,13 @@ private:
|
|||||||
x.erase(i);
|
x.erase(i);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
return std::pair<final_node_type*,bool>(
|
||||||
|
static_cast<final_node_type*>(p.first.get_node()),p.second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Index>
|
template<typename Index>
|
||||||
void external_splice(
|
std::pair<final_node_type*,bool> 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 */)
|
||||||
{
|
{
|
||||||
@ -1145,6 +1151,7 @@ private:
|
|||||||
if(p.second&&position.get_node()!=header()){
|
if(p.second&&position.get_node()!=header()){
|
||||||
relocate(position.get_node(),p.first);
|
relocate(position.get_node(),p.first);
|
||||||
}
|
}
|
||||||
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Iterator>
|
template<typename Iterator>
|
||||||
|
@ -168,11 +168,9 @@ private:
|
|||||||
|
|
||||||
typedef typename call_traits<value_type>::param_type value_param_type;
|
typedef typename call_traits<value_type>::param_type value_param_type;
|
||||||
|
|
||||||
/* Needed to avoid commas in BOOST_MULTI_INDEX_OVERLOADS_TO_VARTEMPL
|
/* needed to avoid commas in some macros */
|
||||||
* expansion.
|
|
||||||
*/
|
|
||||||
|
|
||||||
typedef std::pair<iterator,bool> emplace_return_type;
|
typedef std::pair<iterator,bool> insertion_return_type;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -294,7 +292,7 @@ public:
|
|||||||
/* modifiers */
|
/* modifiers */
|
||||||
|
|
||||||
BOOST_MULTI_INDEX_OVERLOADS_TO_VARTEMPL(
|
BOOST_MULTI_INDEX_OVERLOADS_TO_VARTEMPL(
|
||||||
emplace_return_type,emplace_front,emplace_front_impl)
|
insertion_return_type,emplace_front,emplace_front_impl)
|
||||||
|
|
||||||
std::pair<iterator,bool> push_front(const value_type& x)
|
std::pair<iterator,bool> push_front(const value_type& x)
|
||||||
{return insert(begin(),x);}
|
{return insert(begin(),x);}
|
||||||
@ -303,7 +301,7 @@ public:
|
|||||||
void pop_front(){erase(begin());}
|
void pop_front(){erase(begin());}
|
||||||
|
|
||||||
BOOST_MULTI_INDEX_OVERLOADS_TO_VARTEMPL(
|
BOOST_MULTI_INDEX_OVERLOADS_TO_VARTEMPL(
|
||||||
emplace_return_type,emplace_back,emplace_back_impl)
|
insertion_return_type,emplace_back,emplace_back_impl)
|
||||||
|
|
||||||
std::pair<iterator,bool> push_back(const value_type& x)
|
std::pair<iterator,bool> push_back(const value_type& x)
|
||||||
{return insert(end(),x);}
|
{return insert(end(),x);}
|
||||||
@ -312,7 +310,7 @@ public:
|
|||||||
void pop_back(){erase(--end());}
|
void pop_back(){erase(--end());}
|
||||||
|
|
||||||
BOOST_MULTI_INDEX_OVERLOADS_TO_VARTEMPL_EXTRA_ARG(
|
BOOST_MULTI_INDEX_OVERLOADS_TO_VARTEMPL_EXTRA_ARG(
|
||||||
emplace_return_type,emplace,emplace_impl,iterator,position)
|
insertion_return_type,emplace,emplace_impl,iterator,position)
|
||||||
|
|
||||||
std::pair<iterator,bool> insert(iterator position,const value_type& x)
|
std::pair<iterator,bool> insert(iterator position,const value_type& x)
|
||||||
{
|
{
|
||||||
@ -509,7 +507,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename Index>
|
template<typename Index>
|
||||||
BOOST_MULTI_INDEX_ENABLE_IF_MERGEABLE(sequenced_index,Index,void)
|
BOOST_MULTI_INDEX_ENABLE_IF_MERGEABLE(
|
||||||
|
sequenced_index,Index,insertion_return_type)
|
||||||
splice(
|
splice(
|
||||||
iterator position,Index& x,BOOST_DEDUCED_TYPENAME Index::iterator i)
|
iterator position,Index& x,BOOST_DEDUCED_TYPENAME Index::iterator i)
|
||||||
{
|
{
|
||||||
@ -523,20 +522,24 @@ public:
|
|||||||
index_node_type* pn=position.get_node();
|
index_node_type* pn=position.get_node();
|
||||||
index_node_type* in=static_cast<index_node_type*>(i.get_node());
|
index_node_type* in=static_cast<index_node_type*>(i.get_node());
|
||||||
if(pn!=in)relink(pn,in);
|
if(pn!=in)relink(pn,in);
|
||||||
|
return std::pair<iterator,bool>(make_iterator(in),true);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
external_splice(
|
std::pair<final_node_type*,bool> p=
|
||||||
position,x,i,boost::is_copy_constructible<value_type>());
|
external_splice(
|
||||||
|
position,x,i,boost::is_copy_constructible<value_type>());
|
||||||
|
return std::pair<iterator,bool>(make_iterator(p.first),p.second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Index>
|
template<typename Index>
|
||||||
BOOST_MULTI_INDEX_ENABLE_IF_MERGEABLE(sequenced_index,Index,void)
|
BOOST_MULTI_INDEX_ENABLE_IF_MERGEABLE(
|
||||||
|
sequenced_index,Index,insertion_return_type)
|
||||||
splice(
|
splice(
|
||||||
iterator position,BOOST_RV_REF(Index) x,
|
iterator position,BOOST_RV_REF(Index) x,
|
||||||
BOOST_DEDUCED_TYPENAME Index::iterator i)
|
BOOST_DEDUCED_TYPENAME Index::iterator i)
|
||||||
{
|
{
|
||||||
splice(position,static_cast<Index&>(x),i);
|
return splice(position,static_cast<Index&>(x),i);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Index>
|
template<typename Index>
|
||||||
@ -1020,17 +1023,18 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename Index>
|
template<typename Index>
|
||||||
void external_splice(
|
std::pair<final_node_type*,bool> 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()){
|
||||||
external_splice(position,x,i,boost::false_type());
|
return 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 */
|
||||||
|
|
||||||
if(insert(position,*i).second){
|
std::pair<iterator,bool> p=insert(position,*i);
|
||||||
|
if(p.second){
|
||||||
|
|
||||||
#if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
|
#if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
|
||||||
/* MSVC++ 6.0 optimizer has a hard time with safe mode, and the
|
/* MSVC++ 6.0 optimizer has a hard time with safe mode, and the
|
||||||
@ -1044,11 +1048,13 @@ private:
|
|||||||
x.erase(i);
|
x.erase(i);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
return std::pair<final_node_type*,bool>(
|
||||||
|
static_cast<final_node_type*>(p.first.get_node()),p.second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Index>
|
template<typename Index>
|
||||||
void external_splice(
|
std::pair<final_node_type*,bool> 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 */)
|
||||||
{
|
{
|
||||||
@ -1058,6 +1064,7 @@ private:
|
|||||||
if(p.second&&position.get_node()!=header()){
|
if(p.second&&position.get_node()!=header()){
|
||||||
relink(position.get_node(),p.first);
|
relink(position.get_node(),p.first);
|
||||||
}
|
}
|
||||||
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Iterator>
|
template<typename Iterator>
|
||||||
|
@ -76,6 +76,7 @@ template<typename Sequence>
|
|||||||
static void test_list_ops_unique_seq()
|
static void test_list_ops_unique_seq()
|
||||||
{
|
{
|
||||||
typedef typename nth_index<Sequence,1>::type sequenced_index;
|
typedef typename nth_index<Sequence,1>::type sequenced_index;
|
||||||
|
typedef typename sequenced_index::iterator sequenced_index_iterator;
|
||||||
|
|
||||||
Sequence ss,ss2;
|
Sequence ss,ss2;
|
||||||
sequenced_index &si=get<1>(ss),&si2=get<1>(ss2);
|
sequenced_index &si=get<1>(ss),&si2=get<1>(ss2);
|
||||||
@ -109,10 +110,14 @@ static void test_list_ops_unique_seq()
|
|||||||
|
|
||||||
si.splice(project<1>(ss,ss.find(4)),si,project<1>(ss,ss.find(8)));
|
si.splice(project<1>(ss,ss.find(4)),si,project<1>(ss,ss.find(8)));
|
||||||
CHECK_EQUAL(si,(3)(5)(1)(8)(4)(0)(2)(6));
|
CHECK_EQUAL(si,(3)(5)(1)(8)(4)(0)(2)(6));
|
||||||
si2.clear();
|
|
||||||
si2.splice(si2.begin(),si,si.begin());
|
|
||||||
|
|
||||||
si.splice(si.end(),si2,si2.begin());
|
si2.clear();
|
||||||
|
std::pair<sequenced_index_iterator,bool> p=
|
||||||
|
si2.splice(si2.begin(),si,si.begin());
|
||||||
|
BOOST_TEST(*(p.first)==3&&p.second);
|
||||||
|
|
||||||
|
p=si.splice(si.end(),si2,si2.begin());
|
||||||
|
BOOST_TEST(*(p.first)==3&&p.second);
|
||||||
CHECK_EQUAL(si,(5)(1)(8)(4)(0)(2)(6)(3));
|
CHECK_EQUAL(si,(5)(1)(8)(4)(0)(2)(6)(3));
|
||||||
BOOST_TEST(si2.empty());
|
BOOST_TEST(si2.empty());
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user