fork download
  1. #include <iostream>
  2. #include <list>
  3. #include <string>
  4.  
  5. struct A {
  6. std::string name_;
  7. A(const char* name) : name_(name) {}
  8. };
  9.  
  10. void dump(const std::list<A>& list) {
  11. for (auto&& a : list) {
  12. std::cout << a.name_ << ' ';
  13. }
  14. std::cout << '\n';
  15. }
  16.  
  17. int main() {
  18. std::list<A> myList { { "hello", "pizza", "world", "pizza" } };
  19. dump(myList);
  20. const std::string name = "pizza";
  21. myList.remove_if([&](const A& it){ return it.name_ == name; });
  22. dump(myList);
  23. return 0;
  24. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
hello pizza world pizza 
hello world