fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <map>
  4. #include <unordered_map>
  5. #include <atomic>
  6. #include <algorithm>
  7. #include <iterator>
  8.  
  9. int main()
  10. {
  11. std::unordered_map<std::string, std::atomic<unsigned int>> m;
  12. for (auto p : std::initializer_list<std::pair<std::string, unsigned int>>{{ "a", 32},{ "b" , 22 },{ "c" , 32 },{ "d" , 22 },{ "e" , 55 } })
  13. m.emplace(p);
  14.  
  15. std::multimap<unsigned int, std::string> printmap;
  16.  
  17. std::transform(m.begin(), m.end(), std::inserter(printmap, printmap.end()),
  18. [](auto const &p) { return std::make_pair(p.second.load(), p.first); });
  19.  
  20. for (auto const &p : printmap)
  21. std::cout << p.first << " - " << p.second << std::endl;
  22.  
  23. return 0;
  24. }
Success #stdin #stdout 0s 4328KB
stdin
Standard input is empty
stdout
22 - d
22 - b
32 - a
32 - c
55 - e