I use a map and I want to order the elements not by using the key but
by using the value. I know how to do it with the key but not with the value.
I joined my source code. You will see that I first tried successfully to order with the key (macro CORRECT). Can you complete, rearrange my code for the #else?
You can't sort a map because maps are inherently sorted. Sorting them by the value is even more impossible.
What you're looking for is an std::set, which only uses a value and no key, and is sorted by the value
By the way, I believe your comparison function will cause infinite recursion.
std::map<int,std::string> map; will produce the expected result.