- forward_list[meta header]
- std[meta namespace]
- forward_list[meta class]
- function template[meta id-type]
- cpp11[meta cpp]
template <class Predicate>
void remove_if(Predicate pred); // (1) C++11
template <class Predicate>
size_type remove_if(Predicate pred); // (1) C++20
条件一致する全ての要素を削除する
コンテナの全ての要素に対する各イテレータi
において、pred(*i) == true
となる要素を削除する。
削除された要素に対するイテレータおよび参照は無効となる。
- C++11 : なし
- C++20 : 削除された要素数を返す
pred
呼び出しが例外を投げなければ、この関数は例外を投げない
ちょうどdistance(begin(), end())
回だけ述語を適用する
#include <iostream>
#include <forward_list>
int main()
{
std::forward_list<int> ls = {3, 1, 4, 1};
ls.remove_if([](int x) { return x == 1; }); // 値1の要素を全て削除
for (int x : ls) {
std::cout << x << std::endl;
}
}
- remove_if[color ff0000]
3
4
- C++11
- Clang: ??
- GCC: 4.7.0 [mark verified]
- ICC: ??
- Visual C++: 2010 [mark verified], 2012 [mark verified], 2013 [mark verified], 2015 [mark verified], 2017 [mark verified]