OSDN Git Service

2010-03-02 Paolo Carlini <paolo.carlini@oracle.com>
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 2 Mar 2010 14:08:52 +0000 (14:08 +0000)
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 2 Mar 2010 14:08:52 +0000 (14:08 +0000)
* include/std/bitset (_Base_bitset<>::_M_getdata()): Add.
(hash<_GLIBCXX_STD_D::bitset<_Nb>>): Add, use the latter.
* include/debug/bitset (hash<std::__debug::bitset<_Nb>>): Add.
* include/profile/bitset (hash<std::__profile::bitset<_Nb>>): Likewise.
* testsuite/23_containers/bitset/hash/1.cc: New.

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

libstdc++-v3/ChangeLog
libstdc++-v3/include/debug/bitset
libstdc++-v3/include/profile/bitset
libstdc++-v3/include/std/bitset
libstdc++-v3/testsuite/23_containers/bitset/hash/1.cc [new file with mode: 0644]

index a34bb50..ec69d26 100644 (file)
@@ -1,3 +1,11 @@
+2010-03-02  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       * include/std/bitset (_Base_bitset<>::_M_getdata()): Add.
+       (hash<_GLIBCXX_STD_D::bitset<_Nb>>): Add, use the latter.
+       * include/debug/bitset (hash<std::__debug::bitset<_Nb>>): Add.
+       * include/profile/bitset (hash<std::__profile::bitset<_Nb>>): Likewise.
+       * testsuite/23_containers/bitset/hash/1.cc: New.
+
 2010-03-02  Jonathan Wakely  <jwakely.gcc@gmail.com>
 
        PR libstdc++/43183
index e78eb56..d611892 100644 (file)
@@ -379,6 +379,23 @@ namespace __debug
     { return __os << __x._M_base(); }
 
 } // namespace __debug
+
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+  // DR 1182.
+  /// std::hash specialization for bitset.
+  template<size_t _Nb>
+    struct hash<std::__debug::bitset<_Nb>>
+    : public std::unary_function<std::__debug::bitset<_Nb>, size_t>
+    {
+      size_t
+      operator()(const std::__debug::bitset<_Nb>& __b) const
+      {
+       const size_t __size = (_Nb + __CHAR_BIT__ - 1) / __CHAR_BIT__;
+       return std::_Fnv_hash::hash(__b._M_base()._M_getdata(), __size);
+      }
+    };
+#endif
+
 } // namespace std
 
 #endif
index 2146476..3a988b5 100644 (file)
@@ -353,6 +353,23 @@ namespace __profile
               const bitset<_Nb>& __x)
     { return __os << __x._M_base(); }
 } // namespace __profile
+
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+  // DR 1182.
+  /// std::hash specialization for bitset.
+  template<size_t _Nb>
+    struct hash<std::__profile::bitset<_Nb>>
+    : public std::unary_function<std::__profile::bitset<_Nb>, size_t>
+    {
+      size_t
+      operator()(const std::__profile::bitset<_Nb>& __b) const
+      {
+       const size_t __size = (_Nb + __CHAR_BIT__ - 1) / __CHAR_BIT__;
+       return std::_Fnv_hash::hash(__b._M_base()._M_getdata(), __size);
+      }
+    };
+#endif
+
 } // namespace std
 
 #endif
index 9101e67..23a2e15 100644 (file)
@@ -114,6 +114,12 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
       _M_getword(size_t __pos) const
       { return _M_w[_S_whichword(__pos)]; }
 
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+      const char*
+      _M_getdata() const
+      { return reinterpret_cast<const char*>(_M_w); }
+#endif
+
       _WordT&
       _M_hiword()
       { return _M_w[_Nw - 1]; }
@@ -399,6 +405,12 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
       _M_getword(size_t) const
       { return _M_w; }
 
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+      const char*
+      _M_getdata() const
+      { return reinterpret_cast<const char*>(&_M_w); }
+#endif
+
       _WordT&
       _M_hiword()
       { return _M_w; }
@@ -540,6 +552,12 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
        return *new _WordT; 
       }
 
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+      const char*
+      _M_getdata() const
+      { return reinterpret_cast<const char*>(&_M_getword(0)); }
+#endif
+
       _WordT
       _M_hiword() const
       { return 0; }
@@ -708,6 +726,10 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
            _S_do_sanitize(this->_M_hiword());
        }
 
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+      template<typename> friend class hash;
+#endif
+
     public:
       /**
        *  This encapsulates the concept of a single bit.  An instance of this
@@ -1470,6 +1492,25 @@ _GLIBCXX_END_NESTED_NAMESPACE
 #undef _GLIBCXX_BITSET_WORDS
 #undef _GLIBCXX_BITSET_BITS_PER_WORD
 
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+namespace std
+{
+  // DR 1182.
+  /// std::hash specialization for bitset.
+  template<size_t _Nb>
+    struct hash<_GLIBCXX_STD_D::bitset<_Nb>>
+    : public std::unary_function<_GLIBCXX_STD_D::bitset<_Nb>, size_t>
+    {
+      size_t
+      operator()(const _GLIBCXX_STD_D::bitset<_Nb>& __b) const
+      {
+       const size_t __size = (_Nb + __CHAR_BIT__ - 1) / __CHAR_BIT__;
+       return std::_Fnv_hash::hash(__b._M_getdata(), __size);
+      }
+    };
+}
+#endif // __GXX_EXPERIMENTAL_CXX0X__
+
 #ifdef _GLIBCXX_DEBUG
 # include <debug/bitset>
 #endif
diff --git a/libstdc++-v3/testsuite/23_containers/bitset/hash/1.cc b/libstdc++-v3/testsuite/23_containers/bitset/hash/1.cc
new file mode 100644 (file)
index 0000000..84dc31a
--- /dev/null
@@ -0,0 +1,27 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2010 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <bitset>
+
+// bitset hash
+std::hash<std::bitset<0>>    h1;
+std::hash<std::bitset<10>>   h2;
+std::hash<std::bitset<100>>  h3;
+std::hash<std::bitset<1000>> h4;