名稱空間
變體
操作

std::experimental::erase (std::forward_list)

來自 cppreference.com
< cpp‎ | 實驗性
定義於標頭檔案 <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> 的公共成員函式) [編輯]
std::forward_list 中擦除所有滿足謂詞的元素
(函式模板) [編輯]