#ifndef SPOT_MISC_HASH_HH # define SPOT_MISC_HASH_HH # include // See the G++ FAQ for details about the following. # ifdef __GNUC__ # if __GNUC__ < 3 # include # include namespace Sgi { // inherit globals using ::hash_map; using ::hash_set; using ::hash; }; # else # include # include # if __GNUC_MINOR__ == 0 namespace Sgi = std; // GCC 3.0 # else namespace Sgi = ::__gnu_cxx; // GCC 3.1 and later # endif # endif # else // ... there are other compilers, right? # include # include namespace Sgi = std; # endif namespace spot { /// A hash function for pointers. template struct ptr_hash { size_t operator()(const T* p) const { return reinterpret_cast(p) - static_cast(0); } }; /// A hash function for strings. struct string_hash : Sgi::hash { size_t operator()(const std::string& s) const { // We are living dangerously. Be sure to call operator() // from the super-class, not this one. return Sgi::hash::operator()(s.c_str()); } }; } #endif // SPOT_MISC_HASH_HH