std::forward_list<T,Allocator>::splice_after
提供: cppreference.com
<tbody>
</tbody>
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() の場合、動作は未定義です。 どのイテレータも参照も無効化されませんが、移動後の要素を指すイテレータは other 内ではなく *this 内を参照するようになります。
1) すべての要素を
other から *this に移動させます。 要素は pos の指す要素の後に挿入されます。 操作後、コンテナ other は空になります。 other が *this と同じオブジェクトを参照する場合、動作は未定義です。2)
it の次のイテレータの指す要素を other から *this に移動させます。 要素は pos の指す要素の後に挿入されます。 pos==it の場合、または pos==++it の場合、効果はありません。3) 範囲
(first, last) の要素を other から *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() の3番目の形式における開区間 (first, last) の意味、 l1 の最初の要素が移動されないことをデモンストレーションします。
Run this code
#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());
// not equivalent to 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
関連項目
| ソートされた2つのリストをマージします (パブリックメンバ関数) | |
| 特定の基準を満たす要素を削除します (パブリックメンバ関数) |