Sorting a std::map without deleting and reinserting entries

63 Views Asked by At

I have a std::map where the key is a pointer to a class that has a priority() method and the value is just an int. The map has a compare function that compares keys by their priority(), which is an integer member variable of the key class.

At some point I want to change key priorities, e.g. key A was priority 1, key B was priority 5, after the change key A's priority is now 5 and key B's is 1. Just to emphasise that the objects the keys point to are not changing, jusr one of the object member variables is.

So I want the std::map to reflect this change. Is there a simple way of 'sorting' the map other than saving all the key/values, clearing the map, then inserting the saved values, and hence get a newly sorted map?

0

There are 0 best solutions below