* 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
+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
{ 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
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
_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]; }
_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; }
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; }
_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
#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
--- /dev/null
+// { 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;