1*e4b17023SJohn Marino// Debugging bitset implementation -*- C++ -*- 2*e4b17023SJohn Marino 3*e4b17023SJohn Marino// Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 4*e4b17023SJohn Marino// Free Software Foundation, Inc. 5*e4b17023SJohn Marino// 6*e4b17023SJohn Marino// This file is part of the GNU ISO C++ Library. This library is free 7*e4b17023SJohn Marino// software; you can redistribute it and/or modify it under the 8*e4b17023SJohn Marino// terms of the GNU General Public License as published by the 9*e4b17023SJohn Marino// Free Software Foundation; either version 3, or (at your option) 10*e4b17023SJohn Marino// any later version. 11*e4b17023SJohn Marino 12*e4b17023SJohn Marino// This library is distributed in the hope that it will be useful, 13*e4b17023SJohn Marino// but WITHOUT ANY WARRANTY; without even the implied warranty of 14*e4b17023SJohn Marino// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15*e4b17023SJohn Marino// GNU General Public License for more details. 16*e4b17023SJohn Marino 17*e4b17023SJohn Marino// Under Section 7 of GPL version 3, you are granted additional 18*e4b17023SJohn Marino// permissions described in the GCC Runtime Library Exception, version 19*e4b17023SJohn Marino// 3.1, as published by the Free Software Foundation. 20*e4b17023SJohn Marino 21*e4b17023SJohn Marino// You should have received a copy of the GNU General Public License and 22*e4b17023SJohn Marino// a copy of the GCC Runtime Library Exception along with this program; 23*e4b17023SJohn Marino// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 24*e4b17023SJohn Marino// <http://www.gnu.org/licenses/>. 25*e4b17023SJohn Marino 26*e4b17023SJohn Marino/** @file debug/bitset 27*e4b17023SJohn Marino * This file is a GNU debug extension to the Standard C++ Library. 28*e4b17023SJohn Marino */ 29*e4b17023SJohn Marino 30*e4b17023SJohn Marino#ifndef _GLIBCXX_DEBUG_BITSET 31*e4b17023SJohn Marino#define _GLIBCXX_DEBUG_BITSET 32*e4b17023SJohn Marino 33*e4b17023SJohn Marino#include <bitset> 34*e4b17023SJohn Marino#include <debug/safe_sequence.h> 35*e4b17023SJohn Marino#include <debug/safe_iterator.h> 36*e4b17023SJohn Marino 37*e4b17023SJohn Marinonamespace std _GLIBCXX_VISIBILITY(default) 38*e4b17023SJohn Marino{ 39*e4b17023SJohn Marinonamespace __debug 40*e4b17023SJohn Marino{ 41*e4b17023SJohn Marino /// Class std::bitset with additional safety/checking/debug instrumentation. 42*e4b17023SJohn Marino template<size_t _Nb> 43*e4b17023SJohn Marino class bitset 44*e4b17023SJohn Marino : public _GLIBCXX_STD_C::bitset<_Nb> 45*e4b17023SJohn Marino#ifndef __GXX_EXPERIMENTAL_CXX0X__ 46*e4b17023SJohn Marino , public __gnu_debug::_Safe_sequence_base 47*e4b17023SJohn Marino#endif 48*e4b17023SJohn Marino { 49*e4b17023SJohn Marino typedef _GLIBCXX_STD_C::bitset<_Nb> _Base; 50*e4b17023SJohn Marino 51*e4b17023SJohn Marino public: 52*e4b17023SJohn Marino // In C++0x we rely on normal reference type to preserve the property 53*e4b17023SJohn Marino // of bitset to be use as a literal. 54*e4b17023SJohn Marino // TODO: Find another solution. 55*e4b17023SJohn Marino#ifdef __GXX_EXPERIMENTAL_CXX0X__ 56*e4b17023SJohn Marino typedef typename _Base::reference reference; 57*e4b17023SJohn Marino#else 58*e4b17023SJohn Marino // bit reference: 59*e4b17023SJohn Marino class reference 60*e4b17023SJohn Marino : private _Base::reference 61*e4b17023SJohn Marino , public __gnu_debug::_Safe_iterator_base 62*e4b17023SJohn Marino { 63*e4b17023SJohn Marino typedef typename _Base::reference _Base_ref; 64*e4b17023SJohn Marino 65*e4b17023SJohn Marino friend class bitset; 66*e4b17023SJohn Marino reference(); 67*e4b17023SJohn Marino 68*e4b17023SJohn Marino reference(const _Base_ref& __base, 69*e4b17023SJohn Marino bitset* __seq __attribute__((__unused__))) _GLIBCXX_NOEXCEPT 70*e4b17023SJohn Marino : _Base_ref(__base) 71*e4b17023SJohn Marino , _Safe_iterator_base(__seq, false) 72*e4b17023SJohn Marino { } 73*e4b17023SJohn Marino 74*e4b17023SJohn Marino public: 75*e4b17023SJohn Marino reference(const reference& __x) _GLIBCXX_NOEXCEPT 76*e4b17023SJohn Marino : _Base_ref(__x) 77*e4b17023SJohn Marino , _Safe_iterator_base(__x, false) 78*e4b17023SJohn Marino { } 79*e4b17023SJohn Marino 80*e4b17023SJohn Marino reference& 81*e4b17023SJohn Marino operator=(bool __x) _GLIBCXX_NOEXCEPT 82*e4b17023SJohn Marino { 83*e4b17023SJohn Marino _GLIBCXX_DEBUG_VERIFY(! this->_M_singular(), 84*e4b17023SJohn Marino _M_message(__gnu_debug::__msg_bad_bitset_write) 85*e4b17023SJohn Marino ._M_iterator(*this)); 86*e4b17023SJohn Marino *static_cast<_Base_ref*>(this) = __x; 87*e4b17023SJohn Marino return *this; 88*e4b17023SJohn Marino } 89*e4b17023SJohn Marino 90*e4b17023SJohn Marino reference& 91*e4b17023SJohn Marino operator=(const reference& __x) _GLIBCXX_NOEXCEPT 92*e4b17023SJohn Marino { 93*e4b17023SJohn Marino _GLIBCXX_DEBUG_VERIFY(! __x._M_singular(), 94*e4b17023SJohn Marino _M_message(__gnu_debug::__msg_bad_bitset_read) 95*e4b17023SJohn Marino ._M_iterator(__x)); 96*e4b17023SJohn Marino _GLIBCXX_DEBUG_VERIFY(! this->_M_singular(), 97*e4b17023SJohn Marino _M_message(__gnu_debug::__msg_bad_bitset_write) 98*e4b17023SJohn Marino ._M_iterator(*this)); 99*e4b17023SJohn Marino *static_cast<_Base_ref*>(this) = __x; 100*e4b17023SJohn Marino return *this; 101*e4b17023SJohn Marino } 102*e4b17023SJohn Marino 103*e4b17023SJohn Marino bool 104*e4b17023SJohn Marino operator~() const _GLIBCXX_NOEXCEPT 105*e4b17023SJohn Marino { 106*e4b17023SJohn Marino _GLIBCXX_DEBUG_VERIFY(! this->_M_singular(), 107*e4b17023SJohn Marino _M_message(__gnu_debug::__msg_bad_bitset_read) 108*e4b17023SJohn Marino ._M_iterator(*this)); 109*e4b17023SJohn Marino return ~(*static_cast<const _Base_ref*>(this)); 110*e4b17023SJohn Marino } 111*e4b17023SJohn Marino 112*e4b17023SJohn Marino operator bool() const _GLIBCXX_NOEXCEPT 113*e4b17023SJohn Marino { 114*e4b17023SJohn Marino _GLIBCXX_DEBUG_VERIFY(! this->_M_singular(), 115*e4b17023SJohn Marino _M_message(__gnu_debug::__msg_bad_bitset_read) 116*e4b17023SJohn Marino ._M_iterator(*this)); 117*e4b17023SJohn Marino return *static_cast<const _Base_ref*>(this); 118*e4b17023SJohn Marino } 119*e4b17023SJohn Marino 120*e4b17023SJohn Marino reference& 121*e4b17023SJohn Marino flip() _GLIBCXX_NOEXCEPT 122*e4b17023SJohn Marino { 123*e4b17023SJohn Marino _GLIBCXX_DEBUG_VERIFY(! this->_M_singular(), 124*e4b17023SJohn Marino _M_message(__gnu_debug::__msg_bad_bitset_flip) 125*e4b17023SJohn Marino ._M_iterator(*this)); 126*e4b17023SJohn Marino _Base_ref::flip(); 127*e4b17023SJohn Marino return *this; 128*e4b17023SJohn Marino } 129*e4b17023SJohn Marino }; 130*e4b17023SJohn Marino#endif 131*e4b17023SJohn Marino 132*e4b17023SJohn Marino // 23.3.5.1 constructors: 133*e4b17023SJohn Marino _GLIBCXX_CONSTEXPR bitset() _GLIBCXX_NOEXCEPT 134*e4b17023SJohn Marino : _Base() { } 135*e4b17023SJohn Marino 136*e4b17023SJohn Marino#ifdef __GXX_EXPERIMENTAL_CXX0X__ 137*e4b17023SJohn Marino constexpr bitset(unsigned long long __val) noexcept 138*e4b17023SJohn Marino#else 139*e4b17023SJohn Marino bitset(unsigned long __val) 140*e4b17023SJohn Marino#endif 141*e4b17023SJohn Marino : _Base(__val) { } 142*e4b17023SJohn Marino 143*e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc> 144*e4b17023SJohn Marino explicit 145*e4b17023SJohn Marino bitset(const std::basic_string<_CharT, _Traits, _Alloc>& __str, 146*e4b17023SJohn Marino typename std::basic_string<_CharT, _Traits, _Alloc>::size_type 147*e4b17023SJohn Marino __pos = 0, 148*e4b17023SJohn Marino typename std::basic_string<_CharT, _Traits, _Alloc>::size_type 149*e4b17023SJohn Marino __n = (std::basic_string<_CharT, _Traits, _Alloc>::npos)) 150*e4b17023SJohn Marino : _Base(__str, __pos, __n) { } 151*e4b17023SJohn Marino 152*e4b17023SJohn Marino // _GLIBCXX_RESOLVE_LIB_DEFECTS 153*e4b17023SJohn Marino // 396. what are characters zero and one. 154*e4b17023SJohn Marino template<class _CharT, class _Traits, class _Alloc> 155*e4b17023SJohn Marino bitset(const std::basic_string<_CharT, _Traits, _Alloc>& __str, 156*e4b17023SJohn Marino typename std::basic_string<_CharT, _Traits, _Alloc>::size_type 157*e4b17023SJohn Marino __pos, 158*e4b17023SJohn Marino typename std::basic_string<_CharT, _Traits, _Alloc>::size_type 159*e4b17023SJohn Marino __n, 160*e4b17023SJohn Marino _CharT __zero, _CharT __one = _CharT('1')) 161*e4b17023SJohn Marino : _Base(__str, __pos, __n, __zero, __one) { } 162*e4b17023SJohn Marino 163*e4b17023SJohn Marino bitset(const _Base& __x) : _Base(__x) { } 164*e4b17023SJohn Marino 165*e4b17023SJohn Marino#ifdef __GXX_EXPERIMENTAL_CXX0X__ 166*e4b17023SJohn Marino template<typename _CharT> 167*e4b17023SJohn Marino explicit 168*e4b17023SJohn Marino bitset(const _CharT* __str, 169*e4b17023SJohn Marino typename std::basic_string<_CharT>::size_type __n 170*e4b17023SJohn Marino = std::basic_string<_CharT>::npos, 171*e4b17023SJohn Marino _CharT __zero = _CharT('0'), _CharT __one = _CharT('1')) 172*e4b17023SJohn Marino : _Base(__str, __n, __zero, __one) { } 173*e4b17023SJohn Marino#endif 174*e4b17023SJohn Marino 175*e4b17023SJohn Marino // 23.3.5.2 bitset operations: 176*e4b17023SJohn Marino bitset<_Nb>& 177*e4b17023SJohn Marino operator&=(const bitset<_Nb>& __rhs) _GLIBCXX_NOEXCEPT 178*e4b17023SJohn Marino { 179*e4b17023SJohn Marino _M_base() &= __rhs; 180*e4b17023SJohn Marino return *this; 181*e4b17023SJohn Marino } 182*e4b17023SJohn Marino 183*e4b17023SJohn Marino bitset<_Nb>& 184*e4b17023SJohn Marino operator|=(const bitset<_Nb>& __rhs) _GLIBCXX_NOEXCEPT 185*e4b17023SJohn Marino { 186*e4b17023SJohn Marino _M_base() |= __rhs; 187*e4b17023SJohn Marino return *this; 188*e4b17023SJohn Marino } 189*e4b17023SJohn Marino 190*e4b17023SJohn Marino bitset<_Nb>& 191*e4b17023SJohn Marino operator^=(const bitset<_Nb>& __rhs) _GLIBCXX_NOEXCEPT 192*e4b17023SJohn Marino { 193*e4b17023SJohn Marino _M_base() ^= __rhs; 194*e4b17023SJohn Marino return *this; 195*e4b17023SJohn Marino } 196*e4b17023SJohn Marino 197*e4b17023SJohn Marino bitset<_Nb>& 198*e4b17023SJohn Marino operator<<=(size_t __pos) _GLIBCXX_NOEXCEPT 199*e4b17023SJohn Marino { 200*e4b17023SJohn Marino _M_base() <<= __pos; 201*e4b17023SJohn Marino return *this; 202*e4b17023SJohn Marino } 203*e4b17023SJohn Marino 204*e4b17023SJohn Marino bitset<_Nb>& 205*e4b17023SJohn Marino operator>>=(size_t __pos) _GLIBCXX_NOEXCEPT 206*e4b17023SJohn Marino { 207*e4b17023SJohn Marino _M_base() >>= __pos; 208*e4b17023SJohn Marino return *this; 209*e4b17023SJohn Marino } 210*e4b17023SJohn Marino 211*e4b17023SJohn Marino bitset<_Nb>& 212*e4b17023SJohn Marino set() _GLIBCXX_NOEXCEPT 213*e4b17023SJohn Marino { 214*e4b17023SJohn Marino _Base::set(); 215*e4b17023SJohn Marino return *this; 216*e4b17023SJohn Marino } 217*e4b17023SJohn Marino 218*e4b17023SJohn Marino // _GLIBCXX_RESOLVE_LIB_DEFECTS 219*e4b17023SJohn Marino // 186. bitset::set() second parameter should be bool 220*e4b17023SJohn Marino bitset<_Nb>& 221*e4b17023SJohn Marino set(size_t __pos, bool __val = true) 222*e4b17023SJohn Marino { 223*e4b17023SJohn Marino _Base::set(__pos, __val); 224*e4b17023SJohn Marino return *this; 225*e4b17023SJohn Marino } 226*e4b17023SJohn Marino 227*e4b17023SJohn Marino bitset<_Nb>& 228*e4b17023SJohn Marino reset() _GLIBCXX_NOEXCEPT 229*e4b17023SJohn Marino { 230*e4b17023SJohn Marino _Base::reset(); 231*e4b17023SJohn Marino return *this; 232*e4b17023SJohn Marino } 233*e4b17023SJohn Marino 234*e4b17023SJohn Marino bitset<_Nb>& 235*e4b17023SJohn Marino reset(size_t __pos) 236*e4b17023SJohn Marino { 237*e4b17023SJohn Marino _Base::reset(__pos); 238*e4b17023SJohn Marino return *this; 239*e4b17023SJohn Marino } 240*e4b17023SJohn Marino 241*e4b17023SJohn Marino bitset<_Nb> 242*e4b17023SJohn Marino operator~() const _GLIBCXX_NOEXCEPT 243*e4b17023SJohn Marino { return bitset(~_M_base()); } 244*e4b17023SJohn Marino 245*e4b17023SJohn Marino bitset<_Nb>& 246*e4b17023SJohn Marino flip() _GLIBCXX_NOEXCEPT 247*e4b17023SJohn Marino { 248*e4b17023SJohn Marino _Base::flip(); 249*e4b17023SJohn Marino return *this; 250*e4b17023SJohn Marino } 251*e4b17023SJohn Marino 252*e4b17023SJohn Marino bitset<_Nb>& 253*e4b17023SJohn Marino flip(size_t __pos) 254*e4b17023SJohn Marino { 255*e4b17023SJohn Marino _Base::flip(__pos); 256*e4b17023SJohn Marino return *this; 257*e4b17023SJohn Marino } 258*e4b17023SJohn Marino 259*e4b17023SJohn Marino // element access: 260*e4b17023SJohn Marino // _GLIBCXX_RESOLVE_LIB_DEFECTS 261*e4b17023SJohn Marino // 11. Bitset minor problems 262*e4b17023SJohn Marino reference 263*e4b17023SJohn Marino operator[](size_t __pos) 264*e4b17023SJohn Marino { 265*e4b17023SJohn Marino __glibcxx_check_subscript(__pos); 266*e4b17023SJohn Marino#ifdef __GXX_EXPERIMENTAL_CXX0X__ 267*e4b17023SJohn Marino return _M_base()[__pos]; 268*e4b17023SJohn Marino#else 269*e4b17023SJohn Marino return reference(_M_base()[__pos], this); 270*e4b17023SJohn Marino#endif 271*e4b17023SJohn Marino } 272*e4b17023SJohn Marino 273*e4b17023SJohn Marino // _GLIBCXX_RESOLVE_LIB_DEFECTS 274*e4b17023SJohn Marino // 11. Bitset minor problems 275*e4b17023SJohn Marino _GLIBCXX_CONSTEXPR bool 276*e4b17023SJohn Marino operator[](size_t __pos) const 277*e4b17023SJohn Marino { 278*e4b17023SJohn Marino#ifndef __GXX_EXPERIMENTAL_CXX0X__ 279*e4b17023SJohn Marino // TODO: Check in debug-mode too. 280*e4b17023SJohn Marino __glibcxx_check_subscript(__pos); 281*e4b17023SJohn Marino#endif 282*e4b17023SJohn Marino return _Base::operator[](__pos); 283*e4b17023SJohn Marino } 284*e4b17023SJohn Marino 285*e4b17023SJohn Marino using _Base::to_ulong; 286*e4b17023SJohn Marino#ifdef __GXX_EXPERIMENTAL_CXX0X__ 287*e4b17023SJohn Marino using _Base::to_ullong; 288*e4b17023SJohn Marino#endif 289*e4b17023SJohn Marino 290*e4b17023SJohn Marino template <typename _CharT, typename _Traits, typename _Alloc> 291*e4b17023SJohn Marino std::basic_string<_CharT, _Traits, _Alloc> 292*e4b17023SJohn Marino to_string() const 293*e4b17023SJohn Marino { return _M_base().template to_string<_CharT, _Traits, _Alloc>(); } 294*e4b17023SJohn Marino 295*e4b17023SJohn Marino // _GLIBCXX_RESOLVE_LIB_DEFECTS 296*e4b17023SJohn Marino // 396. what are characters zero and one. 297*e4b17023SJohn Marino template<class _CharT, class _Traits, class _Alloc> 298*e4b17023SJohn Marino std::basic_string<_CharT, _Traits, _Alloc> 299*e4b17023SJohn Marino to_string(_CharT __zero, _CharT __one = _CharT('1')) const 300*e4b17023SJohn Marino { 301*e4b17023SJohn Marino return _M_base().template 302*e4b17023SJohn Marino to_string<_CharT, _Traits, _Alloc>(__zero, __one); 303*e4b17023SJohn Marino } 304*e4b17023SJohn Marino 305*e4b17023SJohn Marino // _GLIBCXX_RESOLVE_LIB_DEFECTS 306*e4b17023SJohn Marino // 434. bitset::to_string() hard to use. 307*e4b17023SJohn Marino template<typename _CharT, typename _Traits> 308*e4b17023SJohn Marino std::basic_string<_CharT, _Traits, std::allocator<_CharT> > 309*e4b17023SJohn Marino to_string() const 310*e4b17023SJohn Marino { return to_string<_CharT, _Traits, std::allocator<_CharT> >(); } 311*e4b17023SJohn Marino 312*e4b17023SJohn Marino // _GLIBCXX_RESOLVE_LIB_DEFECTS 313*e4b17023SJohn Marino // 853. to_string needs updating with zero and one. 314*e4b17023SJohn Marino template<class _CharT, class _Traits> 315*e4b17023SJohn Marino std::basic_string<_CharT, _Traits, std::allocator<_CharT> > 316*e4b17023SJohn Marino to_string(_CharT __zero, _CharT __one = _CharT('1')) const 317*e4b17023SJohn Marino { return to_string<_CharT, _Traits, 318*e4b17023SJohn Marino std::allocator<_CharT> >(__zero, __one); } 319*e4b17023SJohn Marino 320*e4b17023SJohn Marino template<typename _CharT> 321*e4b17023SJohn Marino std::basic_string<_CharT, std::char_traits<_CharT>, 322*e4b17023SJohn Marino std::allocator<_CharT> > 323*e4b17023SJohn Marino to_string() const 324*e4b17023SJohn Marino { 325*e4b17023SJohn Marino return to_string<_CharT, std::char_traits<_CharT>, 326*e4b17023SJohn Marino std::allocator<_CharT> >(); 327*e4b17023SJohn Marino } 328*e4b17023SJohn Marino 329*e4b17023SJohn Marino template<class _CharT> 330*e4b17023SJohn Marino std::basic_string<_CharT, std::char_traits<_CharT>, 331*e4b17023SJohn Marino std::allocator<_CharT> > 332*e4b17023SJohn Marino to_string(_CharT __zero, _CharT __one = _CharT('1')) const 333*e4b17023SJohn Marino { 334*e4b17023SJohn Marino return to_string<_CharT, std::char_traits<_CharT>, 335*e4b17023SJohn Marino std::allocator<_CharT> >(__zero, __one); 336*e4b17023SJohn Marino } 337*e4b17023SJohn Marino 338*e4b17023SJohn Marino std::basic_string<char, std::char_traits<char>, std::allocator<char> > 339*e4b17023SJohn Marino to_string() const 340*e4b17023SJohn Marino { 341*e4b17023SJohn Marino return to_string<char,std::char_traits<char>,std::allocator<char> >(); 342*e4b17023SJohn Marino } 343*e4b17023SJohn Marino 344*e4b17023SJohn Marino std::basic_string<char, std::char_traits<char>, std::allocator<char> > 345*e4b17023SJohn Marino to_string(char __zero, char __one = '1') const 346*e4b17023SJohn Marino { 347*e4b17023SJohn Marino return to_string<char, std::char_traits<char>, 348*e4b17023SJohn Marino std::allocator<char> >(__zero, __one); 349*e4b17023SJohn Marino } 350*e4b17023SJohn Marino 351*e4b17023SJohn Marino using _Base::count; 352*e4b17023SJohn Marino using _Base::size; 353*e4b17023SJohn Marino 354*e4b17023SJohn Marino bool 355*e4b17023SJohn Marino operator==(const bitset<_Nb>& __rhs) const _GLIBCXX_NOEXCEPT 356*e4b17023SJohn Marino { return _M_base() == __rhs; } 357*e4b17023SJohn Marino 358*e4b17023SJohn Marino bool 359*e4b17023SJohn Marino operator!=(const bitset<_Nb>& __rhs) const _GLIBCXX_NOEXCEPT 360*e4b17023SJohn Marino { return _M_base() != __rhs; } 361*e4b17023SJohn Marino 362*e4b17023SJohn Marino using _Base::test; 363*e4b17023SJohn Marino using _Base::all; 364*e4b17023SJohn Marino using _Base::any; 365*e4b17023SJohn Marino using _Base::none; 366*e4b17023SJohn Marino 367*e4b17023SJohn Marino bitset<_Nb> 368*e4b17023SJohn Marino operator<<(size_t __pos) const _GLIBCXX_NOEXCEPT 369*e4b17023SJohn Marino { return bitset<_Nb>(_M_base() << __pos); } 370*e4b17023SJohn Marino 371*e4b17023SJohn Marino bitset<_Nb> 372*e4b17023SJohn Marino operator>>(size_t __pos) const _GLIBCXX_NOEXCEPT 373*e4b17023SJohn Marino { return bitset<_Nb>(_M_base() >> __pos); } 374*e4b17023SJohn Marino 375*e4b17023SJohn Marino _Base& 376*e4b17023SJohn Marino _M_base() _GLIBCXX_NOEXCEPT 377*e4b17023SJohn Marino { return *this; } 378*e4b17023SJohn Marino 379*e4b17023SJohn Marino const _Base& 380*e4b17023SJohn Marino _M_base() const _GLIBCXX_NOEXCEPT 381*e4b17023SJohn Marino { return *this; } 382*e4b17023SJohn Marino }; 383*e4b17023SJohn Marino 384*e4b17023SJohn Marino template<size_t _Nb> 385*e4b17023SJohn Marino bitset<_Nb> 386*e4b17023SJohn Marino operator&(const bitset<_Nb>& __x, const bitset<_Nb>& __y) _GLIBCXX_NOEXCEPT 387*e4b17023SJohn Marino { return bitset<_Nb>(__x) &= __y; } 388*e4b17023SJohn Marino 389*e4b17023SJohn Marino template<size_t _Nb> 390*e4b17023SJohn Marino bitset<_Nb> 391*e4b17023SJohn Marino operator|(const bitset<_Nb>& __x, const bitset<_Nb>& __y) _GLIBCXX_NOEXCEPT 392*e4b17023SJohn Marino { return bitset<_Nb>(__x) |= __y; } 393*e4b17023SJohn Marino 394*e4b17023SJohn Marino template<size_t _Nb> 395*e4b17023SJohn Marino bitset<_Nb> 396*e4b17023SJohn Marino operator^(const bitset<_Nb>& __x, const bitset<_Nb>& __y) _GLIBCXX_NOEXCEPT 397*e4b17023SJohn Marino { return bitset<_Nb>(__x) ^= __y; } 398*e4b17023SJohn Marino 399*e4b17023SJohn Marino template<typename _CharT, typename _Traits, size_t _Nb> 400*e4b17023SJohn Marino std::basic_istream<_CharT, _Traits>& 401*e4b17023SJohn Marino operator>>(std::basic_istream<_CharT, _Traits>& __is, bitset<_Nb>& __x) 402*e4b17023SJohn Marino { return __is >> __x._M_base(); } 403*e4b17023SJohn Marino 404*e4b17023SJohn Marino template<typename _CharT, typename _Traits, size_t _Nb> 405*e4b17023SJohn Marino std::basic_ostream<_CharT, _Traits>& 406*e4b17023SJohn Marino operator<<(std::basic_ostream<_CharT, _Traits>& __os, 407*e4b17023SJohn Marino const bitset<_Nb>& __x) 408*e4b17023SJohn Marino { return __os << __x._M_base(); } 409*e4b17023SJohn Marino 410*e4b17023SJohn Marino} // namespace __debug 411*e4b17023SJohn Marino 412*e4b17023SJohn Marino#ifdef __GXX_EXPERIMENTAL_CXX0X__ 413*e4b17023SJohn Marino // DR 1182. 414*e4b17023SJohn Marino /// std::hash specialization for bitset. 415*e4b17023SJohn Marino template<size_t _Nb> 416*e4b17023SJohn Marino struct hash<__debug::bitset<_Nb>> 417*e4b17023SJohn Marino : public __hash_base<size_t, __debug::bitset<_Nb>> 418*e4b17023SJohn Marino { 419*e4b17023SJohn Marino size_t 420*e4b17023SJohn Marino operator()(const __debug::bitset<_Nb>& __b) const noexcept 421*e4b17023SJohn Marino { return std::hash<_GLIBCXX_STD_C::bitset<_Nb>>()(__b._M_base()); } 422*e4b17023SJohn Marino }; 423*e4b17023SJohn Marino#endif 424*e4b17023SJohn Marino 425*e4b17023SJohn Marino} // namespace std 426*e4b17023SJohn Marino 427*e4b17023SJohn Marino#endif 428