fork download
  1. #include <vector>
  2. #include <unordered_map>
  3. #include <iostream>
  4.  
  5. int main() {
  6. using Key = std::pair<int, void*>;
  7. auto hash = [](const Key & k) {
  8. return std::hash<int>()(k.first) * 31 + std::hash<void*>()(k.second);
  9. };
  10. std::unordered_map<Key, std::vector<int>, decltype(hash)> um(8, hash);
  11.  
  12. void *x, *y; x = &y; y = &x;
  13. um[{1, x}] = { 1, 2, 3 };
  14. um[{2, y}] = { 4, 5 };
  15.  
  16. for (auto const &mapItem : um)
  17. {
  18. std::cout << mapItem.first.first << ", " << mapItem.first.second << ":";
  19. for (auto const &vecItem : mapItem.second)
  20. std::cout << " " << vecItem;
  21. std::cout << std::endl;
  22. }
  23.  
  24. return 0;
  25. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
2, 0x7ffd14b1f660: 4 5
1, 0x7ffd14b1f668: 1 2 3