hash_map is a non-standard extension. unordered_map is part of std::tr1, and will be moved into the std namespace for C++0x. http://en.wikipedia.org/wiki/Unordered_map_%28C%2B%2B%29
Wikipedia never lets down:
The name accepted into TR1 (and the draft for the next standard) is std::unordered_map
, so if you have that available, it's probably the one you want to use.
Other than that, using it is a lot like using std::map
, with the proviso that when/if you traverse the items in an std::map
, they come out in the order specified by operator<
, but for an unordered_map, the order is generally meaningless.
#include <tr1/unordered_map>
will get you next-standard C++ unique hash container. Usage:
std::tr1::unordered_map<std::string,int> my_map;
my_map["answer"] = 42;
printf( "The answer to life and everything is: %d\n", my_map["answer"] );
Source: Stackoverflow.com