Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

operator< overload for std::map's int type comparison? (I want it to sort in descending order..)

Tags:

c++

stl

I have encountered a problem that I want to define a map, that is sorted internally by the first's descending order. if the first is not a primary type, like if it's a class, I can just overload the "<" within that class, but I don't know how to deal with the int type. Any suggestion?

Thanks a lot!!

like image 477
Rachel Avatar asked Dec 17 '22 05:12

Rachel


1 Answers

Add a comparator:

#include <functional>
map<int, value_type, greater<int>> m;

The default is less<int>.

like image 103
Yakov Galka Avatar answered May 21 '23 14:05

Yakov Galka