std::experimental::erase (std::forward_list)
来自 cppreference.cn
< cpp | experimental
定义于头文件 <experimental/forward_list> |
||
template< class T, class A, class U > void erase( std::forward_list<T, A>& c, const U& value ); |
(库基础 TS v2) | |
从容器中移除所有与 value 相等的元素。 等价于 c.remove_if([&](auto& elem) { return elem == value; });。
目录 |
[编辑] 参数
c | - | 要从中擦除元素的容器 |
value | - | 要移除的值 |
[编辑] 复杂度
线性。
[编辑] 示例
运行此代码
#include <experimental/forward_list> #include <iostream> auto show = [](const auto& container) { for (auto e : container) std::cout << e; std::cout << '\n'; }; int main() { std::forward_list<int> data{1, 1, 1, 4, 1, 1, 1, 2, 1, 1, 1}; show(data); std::experimental::erase(data, 1); show(data); }
输出
11141112111 42
注释
与 std::forward_list::remove 不同,此函数模板接受异构类型,并且在调用 == 运算符之前不会强制转换为容器的值类型。
[编辑] 参见
移除满足特定标准的元素 (函数模板) | |
移除满足特定标准的元素 (std::forward_list<T,Allocator> 的公共成员函数) | |
(库基础 2 TS) |
从 std::forward_list 中擦除所有满足谓词的元素 (函数模板) |