diff options
| author | davidben <davidben@chromium.org> | 2016-01-20 17:08:38 -0800 |
|---|---|---|
| committer | Commit bot <commit-bot@chromium.org> | 2016-01-21 01:10:07 +0000 |
| commit | 3f37f7f1459e7b5a452c0e433493e0a6e9649ca7 (patch) | |
| tree | d37f361db93e0f91fe3dedee38851941f5586020 /base/strings/string16.h | |
| parent | 26a2b4883c04424a86abcda3d7333505eb1d032d (diff) | |
| download | chromium_src-3f37f7f1459e7b5a452c0e433493e0a6e9649ca7.zip chromium_src-3f37f7f1459e7b5a452c0e433493e0a6e9649ca7.tar.gz chromium_src-3f37f7f1459e7b5a452c0e433493e0a6e9649ca7.tar.bz2 | |
Allow std::unordered_*.
base::hash_* is, as a transition step, implemented in terms of
std::unordered_*. Later commits will convert existing uses.
Also fix a host of IWYU problems that arose from this CL.
(NOPRESUBMIT because the wstring presubmit check is overzealous
and complains about the reference to wstring in the comment.)
NOPRESUBMIT=true
BUG=576864
TBR=derat@chromium.org,blundell@chromium.org,jbauman@chromium.org,dalecurtis@chromium.org
CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel
Review URL: https://codereview.chromium.org/1502373009
Cr-Commit-Position: refs/heads/master@{#370553}
Diffstat (limited to 'base/strings/string16.h')
| -rw-r--r-- | base/strings/string16.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/base/strings/string16.h b/base/strings/string16.h index e47669c..af44a5c 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_ |
