fork(2) download
  1. #include <string>
  2. #include <list>
  3. #include <iostream>
  4. struct A {
  5. std::string name;
  6. A(const std::string& name) : name(name) {}
  7. };
  8.  
  9. struct pA_comp {
  10. bool operator() (const A* left, const A* right) const {
  11. return left->name < right->name;
  12. }
  13. };
  14. int main()
  15. {
  16. std::list<A*> list = {new A("c"), new A("a"), new A("b")};
  17. list.sort(pA_comp());
  18.  
  19. for(auto i = list.begin(); i!=list.end(); ++i)
  20. {
  21. std::cout << (*i)->name << '\n';
  22. delete *i;
  23. }
  24. }
  25.  
Success #stdin #stdout 0s 2964KB
stdin
Standard input is empty
stdout
a
b
c