Making string
the key for hash_map
If you are using gcc version 3.3.6 you'll need to wrap
operator()
in a class or struct:
class HashString
{
public:
unsigned operator()(std::string const &str) const
{
return __gnu_cxx::hash<char const*>()(str.c_str());
}
};
then declare the hash_map like so:
hash_map<string,string,HashString> _blahBlahMemberVariable ;
If you are using hashmap as an extension:
#include <ext/hash_map>
the following technique for defining __gnu_cxx is useful:
#define __gnu_cxx std
#include <ext/hash_map>
using namespace std;
link