Reputation: 3843
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 these types?
Don't quite understand this question! Thanks for answering.
Upvotes: 1
Views: 149
Reputation: 254451
Assuming the map is instantiated with the default comparator (i.e. as map<Key,Value>
with no third argument):
std::less<Key>
has been specialised (as long as the specialisation doesn't require operator<
).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.
Upvotes: 2