std::list::splice
来自cppreference.com
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
void splice(const_iterator pos, list& other); |
(1) | |
void splice(const_iterator pos, list&& other); |
(1) | (C++11 起) |
void splice(const_iterator pos, list& other, const_iterator it); |
(2) | |
void splice(const_iterator pos, list&& other, const_iterator it); |
(2) | (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) | (C++11 起) |
移动元素从一个列表到另一个.
原文:
Moves elements from one list to another.
没有这样的元素复制。的行为是不确定的,如果get_allocator() != other.get_allocator()。没有迭代器或引用变得无效,移动元素的迭代器是指到*this,不进
1) other
.原文:
No elements are copied. The behavior is undefined if: get_allocator() != other.get_allocator(). No iterators or references become invalidated, the iterators to moved elements now refer into *this, not into
other
.将所有的元素
2) other
*this。前pos
所指向的元素,这些元素被插入。在手术后变成空容器other
。的行为是不确定的,如果this == &other.原文:
Moves all elements from
other
into *this. The elements are inserted before the element pointed to by pos
. The container other
becomes empty after the operation. The behavior is undefined if this == &other.移动元素所指向的
3) it
从other
到*this。前pos
所指向的元素,该元素被插入.原文:
Moves the element pointed to by
it
from other
into *this. The element is inserted before the element pointed to by pos
.[first, last)
从other
到*this移动的范围中的元素。前pos
所指向的元素,这些元素被插入。 pos
是不确定的,如果是一个迭代的范围内[first,last)
的行为.原文:
Moves the elements in the range
[first, last)
from other
into *this. The elements are inserted before the element pointed to by pos
. The behavior is undefined if pos
is an iterator in the range [first,last)
.目录 |
[编辑] 参数
pos | - | 元素之前的内容将被插入
原文: element before which the content will be inserted |
other | - | 另一个容器中的内容移动
原文: another container to move the content from |
it | - | 从
other *this的元素原文: the element to move from other to *this |
first, last | - | 从
other *this的元素范围原文: the range of elements to move from other to *this |
[编辑] 返回值
(无)
[编辑] 复杂性
1-2)恒定
3) 常量,如果this == &other,否则线性std::distance(first, last).
原文:
Constant if this == &other, otherwise linear in 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
[编辑] 另请参阅
合并两个已排序列表 (公共成员函数) | |
删除元素满足特定条件 原文: removes elements satisfying specific criteria (公共成员函数) |