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
This commit is contained in:
Paolo Carlini 2010-03-02 14:08:52 +00:00 committed by Paolo Carlini
parent d9a6979d96
commit ec7058d64d
5 changed files with 110 additions and 0 deletions

View 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

View 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

View 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

View 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

View file

@ -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;