fork(9) download
  1. #include <map>
  2. #include <iostream>
  3.  
  4. struct coord {
  5. int x, y;
  6. };
  7.  
  8. int main() {
  9. auto comp = [](const coord& c1, const coord& c2){
  10. return c1.x < c2.x || (c1.x == c2.x && c1.y < c2.y);
  11. };
  12. std::map<coord, int, decltype(comp)> m(comp);
  13.  
  14. m.insert({ { 0, 0 }, 123 });
  15. m.insert({ { 1, 1 }, 234 });
  16. m.insert({ { 0, 1 }, 345 });
  17. m.insert({ { 1, 0 }, 456 });
  18.  
  19. for (auto const &c : m)
  20. std::cout << c.first.x << ", " << c.first.y << ", " << c.second << std::endl;
  21.  
  22. return 0;
  23. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
0, 0, 123
0, 1, 345
1, 0, 456
1, 1, 234