To unload information from std :: map to std :: vector, you can use the std :: vector constructor, which takes two iterators.
std::vector<std::pair<K,V> > myVec(myMap.begin(), myMap.end());
Then you sorted it with:
std::sort(myVec.begin(),myVec.end(),&myFunction);
myFunction will be a function defined with a signature:
bool myFunction(std::pair<K,V> first, std::pair<K,V> second);
Ask him to return true if you are in the correct order (that is, you must first be before the second). Return false when they are in the wrong order (that is, the second must be earlier).
Alternatively, you can look at boost :: bimap , which seems more customized to your problem.
source share