aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/std/string
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2019-04-03 10:47:47 +0100
committerJonathan Wakely <redi@gcc.gnu.org>2019-04-03 10:47:47 +0100
commit0cb78ef4bcd216413199f9f27eed0ea0a56dd8da (patch)
treec4d7fd4a00fd3526c53a1055a9e91973a4a0fd1e /libstdc++-v3/include/std/string
parent3a3976b14e329421e51a2aa43e516a6871cb5e6b (diff)
downloadgcc-0cb78ef4bcd216413199f9f27eed0ea0a56dd8da.zip
gcc-0cb78ef4bcd216413199f9f27eed0ea0a56dd8da.tar.gz
gcc-0cb78ef4bcd216413199f9f27eed0ea0a56dd8da.tar.bz2
Define std::hash specializations for C++17 PMR strings
These hash specializations should have been added when the pmr::string and related typedefs were added. * include/std/string (__hash_string_base): New class template defining operator() for hashing strings. (hash<pmr::string>, hash<pmr::u8string>, hash<pmr::u16string>) (hash<pmr::u32string>, hash<pmr::wstring>): Define for C++17. * testsuite/21_strings/basic_string/hash/hash.cc: New test. * testsuite/21_strings/basic_string/hash/hash_char8_t.cc: New test. From-SVN: r270116
Diffstat (limited to 'libstdc++-v3/include/std/string')
-rw-r--r--libstdc++-v3/include/std/string35
1 files changed, 35 insertions, 0 deletions
diff --git a/libstdc++-v3/include/std/string b/libstdc++-v3/include/std/string
index 100c6c84..6ccc06f 100644
--- a/libstdc++-v3/include/std/string
+++ b/libstdc++-v3/include/std/string
@@ -74,6 +74,41 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
using wstring = basic_string<wchar_t>;
#endif
} // 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>
+ { };
+#ifdef _GLIBCXX_USE_WCHAR_T
+ template<>
+ struct hash<pmr::wstring>
+ : public __hash_string_base<pmr::wstring>
+ { };
+#endif
+
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace std
#endif // C++17