#include <algorithm>
#include <iostream>
#include <list>
struct P
{
bool operator()(const int &n) const
{
return n % 3 == 0;
}
};
int main()
{
std::list<int> l({ 5, 2, 6, 1, 13, 9, 19 });
std::cout << l.size();
std::remove_if(l.begin(), l.end(), P());
std::cout << l.size() << std::endl;
return 0;
}
答案 : 77
1. STL Algorithm 不会修改container的大小,只会返回iterator表示one element past the last one
2. 要实现真正删除, 必须交给container自己处理,
l.erase(l.begin(), remove_if(l.begin(), l.end(), P()));