#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
typedef std::pair<std::string, int> pair;
int main()
{
std::map<std::string, int> map = {
{"two", 2}, {"one", 1}, {"four", 4}, {"three", 3}
};
std::vector<pair> vec;
std::copy(map.begin(),
map.end(),
std::back_inserter<std::vector<pair>>(vec));
std::sort(vec.begin(), vec.end(),
[](const pair &l, const pair &r)
{
if (l.second != r.second) {
return l.second < r.second;
}
return l.first < r.first;
});
for (auto const &pair: vec) {
std::cout << '{' << pair.first << "," << pair.second << '}' << std::endl;
}
return 0;
}