Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2936)

Unified Diff: base/containers/hash_tables.h

Issue 630503002: Align base::hash_map with C++11, part 1. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@hash-2
Patch Set: comments Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/debug/trace_event_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/containers/hash_tables.h
diff --git a/base/containers/hash_tables.h b/base/containers/hash_tables.h
index 6f37c49c3e476f7ccf9f0685d8ada16befa1b03d..c803ace5cfe2609135e686e5ccc9799d1e30c426 100644
--- a/base/containers/hash_tables.h
+++ b/base/containers/hash_tables.h
@@ -85,6 +85,17 @@ 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 {
+ return hash<uintptr_t>()(reinterpret_cast<uintptr_t>(value));
+ }
+};
+
// 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
« no previous file with comments | « no previous file | base/debug/trace_event_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698