#include <string>
#include <iostream>
#include <vector>
#include <atomic>
#include <algorithm>
#include <unordered_map>
using namespace std;
int main() {
std::unordered_map<std::string, std::atomic<unsigned int>> m;
m["quick"] = 0;
m["brown"] = 1;
m["fox"] = 2;
m["jumps"] = 3;
m["over"] = 4;
m["the"] = 5;
m["lazy"] = 6;
m["dog"] = 7;
std::vector<pair<unsigned int,std::string>> copy;
std::transform(
m.begin()
, m.end()
, back_inserter(copy)
, [](const pair<const std::string, std::atomic<unsigned int>>& p) {
return make_pair(p.second.load(), p.first);
});
for (auto it : copy)
std::cout << " " << it.first << ":" << it.second << std::endl;
std::cout << "==========" << std::endl;
std::sort(copy.begin(), copy.end());
for (auto it : copy)
std::cout << " " << it.first << ":" << it.second << std::endl;
return 0;
}
I2luY2x1ZGUgPHN0cmluZz4KI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8YXRvbWljPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8dW5vcmRlcmVkX21hcD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBtYWluKCkgewogICAgc3RkOjp1bm9yZGVyZWRfbWFwPHN0ZDo6c3RyaW5nLCBzdGQ6OmF0b21pYzx1bnNpZ25lZCBpbnQ+PiBtOwogICAgbVsicXVpY2siXSA9IDA7CiAgICBtWyJicm93biJdID0gMTsKICAgIG1bImZveCJdID0gMjsKICAgIG1bImp1bXBzIl0gPSAzOwogICAgbVsib3ZlciJdID0gNDsKICAgIG1bInRoZSJdID0gNTsKICAgIG1bImxhenkiXSA9IDY7CiAgICBtWyJkb2ciXSA9IDc7CiAgICBzdGQ6OnZlY3RvcjxwYWlyPHVuc2lnbmVkIGludCxzdGQ6OnN0cmluZz4+IGNvcHk7CiAgICBzdGQ6OnRyYW5zZm9ybSgKICAgICAgICBtLmJlZ2luKCkKICAgICwgICBtLmVuZCgpCiAgICAsICAgYmFja19pbnNlcnRlcihjb3B5KQogICAg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