diff options
author | Paolo Carlini <paolo.carlini@oracle.com> | 2010-03-02 14:08:52 +0000 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2010-03-02 14:08:52 +0000 |
commit | ec7058d64dfb1cfc875f5c4692a6568c9520baee (patch) | |
tree | e23eda74f735f0342e9ef1bbfc135a5698e27b00 | |
parent | d9a6979d96fcd19b2aa2660180c3a6ec26909cb3 (diff) | |
download | gcc-ec7058d64dfb1cfc875f5c4692a6568c9520baee.zip gcc-ec7058d64dfb1cfc875f5c4692a6568c9520baee.tar.gz gcc-ec7058d64dfb1cfc875f5c4692a6568c9520baee.tar.bz2 |
bitset (_Base_bitset<>::_M_getdata()): Add.
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.
From-SVN: r157165
-rw-r--r-- | libstdc++-v3/ChangeLog | 8 | ||||
-rw-r--r-- | libstdc++-v3/include/debug/bitset | 17 | ||||
-rw-r--r-- | libstdc++-v3/include/profile/bitset | 17 | ||||
-rw-r--r-- | libstdc++-v3/include/std/bitset | 41 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/23_containers/bitset/hash/1.cc | 27 |
5 files changed, 110 insertions, 0 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index a34bb50..ec69d26a 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -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 diff --git a/libstdc++-v3/include/debug/bitset b/libstdc++-v3/include/debug/bitset index e78eb56..d611892 100644 --- a/libstdc++-v3/include/debug/bitset +++ b/libstdc++-v3/include/debug/bitset @@ -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 diff --git a/libstdc++-v3/include/profile/bitset b/libstdc++-v3/include/profile/bitset index 2146476..3a988b5 100644 --- a/libstdc++-v3/include/profile/bitset +++ b/libstdc++-v3/include/profile/bitset @@ -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 diff --git a/libstdc++-v3/include/std/bitset b/libstdc++-v3/include/std/bitset index 9101e67..23a2e15 100644 --- a/libstdc++-v3/include/std/bitset +++ b/libstdc++-v3/include/std/bitset @@ -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 index 0000000..84dc31a --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/bitset/hash/1.cc @@ -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; |