fork(1) download
  1. #include <iostream>
  2. #include <unordered_map>
  3. #include <utility>
  4.  
  5. struct Hasher
  6. {
  7. int operator()(const std::pair<int, int>& p) const
  8. {
  9. return p.first ^ (p.second << 7) ^ (p.second >> 3);
  10. }
  11. };
  12.  
  13. int main()
  14. {
  15. std::unordered_map<std::pair<int,int>, float, Hasher> m =
  16. { { {1,3}, 2.3 },
  17. { {2,3}, 4.234 },
  18. { {3,5}, -2 },
  19. };
  20.  
  21. // do a lookup
  22. std::cout << m[std::make_pair(2,3)] << '\n';
  23. // add more data
  24. m[std::make_pair(65,73)] = 1.23;
  25. // output everything
  26. for (auto& x : m)
  27. std::cout << x.first.first << ',' << x.first.second << ' '
  28. << x.second << '\n';
  29. }
Success #stdin #stdout 0s 3232KB
stdin
Standard input is empty
stdout
4.234
3,5 -2
1,3 2.3
65,73 1.23
2,3 4.234