fork download
  1. #include <unordered_map>
  2. #include <iostream>
  3. #include <iomanip>
  4.  
  5. int main()
  6. {
  7. std::unordered_map<int, std::pair<int, int>> m {
  8. { 1, { 2, 2 } },
  9. { -3, { 10, -9 } },
  10. { 8, { 4, 4 } },
  11. };
  12.  
  13. auto it = m.find(8);
  14.  
  15. if (it == m.end()) { it =m.emplace(8, std::make_pair(0, 0)).first; }
  16.  
  17. ++it->second.first;
  18.  
  19. for (auto const & p : m)
  20. std::cout << std::setw(2) << p.first << " => [" << std::setw(2)
  21. << p.second.first << " :: " << std::setw(2)
  22. << p.second.second << "]\n";
  23. }
  24.  
Success #stdin #stdout 0s 3036KB
stdin
Standard input is empty
stdout
 8 => [ 5 ::  4]
-3 => [10 :: -9]
 1 => [ 2 ::  2]