the type of map's key
Just saw a question on STL. The question is "<"does not need to be overloaded when the key of map belongs to certain types. What are thes开发者_JAVA百科e types?
Don't quite understand this question! Thanks for answering.
Assuming the map is instantiated with the default comparator (i.e. as map<Key,Value>
with no third argument):
- Built-in numeric types
- Pointers
- Any type for which
std::less<Key>
has been specialised (as long as the specialisation doesn't requireoperator<
). - Pedantically, any type which already has an overload of
operator<
.
For any other key type, the map will try to compare them using an expression like key1 < key2
, which will only compile if there is an overload of operator<
for the key type.
Basically, primitive types for which <
is already defined.
精彩评论