From 4df047dd3494ad17122ea46134a951a319a81b27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Dumont?= Date: Mon, 4 Feb 2013 21:14:07 +0000 Subject: [PATCH] functional_hash.h (std::__is_fast_hash<>): New. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2013-02-04 François Dumont * include/bits/functional_hash.h (std::__is_fast_hash<>): New. * include/bits/basic_string.h: Specialize previous to mark std::hash for string types as slow. * include/bits/hashtable.h (__cache_default): Replace is_integral with __is_fast_hash. * src/c++11/hash_c++0x.cc: Add type_traits include. * testsuite/23_containers/unordered_set/instantiation_neg.cc: Adapt dg-error line number. * testsuite/23_containers/unordered_set/ not_default_constructible_hash_neg.cc: Likewise. From-SVN: r195738 --- libstdc++-v3/ChangeLog | 13 +++++++++++++ libstdc++-v3/include/bits/basic_string.h | 16 ++++++++++++++++ libstdc++-v3/include/bits/functional_hash.h | 12 ++++++++++++ libstdc++-v3/include/bits/hashtable.h | 5 ++--- libstdc++-v3/src/c++11/hash_c++0x.cc | 1 + .../unordered_set/instantiation_neg.cc | 2 +- .../not_default_constructible_hash_neg.cc | 2 +- 7 files changed, 46 insertions(+), 5 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 2c1ffd21598..dc96107a1f9 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,16 @@ +2013-02-04 François Dumont + + * include/bits/functional_hash.h (std::__is_fast_hash<>): New. + * include/bits/basic_string.h: Specialize previous to mark + std::hash for string types as slow. + * include/bits/hashtable.h (__cache_default): Replace is_integral + with __is_fast_hash. + * src/c++11/hash_c++0x.cc: Add type_traits include. + * testsuite/23_containers/unordered_set/instantiation_neg.cc: + Adapt dg-error line number. + * testsuite/23_containers/unordered_set/ + not_default_constructible_hash_neg.cc: Likewise. + 2013-02-04 Manuel López-Ibáñez Paolo Carlini diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h index b5d2526c907..aa188f53a68 100644 --- a/libstdc++-v3/include/bits/basic_string.h +++ b/libstdc++-v3/include/bits/basic_string.h @@ -3051,6 +3051,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return std::_Hash_impl::hash(__s.data(), __s.length()); } }; + template<> + struct __is_fast_hash> : std::false_type + { }; + #ifdef _GLIBCXX_USE_WCHAR_T /// std::hash specialization for wstring. template<> @@ -3062,6 +3066,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return std::_Hash_impl::hash(__s.data(), __s.length() * sizeof(wchar_t)); } }; + + template<> + struct __is_fast_hash> : std::false_type + { }; #endif #endif /* _GLIBCXX_COMPATIBILITY_CXX0X */ @@ -3077,6 +3085,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __s.length() * sizeof(char16_t)); } }; + template<> + struct __is_fast_hash> : std::false_type + { }; + /// std::hash specialization for u32string. template<> struct hash @@ -3087,6 +3099,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return std::_Hash_impl::hash(__s.data(), __s.length() * sizeof(char32_t)); } }; + + template<> + struct __is_fast_hash> : std::false_type + { }; #endif _GLIBCXX_END_NAMESPACE_VERSION diff --git a/libstdc++-v3/include/bits/functional_hash.h b/libstdc++-v3/include/bits/functional_hash.h index 5a99c541495..bc29235cf14 100644 --- a/libstdc++-v3/include/bits/functional_hash.h +++ b/libstdc++-v3/include/bits/functional_hash.h @@ -194,6 +194,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // @} group hashes + // Hint about performance of hash functor. If not fast the hash based + // containers will cache the hash code. + // Default behavior is to consider that hasher are fast unless specified + // otherwise. + template + struct __is_fast_hash : public std::true_type + { }; + + template<> + struct __is_fast_hash> : public std::false_type + { }; + _GLIBCXX_END_NAMESPACE_VERSION } // namespace diff --git a/libstdc++-v3/include/bits/hashtable.h b/libstdc++-v3/include/bits/hashtable.h index d899fa728eb..6515b71eef9 100644 --- a/libstdc++-v3/include/bits/hashtable.h +++ b/libstdc++-v3/include/bits/hashtable.h @@ -40,9 +40,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template using __cache_default - = __not_<__and_, + = __not_<__and_, // Mandatory to make local_iterator default // constructible. is_default_constructible<_Hash>, diff --git a/libstdc++-v3/src/c++11/hash_c++0x.cc b/libstdc++-v3/src/c++11/hash_c++0x.cc index 29549ea2173..fc5295ad208 100644 --- a/libstdc++-v3/src/c++11/hash_c++0x.cc +++ b/libstdc++-v3/src/c++11/hash_c++0x.cc @@ -26,6 +26,7 @@ # error "hash_c++0x.cc must be compiled with -std=gnu++0x" #endif +#include #include namespace std _GLIBCXX_VISIBILITY(default) diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/instantiation_neg.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/instantiation_neg.cc index 6712d626231..827691f2ce0 100644 --- a/libstdc++-v3/testsuite/23_containers/unordered_set/instantiation_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/instantiation_neg.cc @@ -19,7 +19,7 @@ // with this library; see the file COPYING3. If not see // . -// { dg-error "with noexcept" "" { target *-*-* } 252 } +// { dg-error "with noexcept" "" { target *-*-* } 251 } #include diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/not_default_constructible_hash_neg.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/not_default_constructible_hash_neg.cc index 53a25bc65b8..bd62a0808c7 100644 --- a/libstdc++-v3/testsuite/23_containers/unordered_set/not_default_constructible_hash_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/not_default_constructible_hash_neg.cc @@ -19,7 +19,7 @@ // with this library; see the file COPYING3. If not see // . -// { dg-error "default constructible" "" { target *-*-* } 268 } +// { dg-error "default constructible" "" { target *-*-* } 267 } #include