std::forward_list<T,Allocator>::splice_after
来自cppreference.com
< cpp | container | forward list
| void splice_after( const_iterator pos, forward_list& other ); |
(1) | (C++11 起) |
| void splice_after( const_iterator pos, forward_list&& other ); |
(1) | (C++11 起) |
| void splice_after( const_iterator pos, forward_list& other, const_iterator it ); |
(2) | (C++11 起) |
| void splice_after( const_iterator pos, forward_list&& other, const_iterator it ); |
(2) | (C++11 起) |
| void splice_after( const_iterator pos, forward_list& other, const_iterator first, const_iterator last ); |
(3) | (C++11 起) |
| void splice_after( const_iterator pos, forward_list&& other, const_iterator first, const_iterator last ); |
(3) | (C++11 起) |
从另一 forward_list 移动元素到 *this 。
不复制元素。 pos 必须是指向 *this 中的可解引用迭代器或 before_begin() 迭代器(特别是 end() 不是 pos 的合法参数值)。若 get_allocator() != other.get_allocator() 则行为未定义。没有迭代器或引用被非法化,指向被移动的元素的迭代器现在指代到 *this 中,而非 other 中。
1) 从
other 移动所有元素到 *this 。元素被插入到 pos 所指向的元素后。操作后 other 变为空。若 other 与 *this 指代同一对象则行为未定义。2) 从
other 移动后随 it 的迭代器所指向的元素到 *this 。元素被插入到 pos 所指向的元素后,若 pos == it 或若 pos == ++it 则无效果。3) 从
other 移动范围 (first, last) 中的元素到 *this 。元素被插入到 pos 所指向的元素后。不移动 first 所指向的元素。若 pos 是范围 (first,last) 中的元素则行为未定义。参数
| pos | - | 指向将插入内容到其后的元素的迭代器 |
| other | - | 移动内容来源的另一容器 |
| it | - | 指向从 other 移动到 *this 的元素的迭代器的前趋迭代器
|
| first, last | - | 从 other 移动到 *this 的元素范围
|
返回值
(无)
异常
不抛出。
复杂度
1) 与
other 的大小成线性2) 常数
3) 与 std::distance(first, last) 成线性
示例
演示 splice_after() 第三种形式中开区间 (first, last) 的含义:不移动 l1 的首元素。
运行此代码
#include <iostream> #include <forward_list> int main() { std::forward_list<int> l1 = {1, 2, 3, 4, 5}; std::forward_list<int> l2 = {10, 11, 12}; l2.splice_after(l2.cbegin(), l1, l1.cbegin(), l1.cend()); // 不等价于 l2.splice_after(l2.cbegin(), l1); for (int n : l1) std::cout << n << ' '; std::cout << '\n'; for (int n : l2) std::cout << n << ' '; std::cout << '\n'; }
输出:
1 10 2 3 4 5 11 12
参阅
| 合并二个已排序列表 (公开成员函数) | |
| 移除满足特定标准的元素 (公开成员函数) |