OSDN Git Service

2014-04-01 Richard Biener <rguenther@suse.de>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / include / tr1 / functional_hash.h
index 98fb187..1742e15 100644 (file)
@@ -24,7 +24,7 @@
 
 /** @file tr1/functional_hash.h
  *  This is an internal header file, included by other library headers.
- *  You should not attempt to use it directly.
+ *  Do not attempt to use it directly. @headername{tr1/functional}
  */
 
 #ifndef _GLIBCXX_TR1_FUNCTIONAL_HASH_H
 
 #pragma GCC system_header
 
-namespace std
+namespace std _GLIBCXX_VISIBILITY(default)
 {
 namespace tr1
 {
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
   /// Class template hash.
   // Declaration of default hash functor std::tr1::hash.  The types for
   // which std::tr1::hash<T> is well-defined is in clause 6.3.3. of the PDTR.
@@ -85,47 +87,53 @@ namespace tr1
   template<size_t>
     struct _Fnv_hash_base
     {
-      static size_t
-      hash(const char* __first, size_t __length)
-      {
-       size_t __result = 0;
-       for (; __length > 0; --__length)
-         __result = (__result * 131) + *__first++;
-       return __result;
-      }
+      template<typename _Tp>
+        static size_t
+        hash(const _Tp* __ptr, size_t __clength)
+        {
+         size_t __result = 0;
+         const char* __cptr = reinterpret_cast<const char*>(__ptr);
+         for (; __clength; --__clength)
+           __result = (__result * 131) + *__cptr++;
+         return __result;
+       }
     };
 
   template<>
     struct _Fnv_hash_base<4>
     {
-      static size_t
-      hash(const char* __first, size_t __length)
-      {
-       size_t __result = static_cast<size_t>(2166136261UL);
-       for (; __length > 0; --__length)
-         {
-           __result ^= static_cast<size_t>(*__first++);
-           __result *= static_cast<size_t>(16777619UL);
-         }
-       return __result;
-      }
+      template<typename _Tp>
+        static size_t
+        hash(const _Tp* __ptr, size_t __clength)
+        {
+         size_t __result = static_cast<size_t>(2166136261UL);
+         const char* __cptr = reinterpret_cast<const char*>(__ptr);
+         for (; __clength; --__clength)
+           {
+             __result ^= static_cast<size_t>(*__cptr++);
+             __result *= static_cast<size_t>(16777619UL);
+           }
+         return __result;
+       }
     };
   
   template<>
     struct _Fnv_hash_base<8>
     {
-      static size_t
-      hash(const char* __first, size_t __length)
-      {
-       size_t __result =
-         static_cast<size_t>(14695981039346656037ULL);
-       for (; __length > 0; --__length)
-         {
-           __result ^= static_cast<size_t>(*__first++);
-           __result *= static_cast<size_t>(1099511628211ULL);
-         }
-       return __result;
-      }
+      template<typename _Tp>
+        static size_t
+        hash(const _Tp* __ptr, size_t __clength)
+        {
+         size_t __result
+           = static_cast<size_t>(14695981039346656037ULL);
+         const char* __cptr = reinterpret_cast<const char*>(__ptr);
+         for (; __clength; --__clength)
+           {
+             __result ^= static_cast<size_t>(*__cptr++);
+             __result *= static_cast<size_t>(1099511628211ULL);
+           }
+         return __result;
+       }
     };
 
   struct _Fnv_hash
@@ -136,8 +144,7 @@ namespace tr1
     template<typename _Tp>
       static size_t
       hash(const _Tp& __val)
-      { return hash(reinterpret_cast<const char*>(&__val),
-                   sizeof(__val)); }
+      { return hash(&__val, sizeof(__val)); }
   };
 
   /// Explicit specializations for float.
@@ -181,6 +188,8 @@ namespace tr1
     _GLIBCXX_PURE size_t
     hash<const wstring&>::operator()(const wstring&) const;
 #endif
+
+_GLIBCXX_END_NAMESPACE_VERSION
 }
 }