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

Unified Diff: base/strings/string16.h

Issue 1502373009: Allow std::unordered_*. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase, more HashPair -> HashInts Created 4 years, 11 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 | « base/location.h ('k') | base/strings/string16_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/strings/string16.h
diff --git a/base/strings/string16.h b/base/strings/string16.h
index e47669c1b565e7cb79bfc275eb5965a9e506cbdf..af44a5c5bf17a1ee6fd48bed9c794771b189b326 100644
--- a/base/strings/string16.h
+++ b/base/strings/string16.h
@@ -29,6 +29,8 @@
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
+
+#include <functional>
#include <string>
#include "base/base_export.h"
@@ -182,6 +184,21 @@ BASE_EXPORT extern void PrintTo(const string16& str, std::ostream* out);
extern template
class BASE_EXPORT std::basic_string<base::char16, base::string16_char_traits>;
+// Specialize std::hash for base::string16. Although the style guide forbids
+// this in general, it is necessary for consistency with WCHAR_T_IS_UTF16
+// platforms, where base::string16 is a type alias for std::wstring.
+namespace std {
+template<>
+struct hash<base::string16> {
+ std::size_t operator()(const base::string16& s) const {
+ std::size_t result = 0;
+ for (base::char16 c : s)
+ result = (result * 131) + c;
+ return result;
+ }
+};
+} // namespace std
+
#endif // WCHAR_T_IS_UTF32
#endif // BASE_STRINGS_STRING16_H_
« no previous file with comments | « base/location.h ('k') | base/strings/string16_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698