В старых версиях gcc вы также можете использовать hash_map, который может быть «достаточно хорошим».
#include <ext/hash_map> // Gnu gcc specific!
...
// allow the gnu hash_map to work on std::string
namespace __gnu_cxx {
template<> struct hash< std::string > {
size_t operator()(const std::string& s) const {
return hash< const char* >()( s.c_str() );
}
}; /* gcc.gnu.org/ml/libstdc++/2002-04/msg00107.html */
}
// this is what we would love to have:
typedef __gnu_cxx::hash_map<std::string, int> Hash;
....
и позже
Hash hash;
string this_string;
...
hash[ this_string ]++;
...
, который я использовал часто и с успехом.
Привет
БВУ