Namespaces
Variants

std::experimental::erase (std::list)

ja.cppreference.net から

 
 
 
 
ヘッダで定義 <experimental/list>
template< class T, class A, class U >
void erase( std::list<T, A>& c, const U& value );
(library fundamentals TS v2)

と比較して等しいすべての要素value をコンテナから消去します。次と同等: c.remove_if([&](auto& elem) { return elem == value; });.

パラメータ

c - 消去元のコンテナ
value - 削除する値

計算量

線形。

例

#include <experimental/list>
#include <iostream>
auto show = [](const auto& container)
{
    for (auto e : container)
        std::cout << e;
    std::cout << '\n';
};
int main()
{
    std::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::list::remove とは異なり、この関数テンプレートは異種型を受け入れ、コンテナの値型への変換を強制せずに == 演算子を呼び出します。

関連項目

特定の条件を満たす要素を削除する
(関数テンプレート & アルゴリズム関数オブジェクト)
特定の条件を満たす要素を削除する
(std::list<T,Allocator>の公開メンバ関数)
(library fundamentals 2 TS)
述語を満たすすべての要素を std::list
から削除する(関数テンプレート)