fork download
  1. #include <iostream>
  2. #include <map>
  3. using namespace std;
  4.  
  5. struct myStruct {
  6. int a;
  7. int b;
  8. bool operator<(const myStruct& rhs) const {
  9. return rhs.a < this->a && rhs.b < this->b;
  10. }
  11. };
  12.  
  13.  
  14. int main() {
  15. std::map <myStruct, int> mymap ;
  16. myStruct m1={1,2};
  17. myStruct m2={2,1};
  18. mymap.insert(make_pair(m1,3));
  19. std::map<myStruct, int>::iterator it1 = mymap.find(m1);
  20. std::map<myStruct, int>::iterator it2 = mymap.find(m2);
  21. cout << it1->second << it2->second;
  22. // here it1->second=it2->second=3, although I would have expected it2 to be equal to map.end().
  23. }
Success #stdin #stdout 0.02s 2812KB
stdin
Standard input is empty
stdout
33