Reputation: 11
For a c++ map declared like:
map < set<int>,int > x;
What is the default comparator function that the compiler uses?
My code using this statement executed successfully but I am not sure about the comparator it uses.
Upvotes: 1
Views: 241
Reputation: 2261
For both std::map
and std::set
there is a optional template parameter that defines the comparison type (and another one for the allocator.) using this you can use any comparison, including a user defined function!
In both these cases, it defaults to std::less
Look at the docs for each!!
http://www.cplusplus.com/reference/set/set/
http://www.cplusplus.com/reference/map/map/
Upvotes: 0
Reputation: 206577
For a std::map<K, T>
, the default comparator is std::less<K>
.
std::less<K>
uses lhs < rhs
as the default way to compare.
In your case, you end up using:
bool operator<(std::set<int> const& lhs, std::set<int> const& rhs)
Upvotes: 3