-
Using std::map with a custom class key
-
When using std::map should I overload operator== for the key type?
是否需要重载 ==
结论: operator < is enough. Equality can be checked by testing a < b and b < a both returning false.
-
std::map does not care about literal unicity of the keys. It cares about keys equivalence.
-
The keys a and b are equivalent by definition when neither a < b nor b < a is true.
-
Note also that std::map does not directly use operator <. std::map does not know anything about operator <. Instead std::map use