std::forward_list<T,Allocator>::erase_after
提供: cppreference.com
<tbody>
</tbody>
iterator erase_after( const_iterator pos ); |
(1) | (C++11以上) |
iterator erase_after( const_iterator first, const_iterator last ); |
(2) | (C++11以上) |
指定された要素をコンテナから削除します。
1)
pos の後の要素を削除します。2) 範囲
(first; last) の要素を削除します。引数
| pos | - | 削除する要素の前の要素を指すイテレータ |
| first, last | - | 削除する要素の範囲 |
戻り値
1) 削除された要素の後の要素を指すイテレータ、またはそのような要素が存在しない場合は end()。
2)
last。計算量
1) 一定。
2)
first と last の距離に比例。例
Run this code
#include <forward_list>
#include <iterator>
#include <iostream>
int main()
{
std::forward_list<int> l = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
// l.erase( l.begin() ); // ERROR: No function erase
l.erase_after( l.before_begin() ); // Removes first element
for( auto n : l ) std::cout << n << " ";
std::cout << '\n';
auto fi= std::next( l.begin() );
auto la= std::next( fi, 3 );
l.erase_after( fi, la );
for( auto n : l ) std::cout << n << " ";
std::cout << '\n';
}
出力:
2 3 4 5 6 7 8 9
2 3 6 7 8 9
関連項目
| すべての要素を削除します (パブリックメンバ関数) |