What is the best way to use two keys with a std::map?

后端 未结 9 1833
你的背包
你的背包 2021-01-30 03:54

I have a std::map that I\'m using to store values for x and y coordinates. My data is very sparse, so I don\'t want to use arrays or vectors, which would result in

9条回答
  •  旧巷少年郎
    2021-01-30 04:45

    I usually solve this kind of problem like this:

    struct Point {
        int x;
        int y;
    };
    
    inline bool operator<(const Point& p1, const Point& p2) {
        if (p1.x != p2.x) {
            return p1.x < p2.x;
        } else {
            return p1.y < p2.y;
        }
    }
    

提交回复
热议问题