fork download
  1. #include <unordered_map>
  2. #include <iostream>
  3.  
  4. int main() {
  5. using Vote = std::pair<std::string, std::string>;
  6. auto hash = [](const Vote& v){
  7. return std::hash<std::string>()(v.first) * 31 + std::hash<std::string>()(v.second);
  8. };
  9. using Unordered_map = std::unordered_map<Vote, int, decltype(hash)>;
  10. Unordered_map um(8, hash);
  11.  
  12. um.insert({ { "John", "Miller" }, 1 });
  13. um.insert({ { "Jill", "Samson" }, 2 });
  14. um.insert({ { "Jane", "Decker" }, 3 });
  15.  
  16. for (auto const &v : um)
  17. std::cout << v.first.first.c_str() << " " << v.first.second.c_str() << ", " << v.second << std::endl;
  18.  
  19. return 0;
  20. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
Jane Decker, 3
Jill Samson, 2
John Miller, 1