OSDN Git Service

2013-02-04 François Dumont <fdumont@gcc.gnu.org>
authorfdumont <fdumont@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 4 Feb 2013 21:14:07 +0000 (21:14 +0000)
committerfdumont <fdumont@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 4 Feb 2013 21:14:07 +0000 (21:14 +0000)
* 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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@195738 138bc75d-0d04-0410-961f-82ee72b054a4

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/basic_string.h
libstdc++-v3/include/bits/functional_hash.h
libstdc++-v3/include/bits/hashtable.h
libstdc++-v3/src/c++11/hash_c++0x.cc
libstdc++-v3/testsuite/23_containers/unordered_set/instantiation_neg.cc
libstdc++-v3/testsuite/23_containers/unordered_set/not_default_constructible_hash_neg.cc

index 2c1ffd2..dc96107 100644 (file)
@@ -1,3 +1,16 @@
+2013-02-04  François Dumont  <fdumont@gcc.gnu.org>
+
+       * 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  <manu@gcc.gnu.org>
            Paolo Carlini  <paolo.carlini@oracle.com>
 
index b5d2526..aa188f5 100644 (file)
@@ -3051,6 +3051,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       { return std::_Hash_impl::hash(__s.data(), __s.length()); }
     };
 
+  template<>
+    struct __is_fast_hash<hash<string>> : 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<hash<wstring>> : 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<hash<u16string>> : std::false_type
+    { };
+
   /// std::hash specialization for u32string.
   template<>
     struct hash<u32string>
@@ -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<hash<u32string>> : std::false_type
+    { };
 #endif
 
 _GLIBCXX_END_NAMESPACE_VERSION
index 5a99c54..bc29235 100644 (file)
@@ -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<typename _Hash>
+    struct __is_fast_hash : public std::true_type
+    { };
+
+  template<>
+    struct __is_fast_hash<hash<long double>> : public std::false_type
+    { };
+
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace
 
index d899fa7..6515b71 100644 (file)
@@ -40,9 +40,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   template<typename _Tp, typename _Hash>
     using __cache_default
-      =  __not_<__and_<// Do not cache for builtin integral types having trivial
-                      // hasher.
-                      is_integral<_Tp>,
+      =  __not_<__and_<// Do not cache for fast hasher.
+                      __is_fast_hash<_Hash>,
                       // Mandatory to make local_iterator default
                       // constructible.
                       is_default_constructible<_Hash>,
index 29549ea..fc5295a 100644 (file)
@@ -26,6 +26,7 @@
 # error "hash_c++0x.cc must be compiled with -std=gnu++0x"
 #endif
 
+#include <type_traits>
 #include <bits/functional_hash.h>
 
 namespace std _GLIBCXX_VISIBILITY(default)
index 6712d62..827691f 100644 (file)
@@ -19,7 +19,7 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-// { dg-error "with noexcept" "" { target *-*-* } 252 }
+// { dg-error "with noexcept" "" { target *-*-* } 251 }
 
 #include <unordered_set>
 
index 53a25bc..bd62a08 100644 (file)
@@ -19,7 +19,7 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-// { dg-error "default constructible" "" { target *-*-* } 268 }
+// { dg-error "default constructible" "" { target *-*-* } 267 }
 
 #include <unordered_set>