Chromium Code Reviews| Index: base/containers/hash_tables.h |
| diff --git a/base/containers/hash_tables.h b/base/containers/hash_tables.h |
| index 6f37c49c3e476f7ccf9f0685d8ada16befa1b03d..5ddec0881f6a9e8d6a7dcb291f3ac9e7e137db10 100644 |
| --- a/base/containers/hash_tables.h |
| +++ b/base/containers/hash_tables.h |
| @@ -85,6 +85,18 @@ DEFINE_TRIVIAL_HASH(unsigned long long); |
| #undef DEFINE_TRIVIAL_HASH |
| #endif // !defined(OS_ANDROID) |
| +// To align with C++11's std::hash and MSVC's pre-standard stdext::hash_value, |
| +// provide a default hash function for raw pointers. Note: const char * is still |
| +// specialized to hash as a C string. This is consistent with the currently used |
| +// stdext::hash_value, but not C++11. |
| +template<typename T> |
| +struct hash<T*> { |
| + std::size_t operator()(T* value) const { |
| + BASE_HASH_NAMESPACE::hash<uintptr_t> h; |
|
viettrungluu
2014/10/08 17:19:44
You're already inside BASE_HASH_NAMESPACE.
davidben
2014/10/08 18:04:01
Done.
|
| + return h(reinterpret_cast<uintptr_t>(value)); |
|
viettrungluu
2014/10/08 17:19:45
So you should be able to do |return hash<uintptr_t
davidben
2014/10/08 18:04:01
Done, except the cast is still needed.
|
| + } |
| +}; |
| + |
| // Implement string hash functions so that strings of various flavors can |
| // be used as keys in STL maps and sets. The hash algorithm comes from the |
| // GNU C++ library, in <tr1/functional>. It is duplicated here because GCC |