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 );  | 
(2) | (C++11 起) | 
|   void splice_after( const_iterator pos, forward_list& other, const_iterator it );  | 
(3) | (C++11 起) | 
|   void splice_after( const_iterator pos, forward_list&& other, const_iterator it );  | 
(4) | (C++11 起) | 
|   void splice_after( const_iterator pos, forward_list& other, const_iterator first, const_iterator last );  | 
(5) | (C++11 起) | 
|   void splice_after( const_iterator pos, forward_list&& other, const_iterator first, const_iterator last );  | 
(6) | (C++11 起) | 
从另一 forward_list 移动元素到 *this。元素会被插入到 pos 指向的元素后。
不复制元素。没有迭代器或引用会失效。指向被移动的元素的迭代器现在指代到 *this 中,而不是到 other 中。
1,2) 从 other 移动所有元素到 *this。操作后 other 变为空。
3,4) 从 other 移动后随 it 的迭代器所指向的元素到 *this。元素被插入到 pos 指向的元素后,在 pos == it 或 pos == ++it 时没有效果。
5,6) 从 other 移动范围 
(first, last) 中的元素到 *this。不会移动 first 指向的元素。在以下情况下行为未定义:
- get_allocator() != other.get_allocator()。
 - 对于重载 (1,2),*this 和 other 指代同一对象。
 - 对于重载 (3,4),后随 it 的迭代器不是到 other 中的可解引用迭代器。
 - 对于重载 (5,6):
 
参数
| pos | - | 指向将插入内容到其后的元素的迭代器 | 
| other | - | 移动内容来源的另一容器 | 
| it | - | 指向从 other 移动到 *this 的元素的迭代器的前趋迭代器 | 
| first, last | - | 从 other 移动到 *this 的元素范围 | 
返回值
(无)
异常
不抛出。
复杂度
1,2) 与 other 的大小成线性。
3,4) 常数。
5,6) 与 std::distance(first, last) 成线性。
示例
运行此代码
#include <cassert> #include <forward_list> int main() { using F = std::forward_list<int>; // 演示重载 (5) 中开区间 (first, last) 的意义:不会移动 l1 的首个元素。 F l1 = {1, 2, 3, 4, 5}; F l2 = {10, 11, 12}; l2.splice_after(l2.cbegin(), l1, l1.cbegin(), l1.cend()); // 不与 l2.splice_after(l2.cbegin(), l1); 等价,它与以下语句等价: // l2.splice_after(l2.cbegin(), l1, l1.cbefore_begin(), l1.end()); assert((l1 == F{1})); assert((l2 == F{10, 2, 3, 4, 5, 11, 12})); // 重载 (1) F x = {1, 2, 3, 4, 5}; F y = {10, 11, 12}; x.splice_after(x.cbegin(), y); assert((x == F{1, 10, 11, 12, 2, 3, 4, 5})); assert((y == F{})); // 重载 (3) x = {1, 2, 3, 4, 5}; y = {10, 11, 12}; x.splice_after(x.cbegin(), y, y.cbegin()); assert((x == F{1, 11, 2, 3, 4, 5})); assert((y == F{10, 12})); // 重载 (5) x = {1, 2, 3, 4, 5}; y = {10, 11, 12}; x.splice_after(x.cbegin(), y, y.cbegin(), y.cend()); assert((x == F{1, 11, 12, 2, 3, 4, 5})); assert((y == F{10})); }
缺陷报告
下列更改行为的缺陷报告追溯地应用于以前出版的 C++ 标准。
| 缺陷报告 | 应用于 | 出版时的行为 | 正确行为 | 
|---|---|---|---|
| LWG 2045 | C++11 |  在 get_allocator() != other.get_allocator() 的情况下无法保证在 O(1) 时间内完成转移  | 
此时行为未定义 | 
参阅
|    (C++11)  | 
  合并两个有序 list (公开成员函数)  | 
|    (C++11)  | 
  移除满足特定标准的元素  (公开成员函数)  | 
|    (C++11)  | 
   返回指向第一个元素之前迭代器   (公开成员函数)  |