advanced patterns when using std::map with custom struct as key in C++17
I've tried everything I can think of but After trying multiple solutions online, I still can't figure this out. I'm working with an scenario with `std::map` when using a custom struct as a key. I have defined a struct called `Point` which contains `int x` and `int y` coordinates. I implemented the comparison operator `<` to allow the map to order `Point` objects based on their coordinates. However, when I try to insert duplicate points, I notice that the map allows it instead of replacing the existing entry. Here's the relevant code: ```cpp #include <iostream> #include <map> struct Point { int x, y; bool operator<(const Point& other) const { return (x < other.x) || (x == other.x && y < other.y); } }; int main() { std::map<Point, std::string> pointMap; Point p1{1, 2}; Point p2{1, 2}; // Duplicate point pointMap[p1] = "First"; pointMap[p2] = "Second"; // Expected to replace but adds a new entry! for (const auto& [key, value] : pointMap) { std::cout << "Point: (" << key.x << ", " << key.y << ") - " << value << '\n'; } return 0; } ``` When I run this code, I'm expecting that the second insertion should replace the first entry or at least not create a new one, but instead, it results in two separate entries: ``` Point: (1, 2) - First Point: (1, 2) - Second ``` To troubleshoot this, I also tried checking the `operator<` implementation with various points, and it seems fine. I even added a debug print statement to verify the comparison logic is being called correctly, but it still behaves unexpectedly. Any insights into what I might be missing here, or if there's a configuration scenario with `std::map` in C++17? What am I doing wrong? My development environment is Linux. Any help would be greatly appreciated! My development environment is Windows 11. Has anyone else encountered this?