You need to provide operator<
for Point
. std::map internally calls operator<
to sort key.
bool operator<(const Point& lhs, const Point& rhs)
{
// compares lhs.x to rhs.x,
// then lhs.y to rhs.y
return std::tie(lhs.x, lhs.y) < std::tie(rhs.x, rhs.y);
}
see map, it takes Compare
function from template parameter, std::less<key>
is default value.
std::map
is a sorted associative container that contains key-value pairs with unique keys. Keys are sorted by using the comparison function Compare. Search, removal, and insertion operations have logarithmic complexity. Maps are usually implemented as red-black trees