Namespaces
Variants

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

ja.cppreference.net から

 
 
 
 
template< class T, class A, class U >
void erase( std::forward_list<T, A>& c, const U& value );
(library fundamentals 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
(関数テンプレート)