fork download
  1. #include <iostream>
  2. #include <list>
  3. #include <iterator>
  4. #include <algorithm>
  5. using namespace std;
  6.  
  7. struct X {
  8. int ID;
  9. };
  10.  
  11. int main() {
  12. list<X> list;
  13. X t;
  14. t.ID=1;
  15. list.push_back(t);
  16. t.ID=2;
  17. list.push_back(t);
  18. t.ID=3;
  19. list.push_back(t);
  20. t.ID=4;
  21. list.push_back(t);
  22. cout << "before:" << endl;
  23. for (auto v : list) {
  24. cout << v.ID << endl;
  25. }
  26. list.erase(
  27. remove_if(
  28. list.begin()
  29. , list.end()
  30. , [](X x){ return x.ID == 3; }
  31. )
  32. , list.end()
  33. );
  34. cout << "after:" << endl;
  35. for (auto v : list) {
  36. cout << v.ID << endl;
  37. }
  38. return 0;
  39. }
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
before:
1
2
3
4
after:
1
2
4