From b6c27c1023b73cddc9b714d8fec6f5265d1d07a6 Mon Sep 17 00:00:00 2001 From: paolo Date: Tue, 2 Mar 2010 14:08:52 +0000 Subject: [PATCH] 2010-03-02 Paolo Carlini * include/std/bitset (_Base_bitset<>::_M_getdata()): Add. (hash<_GLIBCXX_STD_D::bitset<_Nb>>): Add, use the latter. * include/debug/bitset (hash>): Add. * include/profile/bitset (hash>): 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 | 8 +++++ libstdc++-v3/include/debug/bitset | 17 +++++++++ libstdc++-v3/include/profile/bitset | 17 +++++++++ libstdc++-v3/include/std/bitset | 41 ++++++++++++++++++++++ .../testsuite/23_containers/bitset/hash/1.cc | 27 ++++++++++++++ 5 files changed, 110 insertions(+) create mode 100644 libstdc++-v3/testsuite/23_containers/bitset/hash/1.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index a34bb50875e..ec69d26a3a9 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,11 @@ +2010-03-02 Paolo Carlini + + * include/std/bitset (_Base_bitset<>::_M_getdata()): Add. + (hash<_GLIBCXX_STD_D::bitset<_Nb>>): Add, use the latter. + * include/debug/bitset (hash>): Add. + * include/profile/bitset (hash>): Likewise. + * testsuite/23_containers/bitset/hash/1.cc: New. + 2010-03-02 Jonathan Wakely PR libstdc++/43183 diff --git a/libstdc++-v3/include/debug/bitset b/libstdc++-v3/include/debug/bitset index e78eb561573..d611892e680 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 + struct hash> + : public std::unary_function, 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 21464767331..3a988b5b437 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 + struct hash> + : public std::unary_function, 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 9101e6797ea..23a2e157c01 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(_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(&_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(&_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 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 + 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 #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 00000000000..84dc31aba4a --- /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 +// . + +#include + +// bitset hash +std::hash> h1; +std::hash> h2; +std::hash> h3; +std::hash> h4; -- 2.11.0