Namespaces
Variants

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

From cppreference.net

ヘッダーで定義 <experimental/list>
template < class T, class A, class U >
void erase ( std:: list < T, A > & c, const U & value ) ;
(ライブラリ基盤仕様 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 から削除する
(関数テンプレート)