_bitset.h

00001 /*
00002  * Copyright (c) 1998
00003  * Silicon Graphics Computer Systems, Inc.
00004  *
00005  * Copyright (c) 1999 
00006  * Boris Fomitchev
00007  *
00008  * This material is provided "as is", with absolutely no warranty expressed
00009  * or implied. Any use is at your own risk.
00010  *
00011  * Permission to use or copy this software for any purpose is hereby granted 
00012  * without fee, provided the above notices are retained on all copies.
00013  * Permission to modify the code and to distribute modified code is granted,
00014  * provided the above notices are retained, and a notice that the code was
00015  * modified is included with the above copyright notice.
00016  *
00017  */
00018 
00019 #ifndef _STLP_BITSET_H
00020 #define _STLP_BITSET_H
00021 
00022 // A bitset of size N has N % (sizeof(unsigned long) * CHAR_BIT) unused 
00023 // bits.  (They are the high- order bits in the highest word.)  It is
00024 // a class invariant of class bitset<> that those unused bits are
00025 // always zero.
00026 
00027 // Most of the actual code isn't contained in bitset<> itself, but in the 
00028 // base class _Base_bitset.  The base class works with whole words, not with
00029 // individual bits.  This allows us to specialize _Base_bitset for the
00030 // important special case where the bitset is only a single word.
00031 
00032 // The C++ standard does not define the precise semantics of operator[].
00033 // In this implementation the const version of operator[] is equivalent
00034 // to test(), except that it does no range checking.  The non-const version
00035 // returns a reference to a bit, again without doing any range checking.
00036 
00037 
00038 # ifndef _STLP_INTERNAL_ALGOBASE_H
00039 #  include <stl/_algobase.h>
00040 # endif
00041 
00042 # ifndef _STLP_INTERNAL_ALLOC_H
00043 #  include <stl/_alloc.h>
00044 # endif
00045 
00046 # ifndef _STLP_INTERNAL_ITERATOR_H
00047 #  include <stl/_iterator.h>
00048 # endif
00049 
00050 # ifndef _STLP_INTERNAL_UNINITIALIZED_H
00051 #  include <stl/_uninitialized.h>
00052 # endif
00053 
00054 # ifndef _STLP_RANGE_ERRORS_H
00055 #  include <stl/_range_errors.h>
00056 # endif
00057 
00058 # ifndef _STLP_STRING
00059 #  include <string>
00060 # endif
00061 
00062 # ifndef _STLP_ISTREAM
00063 #  include <istream>
00064 # endif
00065 
00066 #define __BITS_PER_WORD (CHAR_BIT*sizeof(unsigned long))
00067 #define __BITSET_WORDS(__n) ((__n + __BITS_PER_WORD - 1)/__BITS_PER_WORD)
00068 
00069 _STLP_BEGIN_NAMESPACE
00070 
00071 // structure to aid in counting bits
00072 template<class _Dummy> 
00073 class _Bs_G {
00074 public:
00075   static unsigned char _S_bit_count[256];
00076   // Mapping from 8 bit unsigned integers to the index of the first one
00077   // bit:
00078   static unsigned char _S_first_one[256];
00079 };
00080 
00081 //
00082 // Base class: general case.
00083 //
00084 
00085 template<size_t _Nw>
00086 struct _Base_bitset {
00087   typedef unsigned long _WordT;
00088 
00089   _WordT _M_w[_Nw];                // 0 is the least significant word.
00090 
00091   _Base_bitset( void ) { _M_do_reset(); }
00092 
00093   _Base_bitset(unsigned long __val) {
00094     _M_do_reset();
00095     _M_w[0] = __val;
00096   }
00097   
00098   static size_t _STLP_CALL _S_whichword( size_t __pos ) {
00099     return __pos / __BITS_PER_WORD;
00100   }
00101   static size_t _STLP_CALL _S_whichbyte( size_t __pos ) {
00102     return (__pos % __BITS_PER_WORD) / CHAR_BIT;
00103   }
00104   static size_t _STLP_CALL _S_whichbit( size_t __pos ) {
00105     return __pos % __BITS_PER_WORD;
00106   }
00107   static _WordT _STLP_CALL _S_maskbit( size_t __pos ) {
00108     return __STATIC_CAST(_WordT,1) << _S_whichbit(__pos);
00109   }
00110 
00111   _WordT& _M_getword(size_t __pos)       { return _M_w[_S_whichword(__pos)]; }
00112   _WordT  _M_getword(size_t __pos) const { return _M_w[_S_whichword(__pos)]; }
00113 
00114   _WordT& _M_hiword()       { return _M_w[_Nw - 1]; }
00115   _WordT  _M_hiword() const { return _M_w[_Nw - 1]; }
00116 
00117   void _M_do_and(const _Base_bitset<_Nw>& __x) {
00118     for ( size_t __i = 0; __i < _Nw; __i++ ) {
00119       _M_w[__i] &= __x._M_w[__i];
00120     }
00121   }
00122 
00123   void _M_do_or(const _Base_bitset<_Nw>& __x) {
00124     for ( size_t __i = 0; __i < _Nw; __i++ ) {
00125       _M_w[__i] |= __x._M_w[__i];
00126     }
00127   }
00128 
00129   void _M_do_xor(const _Base_bitset<_Nw>& __x) {
00130     for ( size_t __i = 0; __i < _Nw; __i++ ) {
00131       _M_w[__i] ^= __x._M_w[__i];
00132     }
00133   }
00134 
00135   void _M_do_left_shift(size_t __shift);
00136 
00137   void _M_do_right_shift(size_t __shift);
00138 
00139   void _M_do_flip() {
00140     for ( size_t __i = 0; __i < _Nw; __i++ ) {
00141       _M_w[__i] = ~_M_w[__i];
00142     }
00143   }
00144 
00145   void _M_do_set() {
00146     for ( size_t __i = 0; __i < _Nw; __i++ ) {
00147       _M_w[__i] = ~__STATIC_CAST(_WordT,0);
00148     }
00149   }
00150 
00151 
00152   void _M_do_reset() { memset(_M_w, 0, _Nw * sizeof(_WordT)); }
00153 
00154   bool _M_is_equal(const _Base_bitset<_Nw>& __x) const {
00155     for (size_t __i = 0; __i < _Nw; ++__i) {
00156       if (_M_w[__i] != __x._M_w[__i])
00157         return false;
00158     }
00159     return true;
00160   }
00161 
00162   bool _M_is_any() const {
00163     for ( size_t __i = 0; __i < _Nw ; __i++ ) {
00164       if ( _M_w[__i] != __STATIC_CAST(_WordT,0) )
00165         return true;
00166     }
00167     return false;
00168   }
00169 
00170   size_t _M_do_count() const {
00171     size_t __result = 0;
00172     const unsigned char* __byte_ptr = (const unsigned char*)_M_w;
00173     const unsigned char* __end_ptr = (const unsigned char*)(_M_w+_Nw);
00174 
00175     while ( __byte_ptr < __end_ptr ) {
00176       __result += _Bs_G<bool>::_S_bit_count[*__byte_ptr];
00177       __byte_ptr++;
00178     }
00179     return __result;
00180   }
00181 
00182   unsigned long _M_do_to_ulong() const; 
00183 
00184   // find first "on" bit
00185   size_t _M_do_find_first(size_t __not_found) const;
00186 
00187   // find the next "on" bit that follows "prev"
00188   size_t _M_do_find_next(size_t __prev, size_t __not_found) const;
00189 };
00190 
00191 //
00192 // Base class: specialization for a single word.
00193 //
00194 
00195 _STLP_TEMPLATE_NULL
00196 struct _Base_bitset<1UL> {
00197   typedef unsigned long _WordT;
00198   typedef _Base_bitset<1UL> _Self;
00199 
00200   _WordT _M_w;
00201 
00202   _Base_bitset( void ) : _M_w(0) {}
00203   _Base_bitset(unsigned long __val) : _M_w(__val) {}
00204   
00205   static size_t _STLP_CALL _S_whichword( size_t __pos ) {
00206     return __pos / __BITS_PER_WORD ;
00207   }
00208   static size_t _STLP_CALL _S_whichbyte( size_t __pos ) {
00209     return (__pos % __BITS_PER_WORD) / CHAR_BIT;
00210   }
00211   static size_t _STLP_CALL _S_whichbit( size_t __pos ) {
00212     return __pos % __BITS_PER_WORD;
00213   }
00214   static _WordT _STLP_CALL _S_maskbit( size_t __pos ) {
00215     return (__STATIC_CAST(_WordT,1)) << _S_whichbit(__pos);
00216   }
00217 
00218   _WordT& _M_getword(size_t)       { return _M_w; }
00219   _WordT  _M_getword(size_t) const { return _M_w; }
00220 
00221   _WordT& _M_hiword()       { return _M_w; }
00222   _WordT  _M_hiword() const { return _M_w; }
00223 
00224 
00225   void _M_do_and(const _Self& __x) { _M_w &= __x._M_w; }
00226   void _M_do_or(const _Self& __x)  { _M_w |= __x._M_w; }
00227   void _M_do_xor(const _Self& __x) { _M_w ^= __x._M_w; }
00228   void _M_do_left_shift(size_t __shift)     { _M_w <<= __shift; }
00229   void _M_do_right_shift(size_t __shift)    { _M_w >>= __shift; }
00230   void _M_do_flip()                       { _M_w = ~_M_w; }
00231   void _M_do_set()                        { _M_w = ~__STATIC_CAST(_WordT,0); }
00232   void _M_do_reset()                      { _M_w = 0; }
00233 
00234   bool _M_is_equal(const _Self& __x) const {
00235     return _M_w == __x._M_w;
00236   }
00237   bool _M_is_any() const {
00238     return _M_w != 0;
00239   }
00240 
00241   size_t _M_do_count() const {
00242     size_t __result = 0;
00243     const unsigned char* __byte_ptr = (const unsigned char*)&_M_w;
00244     const unsigned char* __end_ptr = ((const unsigned char*)&_M_w)+sizeof(_M_w);
00245     while ( __byte_ptr < __end_ptr ) {
00246       __result += _Bs_G<bool>::_S_bit_count[*__byte_ptr];
00247       __byte_ptr++;
00248     }
00249     return __result;
00250   }
00251 
00252   unsigned long _M_do_to_ulong() const { return _M_w; }
00253 
00254   inline size_t _M_do_find_first(size_t __not_found) const;
00255 
00256   // find the next "on" bit that follows "prev"
00257   inline size_t _M_do_find_next(size_t __prev, size_t __not_found) const; 
00258 
00259 };
00260 
00261 
00262 // ------------------------------------------------------------
00263 //
00264 // Definitions of should-be-non-inline functions from the single-word version of
00265 //  _Base_bitset.
00266 //
00267 
00268 inline size_t 
00269 _Base_bitset<1UL>::_M_do_find_first(size_t __not_found) const
00270 {
00271   //  typedef unsigned long _WordT;
00272   _WordT __thisword = _M_w;
00273 
00274   if ( __thisword != __STATIC_CAST(_WordT,0) ) {
00275     // find byte within word
00276     for ( size_t __j = 0; __j < sizeof(_WordT); __j++ ) {
00277       unsigned char __this_byte
00278         = __STATIC_CAST(unsigned char,(__thisword & (~(unsigned char)0)));
00279       if ( __this_byte )
00280         return __j*CHAR_BIT + _Bs_G<bool>::_S_first_one[__this_byte];
00281 
00282       __thisword >>= CHAR_BIT;
00283     }
00284   }
00285   // not found, so return a value that indicates failure.
00286   return __not_found;
00287 }
00288 
00289 inline size_t 
00290 _Base_bitset<1UL>::_M_do_find_next(size_t __prev, 
00291                                    size_t __not_found ) const
00292 {
00293   // make bound inclusive
00294   ++__prev;
00295 
00296   // check out of bounds
00297   if ( __prev >= __BITS_PER_WORD )
00298     return __not_found;
00299 
00300     // search first (and only) word
00301   _WordT __thisword = _M_w;
00302 
00303   // mask off bits below bound
00304   __thisword &= (~__STATIC_CAST(_WordT,0)) << _S_whichbit(__prev);
00305 
00306   if ( __thisword != __STATIC_CAST(_WordT,0) ) {
00307     // find byte within word
00308     // get first byte into place
00309     __thisword >>= _S_whichbyte(__prev) * CHAR_BIT;
00310     for ( size_t __j = _S_whichbyte(__prev); __j < sizeof(_WordT); __j++ ) {
00311       unsigned char __this_byte
00312         = __STATIC_CAST(unsigned char,(__thisword & (~(unsigned char)0)));
00313       if ( __this_byte )
00314         return __j*CHAR_BIT + _Bs_G<bool>::_S_first_one[__this_byte];
00315 
00316       __thisword >>= CHAR_BIT;
00317     }
00318   }
00319 
00320   // not found, so return a value that indicates failure.
00321   return __not_found;
00322 } // end _M_do_find_next
00323 
00324 
00325 // ------------------------------------------------------------
00326 // Helper class to zero out the unused high-order bits in the highest word.
00327 
00328 template <size_t _Extrabits> struct _Sanitize {
00329   static void _STLP_CALL _M_do_sanitize(unsigned long& __val)
00330     { __val &= ~((~__STATIC_CAST(unsigned long,0)) << _Extrabits); }
00331 };
00332 
00333 _STLP_TEMPLATE_NULL struct _Sanitize<0UL> {
00334   static void _STLP_CALL _M_do_sanitize(unsigned long) {}
00335 };
00336 
00337 // ------------------------------------------------------------
00338 // Class bitset.
00339 //   _Nb may be any nonzero number of type size_t.
00340 
00341 
00342 template<size_t _Nb>
00343 class bitset : public _Base_bitset<__BITSET_WORDS(_Nb) > 
00344 {
00345 public:
00346   enum { _Words = __BITSET_WORDS(_Nb) } ;
00347 
00348 private:
00349   typedef _Base_bitset< _Words > _Base;
00350 
00351   void _M_do_sanitize() {
00352     _Sanitize<_Nb%__BITS_PER_WORD >::_M_do_sanitize(this->_M_hiword());
00353   }
00354 public:
00355   typedef unsigned long _WordT;
00356   struct reference;
00357   friend struct reference;
00358 
00359   // bit reference:
00360   struct reference {
00361   typedef _Base_bitset<_Words > _Bitset_base;
00362   typedef bitset<_Nb> _Bitset;
00363     //    friend _Bitset;
00364     _WordT *_M_wp;
00365     size_t _M_bpos;
00366 
00367     // should be left undefined
00368     reference() {}
00369 
00370     reference( _Bitset& __b, size_t __pos ) {
00371       _M_wp = &__b._M_getword(__pos);
00372       _M_bpos = _Bitset_base::_S_whichbit(__pos);
00373     }
00374 
00375   public:
00376     ~reference() {}
00377 
00378     // for b[i] = __x;
00379     reference& operator=(bool __x) {
00380       if ( __x )
00381         *_M_wp |= _Bitset_base::_S_maskbit(_M_bpos);
00382       else
00383         *_M_wp &= ~_Bitset_base::_S_maskbit(_M_bpos);
00384 
00385       return *this;
00386     }
00387 
00388     // for b[i] = b[__j];
00389     reference& operator=(const reference& __j) {
00390       if ( (*(__j._M_wp) & _Bitset_base::_S_maskbit(__j._M_bpos)) )
00391         *_M_wp |= _Bitset_base::_S_maskbit(_M_bpos);
00392       else
00393         *_M_wp &= ~_Bitset_base::_S_maskbit(_M_bpos);
00394 
00395       return *this;
00396     }
00397 
00398     // flips the bit
00399     bool operator~() const { return (*(_M_wp) & _Bitset_base::_S_maskbit(_M_bpos)) == 0; }
00400 
00401     // for __x = b[i];
00402     operator bool() const { return (*(_M_wp) & _Bitset_base::_S_maskbit(_M_bpos)) != 0; }
00403 
00404     // for b[i].flip();
00405     reference& flip() {
00406       *_M_wp ^= _Bitset_base::_S_maskbit(_M_bpos);
00407       return *this;
00408     }
00409   };
00410 
00411   // 23.3.5.1 constructors:
00412   bitset() {}
00413 
00414   bitset(unsigned long __val) : _Base_bitset<_Words>(__val) { _M_do_sanitize(); }
00415 
00416 # ifdef _STLP_MEMBER_TEMPLATES
00417   template<class _CharT, class _Traits, class _Alloc>
00418   explicit bitset(const basic_string<_CharT,_Traits,_Alloc>& __s,
00419                   size_t __pos = 0)
00420     : _Base_bitset<_Words >() 
00421   {
00422     if (__pos > __s.size()) 
00423       __stl_throw_out_of_range("bitset");
00424     _M_copy_from_string(__s, __pos,
00425                         basic_string<_CharT, _Traits, _Alloc>::npos);
00426   }
00427   template<class _CharT, class _Traits, class _Alloc>
00428   bitset(const basic_string<_CharT, _Traits, _Alloc>& __s,
00429           size_t __pos,
00430           size_t __n)
00431   : _Base_bitset<_Words >() 
00432   {
00433     if (__pos > __s.size()) 
00434       __stl_throw_out_of_range("bitset");
00435     _M_copy_from_string(__s, __pos, __n);
00436   }
00437 #else /* _STLP_MEMBER_TEMPLATES */
00438   explicit bitset(const string& __s,
00439                   size_t __pos = 0,
00440                   size_t __n = (size_t)-1) 
00441     : _Base_bitset<_Words >() 
00442   {
00443     if (__pos > __s.size()) 
00444       __stl_throw_out_of_range("bitset");
00445     _M_copy_from_string(__s, __pos, __n);
00446   }
00447 #endif /* _STLP_MEMBER_TEMPLATES */
00448 
00449   // 23.3.5.2 bitset operations:
00450   bitset<_Nb>& operator&=(const bitset<_Nb>& __rhs) {
00451     this->_M_do_and(__rhs);
00452     return *this;
00453   }
00454 
00455   bitset<_Nb>& operator|=(const bitset<_Nb>& __rhs) {
00456     this->_M_do_or(__rhs);
00457     return *this;
00458   }
00459 
00460   bitset<_Nb>& operator^=(const bitset<_Nb>& __rhs) {
00461     this->_M_do_xor(__rhs);
00462     return *this;
00463   }
00464 
00465   bitset<_Nb>& operator<<=(size_t __pos) {
00466     this->_M_do_left_shift(__pos);
00467     this->_M_do_sanitize();
00468     return *this;
00469   }
00470 
00471   bitset<_Nb>& operator>>=(size_t __pos) {
00472     this->_M_do_right_shift(__pos);
00473     this->_M_do_sanitize();
00474     return *this;
00475   }
00476 
00477   //
00478   // Extension:
00479   // Versions of single-bit set, reset, flip, test with no range checking.
00480   //
00481 
00482   bitset<_Nb>& _Unchecked_set(size_t __pos) {
00483     this->_M_getword(__pos) |= _Base_bitset<_Words > ::_S_maskbit(__pos);
00484     return *this;
00485   }
00486 
00487   bitset<_Nb>& _Unchecked_set(size_t __pos, int __val) {
00488     if (__val)
00489       this->_M_getword(__pos) |= this->_S_maskbit(__pos);
00490     else
00491       this->_M_getword(__pos) &= ~ this->_S_maskbit(__pos);
00492 
00493     return *this;
00494   }
00495 
00496   bitset<_Nb>& _Unchecked_reset(size_t __pos) {
00497     this->_M_getword(__pos) &= ~ this->_S_maskbit(__pos);
00498     return *this;
00499   }
00500 
00501   bitset<_Nb>& _Unchecked_flip(size_t __pos) {
00502     this->_M_getword(__pos) ^= this->_S_maskbit(__pos);
00503     return *this;
00504   }
00505 
00506   bool _Unchecked_test(size_t __pos) const {
00507     return (this->_M_getword(__pos) & this->_S_maskbit(__pos)) != __STATIC_CAST(_WordT,0);
00508   }
00509 
00510   // Set, reset, and flip.
00511 
00512   bitset<_Nb>& set() {
00513     this->_M_do_set();
00514     this->_M_do_sanitize();
00515     return *this;
00516   }
00517 
00518   bitset<_Nb>& set(size_t __pos) {
00519     if (__pos >= _Nb)
00520       __stl_throw_out_of_range("bitset");
00521     return _Unchecked_set(__pos);
00522   }
00523 
00524   bitset<_Nb>& set(size_t __pos, int __val) {
00525     if (__pos >= _Nb)
00526       __stl_throw_out_of_range("bitset");
00527     return _Unchecked_set(__pos, __val);
00528   }
00529 
00530   bitset<_Nb>& reset() {
00531     this->_M_do_reset();
00532     return *this;
00533   }
00534 
00535   bitset<_Nb>& reset(size_t __pos) {
00536     if (__pos >= _Nb)
00537       __stl_throw_out_of_range("bitset");
00538 
00539     return _Unchecked_reset(__pos);
00540   }
00541 
00542   bitset<_Nb>& flip() {
00543     this->_M_do_flip();
00544     this->_M_do_sanitize();
00545     return *this;
00546   }
00547 
00548   bitset<_Nb>& flip(size_t __pos) {
00549     if (__pos >= _Nb)
00550       __stl_throw_out_of_range("bitset");
00551 
00552     return _Unchecked_flip(__pos);
00553   }
00554 
00555   bitset<_Nb> operator~() const { 
00556     return bitset<_Nb>(*this).flip();
00557   }
00558 
00559   // element access:
00560   //for b[i];
00561   reference operator[](size_t __pos) { return reference(*this,__pos); }
00562   bool operator[](size_t __pos) const { return _Unchecked_test(__pos); }
00563 
00564   unsigned long to_ulong() const { return this->_M_do_to_ulong(); }
00565 
00566 #if defined (_STLP_MEMBER_TEMPLATES) && !  defined (_STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS)
00567   template <class _CharT, class _Traits, class _Alloc>
00568   basic_string<_CharT, _Traits, _Alloc> to_string() const {
00569     basic_string<_CharT, _Traits, _Alloc> __result;
00570     _M_copy_to_string(__result);
00571     return __result;
00572   }
00573 #else
00574   string to_string() const {
00575     string __result;
00576     _M_copy_to_string(__result);
00577     return __result;
00578   }
00579 #endif /* _STLP_EXPLICIT_FUNCTION_TMPL_ARGS */
00580 
00581   size_t count() const { return this->_M_do_count(); }
00582 
00583   size_t size() const { return _Nb; }
00584 
00585   bool operator==(const bitset<_Nb>& __rhs) const {
00586     return this->_M_is_equal(__rhs);
00587   }
00588   bool operator!=(const bitset<_Nb>& __rhs) const {
00589     return !this->_M_is_equal(__rhs);
00590   }
00591 
00592   bool test(size_t __pos) const {
00593     if (__pos >= _Nb)
00594       __stl_throw_out_of_range("bitset");
00595     
00596     return _Unchecked_test(__pos);
00597   }
00598 
00599   bool any() const { return this->_M_is_any(); }
00600   bool none() const { return !this->_M_is_any(); }
00601 
00602   bitset<_Nb> operator<<(size_t __pos) const { 
00603     bitset<_Nb> __result(*this);
00604     __result <<= __pos ;  return __result; 
00605   }
00606   bitset<_Nb> operator>>(size_t __pos) const { 
00607     bitset<_Nb> __result(*this);
00608     __result >>= __pos ;  return __result; 
00609   }
00610 
00611   //
00612   // EXTENSIONS: bit-find operations.  These operations are
00613   // experimental, and are subject to change or removal in future
00614   // versions.
00615   // 
00616 
00617   // find the index of the first "on" bit
00618   size_t _Find_first() const 
00619     { return this->_M_do_find_first(_Nb); }
00620 
00621   // find the index of the next "on" bit after prev
00622   size_t _Find_next( size_t __prev ) const 
00623     { return this->_M_do_find_next(__prev, _Nb); }
00624 
00625 //
00626 // Definitions of should-be non-inline member functions.
00627 //
00628 # if defined (_STLP_MEMBER_TEMPLATES)
00629   template<class _CharT, class _Traits, class _Alloc>
00630     void _M_copy_from_string(const basic_string<_CharT,_Traits,_Alloc>& __s,
00631                              size_t __pos,
00632                              size_t __n) {
00633 #else
00634     void _M_copy_from_string(const string& __s,
00635                              size_t __pos,
00636                              size_t __n) {
00637       typedef char_traits<char> _Traits;
00638 #endif
00639       reset();
00640       size_t __tmp = _Nb;
00641       const size_t __Nbits = (min) (__tmp, (min) (__n, __s.size() - __pos));
00642       for ( size_t __i= 0; __i < __Nbits; ++__i) {
00643         typename _Traits::int_type __k = _Traits::to_int_type(__s[__pos + __Nbits - __i - 1]);
00644         // boris : widen() ?
00645         if (__k == '1')
00646           set(__i);
00647         else if (__k !='0')
00648           __stl_throw_invalid_argument("bitset");
00649       }
00650     }
00651   
00652 # if defined (_STLP_MEMBER_TEMPLATES)
00653   template <class _CharT, class _Traits, class _Alloc>
00654     void _M_copy_to_string(basic_string<_CharT, _Traits, _Alloc>& __s) const
00655 # else
00656     void _M_copy_to_string(string& __s) const
00657 # endif
00658     {
00659       __s.assign(_Nb, '0');
00660       
00661       for (size_t __i = 0; __i < _Nb; ++__i) 
00662         if (_Unchecked_test(__i))
00663           __s[_Nb - 1 - __i] = '1';
00664     }
00665 
00666 # if defined (_STLP_NON_TYPE_TMPL_PARAM_BUG)
00667   bitset<_Nb> operator&(const bitset<_Nb>& __y) const {
00668     bitset<_Nb> __result(*this);
00669     __result &= __y;
00670     return __result;
00671   }
00672   bitset<_Nb> operator|(const bitset<_Nb>& __y) const {
00673     bitset<_Nb> __result(*this);
00674     __result |= __y;
00675     return __result;
00676   }
00677   bitset<_Nb> operator^(const bitset<_Nb>& __y) const {
00678     bitset<_Nb> __result(*this);
00679     __result ^= __y;
00680     return __result;
00681   }
00682 # endif 
00683 
00684 };
00685 
00686 // ------------------------------------------------------------
00687 //
00688 // 23.3.5.3 bitset operations:
00689 //
00690 
00691 # if ! defined (_STLP_NON_TYPE_TMPL_PARAM_BUG)
00692 
00693 template <size_t _Nb>
00694 inline bitset<_Nb>  _STLP_CALL
00695 operator&(const bitset<_Nb>& __x,
00696           const bitset<_Nb>& __y) {
00697   bitset<_Nb> __result(__x);
00698   __result &= __y;
00699   return __result;
00700 }
00701 
00702 
00703 template <size_t _Nb>
00704 inline bitset<_Nb>  _STLP_CALL
00705 operator|(const bitset<_Nb>& __x,
00706           const bitset<_Nb>& __y) {
00707   bitset<_Nb> __result(__x);
00708   __result |= __y;
00709   return __result;
00710 }
00711 
00712 template <size_t _Nb>
00713 inline bitset<_Nb>  _STLP_CALL
00714 operator^(const bitset<_Nb>& __x,
00715           const bitset<_Nb>& __y) {
00716   bitset<_Nb> __result(__x);
00717   __result ^= __y;
00718   return __result;
00719 }
00720 
00721 #if defined ( _STLP_USE_NEW_IOSTREAMS )
00722 
00723 template <class _CharT, class _Traits, size_t _Nb>
00724 basic_istream<_CharT, _Traits>&  _STLP_CALL
00725 operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Nb>& __x);
00726 
00727 
00728 template <class _CharT, class _Traits, size_t _Nb>
00729 basic_ostream<_CharT, _Traits>& _STLP_CALL
00730 operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Nb>& __x);
00731 
00732 #elif ! defined ( _STLP_USE_NO_IOSTREAMS )
00733 
00734 // (reg) For Watcom IO, this tells if ostream class is in .exe or in .dll
00735 template <size_t _Nb>
00736 _ISTREAM_DLL& _STLP_CALL
00737 operator>>(_ISTREAM_DLL& __is, bitset<_Nb>& __x);
00738 
00739 template <size_t _Nb>
00740 inline _OSTREAM_DLL&  _STLP_CALL operator<<(_OSTREAM_DLL& __os, const bitset<_Nb>& __x) {
00741   string __tmp;
00742   __x._M_copy_to_string(__tmp);
00743   return __os << __tmp;
00744 }
00745 
00746 #endif
00747 
00748 # endif /* _STLP_NON_TYPE_TMPL_PARAM_BUG */
00749 
00750 #  undef  bitset
00751 
00752 
00753 _STLP_END_NAMESPACE
00754 
00755 #  undef __BITS_PER_WORD
00756 #  undef __BITSET_WORDS
00757 
00758 # if !defined (_STLP_LINK_TIME_INSTANTIATION)
00759 #  include <stl/_bitset.c>
00760 # endif
00761 
00762 #endif /* _STLP_BITSET_H */
00763 
00764 
00765 // Local Variables:
00766 // mode:C++
00767 // End:
00768 

Generated on Mon Jun 5 10:20:45 2006 for Intelligence.kdevelop by  doxygen 1.4.6