名前空間
変種
操作

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

From cppreference.com
 
 
 
 
ヘッダ <experimental/forward_list> で定義
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> の public member function) [編集]
(ライブラリの基本機能 2 TS)
std::forward_list から述語を満たすすべての要素を削除します。
(関数テンプレート) [[編集]]
English 日本語 中文(简体) 中文(繁體)