I want to use multiset to count some custom defined keys. The keys are not comparable numerically, comparing two keys does not mean anything, but their equality can be checked.
I see that multiset template wants a Compare to order the multiset. The order is not important to me, only the counts are important. If I omit Compare completely what happens? Does multiset work without any problems for my custom keys? If I cannot use std::multiset what are my alternatives?
You cannot use
std::multisetif you don’t have a strict weak ordering. Your options are:Impose a strict-weak ordering on your data. If your key is a “linear” data structure, it is usually a good idea to compare it lexicographically.
Use an unordered container equivalent, e.g.,
boost::unordered_multiset. For that, you will need to make your custom data-type hash-able, which is often-times easier than imposing some kind of order.