std::list::splice
void splice( const_iterator pos, list& other ); | (1) | |
|---|---|---|
void splice( const_iterator pos, list&& other ); | (1) | (since C++11) |
void splice( const_iterator pos, list& other, const_iterator it ); | (2) | |
void splice( const_iterator pos, list&& other, const_iterator it ); | (2) | (since C++11) |
void splice( const_iterator pos, list& other, const_iterator first, const_iterator last); | (3) | |
void splice( const_iterator pos, list&& other, const_iterator first, const_iterator last ); | (3) | (since C++11) |
将元素从一个列表转移到另一个列表。
没有复制或移动元素,只重新指向列表节点的内部指针。如果:get_allocator() != other.get_allocator()没有迭代器或引用失效,对移动元素的迭代器仍然有效,但现在引用到*this,而不是进入other...
1%29从other进*this.将元素插入到pos.集装箱other手术后变为空。如果this == &other...
2%29传输由it从other进*this。元素插入到pos...
3%29转移范围内的元素[first, last)从other进*this.将元素插入到pos如果pos是范围内的迭代器。[first,last)...
参数
pos | - | element before which the content will be inserted |
|---|---|---|
other | - | another container to transfer the content from |
it | - | the element to transfer from other to *this |
first, last | - | the range of elements to transfer from other to *this |
返回值
%280%29
复杂性
1-2%29常数。
3%29常数this == &other,否则线性在std::distance(first, last)...
例
二次
#include <iostream>
#include <list>
std::ostream& operator<<(std::ostream& ostr, const std::list<int>& list)
{
for (auto &i : list) {
ostr << " " << i;
}
return ostr;
}
int main ()
{
std::list<int> list1 = { 1, 2, 3, 4, 5 };
std::list<int> list2 = { 10, 20, 30, 40, 50 };
auto it = list1.begin();
std::advance(it, 2);
list1.splice(it, list2);
std::cout << "list1: " << list1 << "\n";
std::cout << "list2: " << list2 << "\n";
list2.splice(list2.begin(), list1, it, list1.end());
std::cout << "list1: " << list1 << "\n";
std::cout << "list2: " << list2 << "\n";
}二次
产出:
二次
list1: 1 2 10 20 30 40 50 3 4 5
list2:
list1: 1 2 10 20 30 40 50
list2: 3 4 5二次
另见
merge | merges two sorted lists (public member function) |
|---|---|
removeremove_if | removes elements satisfying specific criteria (public member function) |
© cppreference.com在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com

