diff --git a/libcxx/docs/Status/Cxx2bIssues.csv b/libcxx/docs/Status/Cxx2bIssues.csv --- a/libcxx/docs/Status/Cxx2bIssues.csv +++ b/libcxx/docs/Status/Cxx2bIssues.csv @@ -173,7 +173,7 @@ "`3702 `__","Should ``zip_transform_view::iterator`` remove ``operator<``","July 2022","","" "`3703 `__","Missing requirements for ``expected`` requires ``is_void``","July 2022","","" "`3704 `__","LWG 2059 added overloads that might be ill-formed for sets","July 2022","","" -"`3705 `__","Hashability shouldn't depend on basic_string's allocator","July 2022","","" +"`3705 `__","Hashability shouldn't depend on basic_string's allocator","July 2022","|Complete|","16.0" "`3707 `__","chunk_view::outer-iterator::value_type::size should return unsigned type","July 2022","","","|ranges|" "`3708 `__","``take_while_view::sentinel``'s conversion constructor should move","July 2022","","","|ranges|" "`3709 `__","LWG-3703 was underly ambitious","July 2022","","" diff --git a/libcxx/include/string b/libcxx/include/string --- a/libcxx/include/string +++ b/libcxx/include/string @@ -4597,15 +4597,32 @@ basic_string<_CharT, _Traits, _Allocator>::npos; template -struct _LIBCPP_TEMPLATE_VIS - hash, _Allocator> > - : public __unary_function, _Allocator>, size_t> +struct __string_hash : public __unary_function, _Allocator>, size_t> { size_t operator()(const basic_string<_CharT, char_traits<_CharT>, _Allocator>& __val) const _NOEXCEPT { return __do_string_hash(__val.data(), __val.data() + __val.size()); } }; +template +struct hash, _Allocator> > : __string_hash {}; + +#ifndef _LIBCPP_HAS_NO_CHAR8_T +template +struct hash, _Allocator> > : __string_hash {}; +#endif + +template +struct hash, _Allocator> > : __string_hash {}; + +template +struct hash, _Allocator> > : __string_hash {}; + +#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +template +struct hash, _Allocator> > : __string_hash {}; +#endif + template _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, diff --git a/libcxx/include/string_view b/libcxx/include/string_view --- a/libcxx/include/string_view +++ b/libcxx/include/string_view @@ -962,8 +962,7 @@ // [string.view.hash] template -struct _LIBCPP_TEMPLATE_VIS hash > > - : public __unary_function >, size_t> +struct __string_view_hash : public __unary_function >, size_t> { _LIBCPP_INLINE_VISIBILITY size_t operator()(const basic_string_view<_CharT, char_traits<_CharT> > __val) const _NOEXCEPT { @@ -971,6 +970,25 @@ } }; +template <> +struct hash > > : __string_view_hash {}; + +#ifndef _LIBCPP_HAS_NO_CHAR8_T +template <> +struct hash > > : __string_view_hash {}; +#endif + +template <> +struct hash > > : __string_view_hash {}; + +template <> +struct hash > > : __string_view_hash {}; + +#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +template <> +struct hash > > : __string_view_hash {}; +#endif + #if _LIBCPP_STD_VER > 11 inline namespace literals { diff --git a/libcxx/test/std/strings/basic.string.hash/enabled_hashes.pass.cpp b/libcxx/test/std/strings/basic.string.hash/enabled_hashes.pass.cpp --- a/libcxx/test/std/strings/basic.string.hash/enabled_hashes.pass.cpp +++ b/libcxx/test/std/strings/basic.string.hash/enabled_hashes.pass.cpp @@ -15,10 +15,15 @@ #include +#include "constexpr_char_traits.h" #include "poisoned_hash_helper.h" - +#include "test_allocator.h" #include "test_macros.h" +struct MyChar { + char c; +}; + int main(int, char**) { test_library_hash_specializations_available(); { @@ -31,6 +36,9 @@ #endif test_hash_enabled_for_type(); test_hash_enabled_for_type(); + test_hash_enabled_for_type, test_allocator>>(); + test_hash_disabled_for_type, std::allocator>>(); + test_hash_disabled_for_type, std::allocator>>(); } return 0; diff --git a/libcxx/test/std/strings/string.view/string.view.hash/enabled_hashes.pass.cpp b/libcxx/test/std/strings/string.view/string.view.hash/enabled_hashes.pass.cpp --- a/libcxx/test/std/strings/string.view/string.view.hash/enabled_hashes.pass.cpp +++ b/libcxx/test/std/strings/string.view/string.view.hash/enabled_hashes.pass.cpp @@ -16,10 +16,14 @@ #include +#include "constexpr_char_traits.h" #include "poisoned_hash_helper.h" - #include "test_macros.h" +struct MyChar { + char c; +}; + int main(int, char**) { test_library_hash_specializations_available(); { @@ -32,6 +36,8 @@ #endif test_hash_enabled_for_type(); test_hash_enabled_for_type(); + test_hash_disabled_for_type>>(); + test_hash_disabled_for_type>>(); } return 0;