diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2022-06-09 12:07:15 +0100 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2022-06-10 14:39:25 +0100 |
commit | b370ed0bf93ecf0ff51d29e7fc132c433b2aa1be (patch) | |
tree | e34dad399c36da51e8135fbe7f03773feb3c769b /libstdc++-v3/include/std | |
parent | 5940b4e59f8e198dbf7e8b733561ef72a9ba2cbc (diff) | |
download | gcc-b370ed0bf93ecf0ff51d29e7fc132c433b2aa1be.zip gcc-b370ed0bf93ecf0ff51d29e7fc132c433b2aa1be.tar.gz gcc-b370ed0bf93ecf0ff51d29e7fc132c433b2aa1be.tar.bz2 |
libstdc++: Make std::hash<basic_string<>> allocator-agnostic (LWG 3705)
This new library issue was recently moved to Tentatively Ready by an LWG
poll, so I'm making the change on trunk.
As noted in PR libstc++/105907 the std::hash specializations for PMR
strings were not treated as slow hashes by the unordered containers, so
this change preserves that. The new specializations for custom
allocators are also not treated as slow, for the same reason. For the
versioned namespace (i.e. unstable ABI) we don't have to worry about
that, so can enable hash code caching for all basic_string
specializations.
libstdc++-v3/ChangeLog:
* include/bits/basic_string.h (__hash_str_base): New class
template.
(hash<basic_string<C, char_traits<C>, A>>): Define partial
specialization for each of the standard character types.
(hash<string>, hash<wstring>, hash<u8string>, hash<u16string>)
(hash<u32string>): Remove explicit specializations.
* include/std/string (__hash_string_base): Remove class
template.
(hash<pmr::string>, hash<pmr::wstring>, hash<pmr::u8string>)
(hash<pmr::u16string>, hash<pmr::u32string>): Remove explicit
specializations.
* testsuite/21_strings/basic_string/hash/hash.cc: Test with
custom allocators.
* testsuite/21_strings/basic_string/hash/hash_char8_t.cc:
Likewise.
Diffstat (limited to 'libstdc++-v3/include/std')
-rw-r--r-- | libstdc++-v3/include/std/string | 33 |
1 files changed, 0 insertions, 33 deletions
diff --git a/libstdc++-v3/include/std/string b/libstdc++-v3/include/std/string index 4a06330..37a4aab 100644 --- a/libstdc++-v3/include/std/string +++ b/libstdc++-v3/include/std/string @@ -69,39 +69,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION using u32string = basic_string<char32_t>; using wstring = basic_string<wchar_t>; } // namespace pmr - - template<typename _Str> - struct __hash_string_base - : public __hash_base<size_t, _Str> - { - size_t - operator()(const _Str& __s) const noexcept - { return hash<basic_string_view<typename _Str::value_type>>{}(__s); } - }; - - template<> - struct hash<pmr::string> - : public __hash_string_base<pmr::string> - { }; -#ifdef _GLIBCXX_USE_CHAR8_T - template<> - struct hash<pmr::u8string> - : public __hash_string_base<pmr::u8string> - { }; -#endif - template<> - struct hash<pmr::u16string> - : public __hash_string_base<pmr::u16string> - { }; - template<> - struct hash<pmr::u32string> - : public __hash_string_base<pmr::u32string> - { }; - template<> - struct hash<pmr::wstring> - : public __hash_string_base<pmr::wstring> - { }; - _GLIBCXX_END_NAMESPACE_VERSION } // namespace std #endif // C++17 |