fork download
  1. #include <iostream>
  2. #include <map>
  3. using namespace std;
  4.  
  5. struct _tagTest{
  6. int x{0};
  7. int y{0};
  8.  
  9. struct comp{
  10. bool operator()(const _tagTest& _lhs, const _tagTest& _rhs) const
  11. {
  12. if (_lhs.x == _rhs.x && _lhs.y == _rhs.y)
  13. return false;
  14. else if (_lhs.x < _rhs.x || _lhs.y < _rhs.y)
  15. return true;
  16.  
  17. return false;
  18. }
  19. };
  20. };
  21.  
  22. int main() {
  23. std::map<_tagTest, int, _tagTest::comp> mapTest;
  24. ++mapTest[{1, 2}];
  25. ++mapTest[{1, 2}];
  26. ++mapTest[{1, 3}];
  27. ++mapTest[{1, 3}];
  28. ++mapTest[{1, 3}];
  29. ++mapTest[{2, 3}];
  30. ++mapTest[{2, 1}];
  31. std::map<_tagTest, int, _tagTest::comp>::iterator itMap = mapTest.begin();
  32. for (; itMap != mapTest.end(); ++itMap)
  33. {
  34. std::cout << itMap->first.x << " " << itMap->first.y << ":" << itMap->second << std::endl;
  35. }
  36. return 0;
  37. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
1 2:2
1 3:3
2 1:1
2 3:1