Try using
std::unordered_map
from the header
<unordered_map>
Edit: I realize my answer did not fully answer your question.
This does what you want, although it is not a very efficient solution.
//Create new map
std::unordered_map<int, int> map;
map[1] = 2;
map[2] = 3;
map[3] = 1;
//Create vector to sort map
std::vector<std::pair<int,int>> tmp;
for (auto p : map)
{
tmp.push_back(std::make_pair(p.second, p.first));
}
std::sort(tmp.begin(), tmp.end());
map.clear();
for (auto p : tmp)
{
map.insert(std::make_pair(p.second, p.first));
}
//Display new map values
for (auto a : map) std::cout << a.first << ':' << a.second << '\n';
Besides <unordered_map>
this solution requires the following headers:
<algorithm>
<vector>