This is my code:
map<string, int> errs;
struct Compare {
bool operator() (map<string, int>::const_iterator l,
map<string, int>::const_iterator r) {
return ((*l).second < (*r).second);
}
} comp;
sort(errs.begin(), errs.end(), comp);
Can’t compile. This is what I’m getting:
no matching function for call to ‘sort(..’
Why so? Can anyone help? Thanks!
Maps are, by definition, sorted by their keys, so you can’t resort a map by its values.
You can provide an alternate comparison function as the third template parameter to a map, if you want to sort the keys by a non-default order.
If you’re trying to sort a map by its values, then perhaps you could try using Boost.MultiIndex to make a bidirectional map instead?