Rooh
asked on
Preventing sorting in std::map
Hi,
How can I prevent sorting in c++ std::map?
Thanks,
How can I prevent sorting in c++ std::map?
Thanks,
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
If you are putting your own class or struct in the map, you can overload the < operator to always return false. Or you can pass a comparator in the constructor that always returns false. This will make the map think all the elements are equal and it will not sort. Of course, if you prevent sorting, map lookups will be much less efficient. If you want efficiency without sorting, try some kind of hash table.
However, is std::unordered_map what you are after then?