std::forward_list<T,Allocator>::erase_after
來自 cppreference.com
< cpp | 容器 | forward_list
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 之間距離的線性複雜度。
[編輯] 示例
執行此程式碼
#include <forward_list> #include <iostream> #include <iterator> 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
[編輯] 參閱
清除內容 (public 成員函式) |