fork(1) download
  1. #include <functional>
  2. #include <iostream>
  3. #include <map>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9. map<int, string, greater<int>> foo;
  10. //map<int, string> foo(greater<int>()); Doesn't work
  11. map<int, string, function<bool(const int&, const int&)>> bar([](const int& lhs, const int& rhs){ return lhs > rhs; });
  12. //map<int, string> bar([](const int& lhs, const int& rhs){ return lhs > rhs; }); Doesn't work
  13.  
  14. foo[1] = "one"s;
  15. foo[2] = "two"s;
  16. bar[3] = "three"s;
  17. bar[4] = "four"s;
  18.  
  19. for(auto& i : foo) {
  20. cout << i.first << ':' << i.second << endl;
  21. }
  22.  
  23. for(auto& i : bar) {
  24. cout << i.first << ':' << i.second << endl;
  25. }
  26. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
2:two
1:one
4:four
3:three