mfgnik

Untitled

Jan 26th, 2021
614
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <unordered_map>
  3.  
  4. struct Point {
  5.     int x;
  6.     int y;
  7.  
  8.     bool operator==(const Point& other) {
  9.         return x == other.x && y == other.y;
  10.     }
  11.  
  12. };
  13.  
  14. namespace std {
  15.     template<>
  16.     struct hash<Point> {
  17.         inline size_t operator()(const Point& point) const {
  18.             return point.x * 1024 + point.y;
  19.         }
  20.     };
  21. }
  22.  
  23.  
  24. int main() {
  25.     std::unordered_map<Point, int> points_map;
  26.  
  27.     points_map.emplace(Point{1, 2}, 3);
  28.  
  29.     std::cout << points_map.size();
  30. }
RAW Paste Data