Source of ListingC8-3.cpp


  1: //  Created by Frank M. Carrano and Timothy M. Henry.
  2: //  Copyright (c) 2017 Pearson Education, Hoboken, New Jersey.

  4: // Listing C8-3.

  6: #include <iostream>
  7: #include <string>
  8: #include <unordered_map>

 10: // Create a type since this is a long name to use (optional)
 11: typedef std::unordered_map<std::string, int> StringKeyMap;

 13: // Create a dummyMap object so we can get its hash function
 14: StringKeyMap dummyMap;

 16: // Capture the hash function for use in program
 17: StringKeyMap::hasher myHashFunction = dummyMap.hash_function();

 19: int main()
 20: {
 21:    std::cout << "Hashing a String: " << myHashFunction("Hashing a String:")
 22:              << std::endl;
 23:    std::cout << "Smashing a String: " << myHashFunction ("Smashing a String:")
 24:              << std::endl;
 25:    return 0;
 26: }  // end main