How can I search an std::map using a key of a different type
问题 If I have std::map<X, Blah> , what is the best way of looking up a matching item in the map using an instance of Y ? Assume the information in Y is enough to uniquely find an X , but for performance reasons I don't want to create an instance of X by copying Y values. I realize I can do this by creating a common base class or interface for X and Y and making that the map key, but is there any other way? e.g. creating some sort of comparator object? Here is the sample code for clarity: class X