fork download
  1. #include <iostream>
  2. #include <set>
  3. #include <map>
  4.  
  5. typedef std::set<int,bool(*)(int,int)> Set;
  6. typedef std::map<std::string, Set> Map;
  7.  
  8. bool f(int a, int b){ return a<b;}
  9. bool g(int a, int b){ return a>b;}
  10.  
  11. int main() {
  12. Map m;
  13. m["f"] = Set(&f);
  14. m["g"] = Set(&g);
  15. for(int i = -5; i < 5; ++i) {
  16. m["f"].insert(i);
  17. m["g"].insert(i);
  18. }
  19. for(Set::iterator i = m["f"].begin(); i != m["f"].end(); ++i){std::cout << *i << " ";}
  20. std::cout << "\n";
  21. for(Set::iterator i = m["g"].begin(); i != m["g"].end(); ++i){std::cout << *i << " ";}
  22. std::cout << "\n";
  23. return 0;
  24. }
Success #stdin #stdout 0s 3236KB
stdin
Standard input is empty
stdout
-5 -4 -3 -2 -1 0 1 2 3 4 
4 3 2 1 0 -1 -2 -3 -4 -5