C++
容器 | Containers

std::forward_list::erase_after

STD:向前[医]名单::擦除[医]后

iterator erase_after( const_iterator pos (1)(since C++11)
iterator erase_after( const_iterator first, const_iterator last (2)(since C++11)

从容器中移除指定的元素。

1%29移除以下元素pos...

2%29移除范围内的元素。(first; last)...

参数

pos-iterator to the element preceding the element to remove
first, last-range of elements to remove

返回值

1%29 Iterator对被擦除元素后面的元素,或end()如果不存在这样的元素。

2%29last

复杂性

1%29常数。

2%29直线距离firstlast...

二次

#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

二次

另见

clearclears the contents (public member function)

© cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

http://en.cppreference.com/w/cpp/container/Forward[医]列表/擦除[医]后