epoc32/include/stdapis/stlport/stl/_bitset.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
     1 /*
     2  * © Portions copyright (c) 2006-2007 Nokia Corporation.  All rights reserved.
     3  * Copyright (c) 1998
     4  * Silicon Graphics Computer Systems, Inc.
     5  *
     6  * Copyright (c) 1999 
     7  * Boris Fomitchev
     8  *
     9  * This material is provided "as is", with absolutely no warranty expressed
    10  * or implied. Any use is at your own risk.
    11  *
    12  * Permission to use or copy this software for any purpose is hereby granted 
    13  * without fee, provided the above notices are retained on all copies.
    14  * Permission to modify the code and to distribute modified code is granted,
    15  * provided the above notices are retained, and a notice that the code was
    16  * modified is included with the above copyright notice.
    17  *
    18  */
    19 
    20 #ifndef _STLP_BITSET_H
    21 #define _STLP_BITSET_H
    22 
    23 // A bitset of size N has N % (sizeof(unsigned long) * CHAR_BIT) unused 
    24 // bits.  (They are the high- order bits in the highest word.)  It is
    25 // a class invariant of class bitset<> that those unused bits are
    26 // always zero.
    27 
    28 // Most of the actual code isn't contained in bitset<> itself, but in the 
    29 // base class _Base_bitset.  The base class works with whole words, not with
    30 // individual bits.  This allows us to specialize _Base_bitset for the
    31 // important special case where the bitset is only a single word.
    32 
    33 // The C++ standard does not define the precise semantics of operator[].
    34 // In this implementation the const version of operator[] is equivalent
    35 // to test(), except that it does no range checking.  The non-const version
    36 // returns a reference to a bit, again without doing any range checking.
    37 
    38 
    39 # ifndef _STLP_INTERNAL_ALGOBASE_H
    40 #  include <stl/_algobase.h>
    41 # endif
    42 
    43 # ifndef _STLP_INTERNAL_ALLOC_H
    44 #  include <stl/_alloc.h>
    45 # endif
    46 
    47 # ifndef _STLP_INTERNAL_ITERATOR_H
    48 #  include <stl/_iterator.h>
    49 # endif
    50 
    51 # ifndef _STLP_INTERNAL_UNINITIALIZED_H
    52 #  include <stl/_uninitialized.h>
    53 # endif
    54 
    55 # ifndef _STLP_RANGE_ERRORS_H
    56 #  include <stl/_range_errors.h>
    57 # endif
    58 
    59 # ifndef _STLP_STRING
    60 #  include <string>
    61 # endif
    62 
    63 # ifndef _STLP_ISTREAM
    64 #  include <istream>
    65 # endif
    66 
    67 #define __BITS_PER_WORD (CHAR_BIT*sizeof(unsigned long))
    68 #define __BITSET_WORDS(__n) ((__n + __BITS_PER_WORD - 1)/__BITS_PER_WORD)
    69 
    70 _STLP_BEGIN_NAMESPACE
    71 
    72 // structure to aid in counting bits
    73 template<class _Dummy> 
    74 class _Bs_G {
    75 public:
    76   static const unsigned char _S_bit_count[256];
    77   // Mapping from 8 bit unsigned integers to the index of the first one
    78   // bit:
    79   static const unsigned char _S_first_one[256];
    80 };
    81 
    82 //
    83 // Base class: general case.
    84 //
    85 
    86 template<size_t _Nw>
    87 struct _Base_bitset {
    88   typedef unsigned long _WordT;
    89 
    90   _WordT _M_w[_Nw];                // 0 is the least significant word.
    91 
    92   _Base_bitset( void ) { _M_do_reset(); }
    93 
    94   _Base_bitset(unsigned long __val) {
    95     _M_do_reset();
    96     _M_w[0] = __val;
    97   }
    98   
    99   static size_t _STLP_CALL _S_whichword( size_t __pos ) {
   100     return __pos / __BITS_PER_WORD;
   101   }
   102   static size_t _STLP_CALL _S_whichbyte( size_t __pos ) {
   103     return (__pos % __BITS_PER_WORD) / CHAR_BIT;
   104   }
   105   static size_t _STLP_CALL _S_whichbit( size_t __pos ) {
   106     return __pos % __BITS_PER_WORD;
   107   }
   108   static _WordT _STLP_CALL _S_maskbit( size_t __pos ) {
   109     return __STATIC_CAST(_WordT,1) << _S_whichbit(__pos);
   110   }
   111 
   112   _WordT& _M_getword(size_t __pos)       { return _M_w[_S_whichword(__pos)]; }
   113   _WordT  _M_getword(size_t __pos) const { return _M_w[_S_whichword(__pos)]; }
   114 
   115   _WordT& _M_hiword()       { return _M_w[_Nw - 1]; }
   116   _WordT  _M_hiword() const { return _M_w[_Nw - 1]; }
   117 
   118   void _M_do_and(const _Base_bitset<_Nw>& __x) {
   119     for ( size_t __i = 0; __i < _Nw; __i++ ) {
   120       _M_w[__i] &= __x._M_w[__i];
   121     }
   122   }
   123 
   124   void _M_do_or(const _Base_bitset<_Nw>& __x) {
   125     for ( size_t __i = 0; __i < _Nw; __i++ ) {
   126       _M_w[__i] |= __x._M_w[__i];
   127     }
   128   }
   129 
   130   void _M_do_xor(const _Base_bitset<_Nw>& __x) {
   131     for ( size_t __i = 0; __i < _Nw; __i++ ) {
   132       _M_w[__i] ^= __x._M_w[__i];
   133     }
   134   }
   135 
   136   void _M_do_left_shift(size_t __shift);
   137 
   138   void _M_do_right_shift(size_t __shift);
   139 
   140   void _M_do_flip() {
   141     for ( size_t __i = 0; __i < _Nw; __i++ ) {
   142       _M_w[__i] = ~_M_w[__i];
   143     }
   144   }
   145 
   146   void _M_do_set() {
   147     for ( size_t __i = 0; __i < _Nw; __i++ ) {
   148       _M_w[__i] = ~__STATIC_CAST(_WordT,0);
   149     }
   150   }
   151 
   152 
   153   void _M_do_reset() { memset(_M_w, 0, _Nw * sizeof(_WordT)); }
   154 
   155   bool _M_is_equal(const _Base_bitset<_Nw>& __x) const {
   156     for (size_t __i = 0; __i < _Nw; ++__i) {
   157       if (_M_w[__i] != __x._M_w[__i])
   158         return false;
   159     }
   160     return true;
   161   }
   162 
   163   bool _M_is_any() const {
   164     for ( size_t __i = 0; __i < _Nw ; __i++ ) {
   165       if ( _M_w[__i] != __STATIC_CAST(_WordT,0) )
   166         return true;
   167     }
   168     return false;
   169   }
   170 
   171   size_t _M_do_count() const {
   172     size_t __result = 0;
   173     const unsigned char* __byte_ptr = (const unsigned char*)_M_w;
   174     const unsigned char* __end_ptr = (const unsigned char*)(_M_w+_Nw);
   175 
   176     while ( __byte_ptr < __end_ptr ) {
   177       __result += _Bs_G<bool>::_S_bit_count[*__byte_ptr];
   178       __byte_ptr++;
   179     }
   180     return __result;
   181   }
   182 
   183   unsigned long _M_do_to_ulong() const; 
   184 
   185   // find first "on" bit
   186   size_t _M_do_find_first(size_t __not_found) const;
   187 
   188   // find the next "on" bit that follows "prev"
   189   size_t _M_do_find_next(size_t __prev, size_t __not_found) const;
   190 };
   191 
   192 //
   193 // Base class: specialization for a single word.
   194 //
   195 
   196 _STLP_TEMPLATE_NULL
   197 struct _Base_bitset<1UL> {
   198   typedef unsigned long _WordT;
   199   typedef _Base_bitset<1UL> _Self;
   200 
   201   _WordT _M_w;
   202 
   203   _Base_bitset( void ) : _M_w(0) {}
   204   _Base_bitset(unsigned long __val) : _M_w(__val) {}
   205   
   206   static size_t _STLP_CALL _S_whichword( size_t __pos ) {
   207     return __pos / __BITS_PER_WORD ;
   208   }
   209   static size_t _STLP_CALL _S_whichbyte( size_t __pos ) {
   210     return (__pos % __BITS_PER_WORD) / CHAR_BIT;
   211   }
   212   static size_t _STLP_CALL _S_whichbit( size_t __pos ) {
   213     return __pos % __BITS_PER_WORD;
   214   }
   215   static _WordT _STLP_CALL _S_maskbit( size_t __pos ) {
   216     return (__STATIC_CAST(_WordT,1)) << _S_whichbit(__pos);
   217   }
   218 
   219   _WordT& _M_getword(size_t)       { return _M_w; }
   220   _WordT  _M_getword(size_t) const { return _M_w; }
   221 
   222   _WordT& _M_hiword()       { return _M_w; }
   223   _WordT  _M_hiword() const { return _M_w; }
   224 
   225 
   226   void _M_do_and(const _Self& __x) { _M_w &= __x._M_w; }
   227   void _M_do_or(const _Self& __x)  { _M_w |= __x._M_w; }
   228   void _M_do_xor(const _Self& __x) { _M_w ^= __x._M_w; }
   229   void _M_do_left_shift(size_t __shift)     { _M_w <<= __shift; }
   230   void _M_do_right_shift(size_t __shift)    { _M_w >>= __shift; }
   231   void _M_do_flip()                       { _M_w = ~_M_w; }
   232   void _M_do_set()                        { _M_w = ~__STATIC_CAST(_WordT,0); }
   233   void _M_do_reset()                      { _M_w = 0; }
   234 
   235   bool _M_is_equal(const _Self& __x) const {
   236     return _M_w == __x._M_w;
   237   }
   238   bool _M_is_any() const {
   239     return _M_w != 0;
   240   }
   241 
   242   size_t _M_do_count() const {
   243     size_t __result = 0;
   244     const unsigned char* __byte_ptr = (const unsigned char*)&_M_w;
   245     const unsigned char* __end_ptr = ((const unsigned char*)&_M_w)+sizeof(_M_w);
   246     while ( __byte_ptr < __end_ptr ) {
   247       __result += _Bs_G<bool>::_S_bit_count[*__byte_ptr];
   248       __byte_ptr++;
   249     }
   250     return __result;
   251   }
   252 
   253   unsigned long _M_do_to_ulong() const { return _M_w; }
   254 
   255   inline size_t _M_do_find_first(size_t __not_found) const;
   256 
   257   // find the next "on" bit that follows "prev"
   258   inline size_t _M_do_find_next(size_t __prev, size_t __not_found) const; 
   259 
   260 };
   261 
   262 
   263 // ------------------------------------------------------------
   264 //
   265 // Definitions of should-be-non-inline functions from the single-word version of
   266 //  _Base_bitset.
   267 //
   268 
   269 inline size_t 
   270 _Base_bitset<1UL>::_M_do_find_first(size_t __not_found) const
   271 {
   272   //  typedef unsigned long _WordT;
   273   _WordT __thisword = _M_w;
   274 
   275   if ( __thisword != __STATIC_CAST(_WordT,0) ) {
   276     // find byte within word
   277     for ( size_t __j = 0; __j < sizeof(_WordT); __j++ ) {
   278       unsigned char __this_byte
   279         = __STATIC_CAST(unsigned char,(__thisword & (~(unsigned char)0)));
   280       if ( __this_byte )
   281         return __j*CHAR_BIT + _Bs_G<bool>::_S_first_one[__this_byte];
   282 
   283       __thisword >>= CHAR_BIT;
   284     }
   285   }
   286   // not found, so return a value that indicates failure.
   287   return __not_found;
   288 }
   289 
   290 inline size_t 
   291 _Base_bitset<1UL>::_M_do_find_next(size_t __prev, 
   292                                    size_t __not_found ) const
   293 {
   294   // make bound inclusive
   295   ++__prev;
   296 
   297   // check out of bounds
   298   if ( __prev >= __BITS_PER_WORD )
   299     return __not_found;
   300 
   301     // search first (and only) word
   302   _WordT __thisword = _M_w;
   303 
   304   // mask off bits below bound
   305   __thisword &= (~__STATIC_CAST(_WordT,0)) << _S_whichbit(__prev);
   306 
   307   if ( __thisword != __STATIC_CAST(_WordT,0) ) {
   308     // find byte within word
   309     // get first byte into place
   310     __thisword >>= _S_whichbyte(__prev) * CHAR_BIT;
   311     for ( size_t __j = _S_whichbyte(__prev); __j < sizeof(_WordT); __j++ ) {
   312       unsigned char __this_byte
   313         = __STATIC_CAST(unsigned char,(__thisword & (~(unsigned char)0)));
   314       if ( __this_byte )
   315         return __j*CHAR_BIT + _Bs_G<bool>::_S_first_one[__this_byte];
   316 
   317       __thisword >>= CHAR_BIT;
   318     }
   319   }
   320 
   321   // not found, so return a value that indicates failure.
   322   return __not_found;
   323 } // end _M_do_find_next
   324 
   325 
   326 // ------------------------------------------------------------
   327 // Helper class to zero out the unused high-order bits in the highest word.
   328 
   329 template <size_t _Extrabits> struct _Sanitize {
   330   static void _STLP_CALL _M_do_sanitize(unsigned long& __val)
   331     { __val &= ~((~__STATIC_CAST(unsigned long,0)) << _Extrabits); }
   332 };
   333 
   334 _STLP_TEMPLATE_NULL struct _Sanitize<0UL> {
   335   static void _STLP_CALL _M_do_sanitize(unsigned long) {}
   336 };
   337 
   338 // ------------------------------------------------------------
   339 // Class bitset.
   340 //   _Nb may be any nonzero number of type size_t.
   341 
   342 
   343 template<size_t _Nb>
   344 class bitset : public _Base_bitset<__BITSET_WORDS(_Nb) > 
   345 {
   346 public:
   347   enum { _Words = __BITSET_WORDS(_Nb) } ;
   348 
   349 private:
   350   typedef _Base_bitset< _Words > _Base;
   351 
   352   void _M_do_sanitize() {
   353     _Sanitize<_Nb%__BITS_PER_WORD >::_M_do_sanitize(this->_M_hiword());
   354   }
   355 public:
   356   typedef unsigned long _WordT;
   357   struct reference;
   358   friend struct reference;
   359 
   360   // bit reference:
   361   struct reference {
   362   typedef _Base_bitset<_Words > _Bitset_base;
   363   typedef bitset<_Nb> _Bitset;
   364     //    friend _Bitset;
   365     _WordT *_M_wp;
   366     size_t _M_bpos;
   367 
   368     // should be left undefined
   369     reference() {}
   370 
   371     reference( _Bitset& __b, size_t __pos ) {
   372       _M_wp = &__b._M_getword(__pos);
   373       _M_bpos = _Bitset_base::_S_whichbit(__pos);
   374     }
   375 
   376   public:
   377     ~reference() {}
   378 
   379     // for b[i] = __x;
   380     reference& operator=(bool __x) {
   381       if ( __x )
   382         *_M_wp |= _Bitset_base::_S_maskbit(_M_bpos);
   383       else
   384         *_M_wp &= ~_Bitset_base::_S_maskbit(_M_bpos);
   385 
   386       return *this;
   387     }
   388 
   389     // for b[i] = b[__j];
   390     reference& operator=(const reference& __j) {
   391       if ( (*(__j._M_wp) & _Bitset_base::_S_maskbit(__j._M_bpos)) )
   392         *_M_wp |= _Bitset_base::_S_maskbit(_M_bpos);
   393       else
   394         *_M_wp &= ~_Bitset_base::_S_maskbit(_M_bpos);
   395 
   396       return *this;
   397     }
   398 
   399     // flips the bit
   400     bool operator~() const { return (*(_M_wp) & _Bitset_base::_S_maskbit(_M_bpos)) == 0; }
   401 
   402     // for __x = b[i];
   403     operator bool() const { return (*(_M_wp) & _Bitset_base::_S_maskbit(_M_bpos)) != 0; }
   404 
   405     // for b[i].flip();
   406     reference& flip() {
   407       *_M_wp ^= _Bitset_base::_S_maskbit(_M_bpos);
   408       return *this;
   409     }
   410   };
   411 
   412   // 23.3.5.1 constructors:
   413   bitset() {}
   414 
   415   bitset(unsigned long __val) : _Base_bitset<_Words>(__val) { _M_do_sanitize(); }
   416 
   417 # ifdef _STLP_MEMBER_TEMPLATES
   418   template<class _CharT, class _Traits, class _Alloc>
   419   explicit bitset(const basic_string<_CharT,_Traits,_Alloc>& __s,
   420                   size_t __pos = 0)
   421     : _Base_bitset<_Words >() 
   422   {
   423     if (__pos > __s.size()) 
   424       __stl_throw_out_of_range("bitset");
   425     _M_copy_from_string(__s, __pos,
   426                         basic_string<_CharT, _Traits, _Alloc>::npos);
   427   }
   428   template<class _CharT, class _Traits, class _Alloc>
   429   bitset(const basic_string<_CharT, _Traits, _Alloc>& __s,
   430           size_t __pos,
   431           size_t __n)
   432   : _Base_bitset<_Words >() 
   433   {
   434     if (__pos > __s.size()) 
   435       __stl_throw_out_of_range("bitset");
   436     _M_copy_from_string(__s, __pos, __n);
   437   }
   438 #else /* _STLP_MEMBER_TEMPLATES */
   439   explicit bitset(const string& __s,
   440                   size_t __pos = 0,
   441                   size_t __n = (size_t)-1) 
   442     : _Base_bitset<_Words >() 
   443   {
   444     if (__pos > __s.size()) 
   445       __stl_throw_out_of_range("bitset");
   446     _M_copy_from_string(__s, __pos, __n);
   447   }
   448 #endif /* _STLP_MEMBER_TEMPLATES */
   449 
   450   // 23.3.5.2 bitset operations:
   451   bitset<_Nb>& operator&=(const bitset<_Nb>& __rhs) {
   452     this->_M_do_and(__rhs);
   453     return *this;
   454   }
   455 
   456   bitset<_Nb>& operator|=(const bitset<_Nb>& __rhs) {
   457     this->_M_do_or(__rhs);
   458     return *this;
   459   }
   460 
   461   bitset<_Nb>& operator^=(const bitset<_Nb>& __rhs) {
   462     this->_M_do_xor(__rhs);
   463     return *this;
   464   }
   465 
   466   bitset<_Nb>& operator<<=(size_t __pos) {
   467 #ifdef __SYMBIAN32__
   468 	if(__pos < _Nb)
   469 	{
   470     	this->_M_do_left_shift(__pos);
   471     	this->_M_do_sanitize();
   472 	}
   473 	else
   474 		this->_M_do_reset();
   475 #else
   476 	this->_M_do_left_shift(__pos);
   477 	this->_M_do_sanitize();
   478 #endif
   479 
   480     return *this;
   481   }
   482 
   483   bitset<_Nb>& operator>>=(size_t __pos) {
   484 #ifdef __SYMBIAN32__
   485 	if(__pos < _Nb)
   486 	{
   487     	this->_M_do_right_shift(__pos);
   488     	this->_M_do_sanitize();
   489 	}
   490 	else
   491 		this->_M_do_reset();
   492 #else
   493 	this->_M_do_right_shift(__pos);
   494     this->_M_do_sanitize();
   495 #endif
   496 
   497     return *this;
   498   }
   499 
   500   //
   501   // Extension:
   502   // Versions of single-bit set, reset, flip, test with no range checking.
   503   //
   504 
   505   bitset<_Nb>& _Unchecked_set(size_t __pos) {
   506     this->_M_getword(__pos) |= _Base_bitset<_Words > ::_S_maskbit(__pos);
   507     return *this;
   508   }
   509 
   510   bitset<_Nb>& _Unchecked_set(size_t __pos, int __val) {
   511     if (__val)
   512       this->_M_getword(__pos) |= this->_S_maskbit(__pos);
   513     else
   514       this->_M_getword(__pos) &= ~ this->_S_maskbit(__pos);
   515 
   516     return *this;
   517   }
   518 
   519   bitset<_Nb>& _Unchecked_reset(size_t __pos) {
   520     this->_M_getword(__pos) &= ~ this->_S_maskbit(__pos);
   521     return *this;
   522   }
   523 
   524   bitset<_Nb>& _Unchecked_flip(size_t __pos) {
   525     this->_M_getword(__pos) ^= this->_S_maskbit(__pos);
   526     return *this;
   527   }
   528 
   529   bool _Unchecked_test(size_t __pos) const {
   530     return (this->_M_getword(__pos) & this->_S_maskbit(__pos)) != __STATIC_CAST(_WordT,0);
   531   }
   532 
   533   // Set, reset, and flip.
   534 
   535   bitset<_Nb>& set() {
   536     this->_M_do_set();
   537     this->_M_do_sanitize();
   538     return *this;
   539   }
   540 
   541   bitset<_Nb>& set(size_t __pos) {
   542     if (__pos >= _Nb)
   543       __stl_throw_out_of_range("bitset");
   544     return _Unchecked_set(__pos);
   545   }
   546 
   547   bitset<_Nb>& set(size_t __pos, int __val) {
   548     if (__pos >= _Nb)
   549       __stl_throw_out_of_range("bitset");
   550     return _Unchecked_set(__pos, __val);
   551   }
   552 
   553   bitset<_Nb>& reset() {
   554     this->_M_do_reset();
   555     return *this;
   556   }
   557 
   558   bitset<_Nb>& reset(size_t __pos) {
   559     if (__pos >= _Nb)
   560       __stl_throw_out_of_range("bitset");
   561 
   562     return _Unchecked_reset(__pos);
   563   }
   564 
   565   bitset<_Nb>& flip() {
   566     this->_M_do_flip();
   567     this->_M_do_sanitize();
   568     return *this;
   569   }
   570 
   571   bitset<_Nb>& flip(size_t __pos) {
   572     if (__pos >= _Nb)
   573       __stl_throw_out_of_range("bitset");
   574 
   575     return _Unchecked_flip(__pos);
   576   }
   577 
   578   bitset<_Nb> operator~() const { 
   579     return bitset<_Nb>(*this).flip();
   580   }
   581 
   582   // element access:
   583   //for b[i];
   584   reference operator[](size_t __pos) { return reference(*this,__pos); }
   585   bool operator[](size_t __pos) const { return _Unchecked_test(__pos); }
   586 
   587   unsigned long to_ulong() const { return this->_M_do_to_ulong(); }
   588 
   589 #if defined (_STLP_MEMBER_TEMPLATES) && !  defined (_STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS)
   590   template <class _CharT, class _Traits, class _Alloc>
   591   basic_string<_CharT, _Traits, _Alloc> to_string() const {
   592     basic_string<_CharT, _Traits, _Alloc> __result;
   593     _M_copy_to_string(__result);
   594     return __result;
   595   }
   596 #else
   597   string to_string() const {
   598     string __result;
   599     _M_copy_to_string(__result);
   600     return __result;
   601   }
   602 #endif /* _STLP_EXPLICIT_FUNCTION_TMPL_ARGS */
   603 
   604   size_t count() const { return this->_M_do_count(); }
   605 
   606   size_t size() const { return _Nb; }
   607 
   608   bool operator==(const bitset<_Nb>& __rhs) const {
   609     return this->_M_is_equal(__rhs);
   610   }
   611   bool operator!=(const bitset<_Nb>& __rhs) const {
   612     return !this->_M_is_equal(__rhs);
   613   }
   614 
   615   bool test(size_t __pos) const {
   616     if (__pos >= _Nb)
   617       __stl_throw_out_of_range("bitset");
   618     
   619     return _Unchecked_test(__pos);
   620   }
   621 
   622   bool any() const { return this->_M_is_any(); }
   623   bool none() const { return !this->_M_is_any(); }
   624 
   625   bitset<_Nb> operator<<(size_t __pos) const { 
   626     bitset<_Nb> __result(*this);
   627     __result <<= __pos ;  return __result; 
   628   }
   629   bitset<_Nb> operator>>(size_t __pos) const { 
   630     bitset<_Nb> __result(*this);
   631     __result >>= __pos ;  return __result; 
   632   }
   633 
   634   //
   635   // EXTENSIONS: bit-find operations.  These operations are
   636   // experimental, and are subject to change or removal in future
   637   // versions.
   638   // 
   639 
   640   // find the index of the first "on" bit
   641   size_t _Find_first() const 
   642     { return this->_M_do_find_first(_Nb); }
   643 
   644   // find the index of the next "on" bit after prev
   645   size_t _Find_next( size_t __prev ) const 
   646     { return this->_M_do_find_next(__prev, _Nb); }
   647 
   648 //
   649 // Definitions of should-be non-inline member functions.
   650 //
   651 # if defined (_STLP_MEMBER_TEMPLATES)
   652   template<class _CharT, class _Traits, class _Alloc>
   653     void _M_copy_from_string(const basic_string<_CharT,_Traits,_Alloc>& __s,
   654 			     size_t __pos,
   655 			     size_t __n) {
   656 #else
   657     void _M_copy_from_string(const string& __s,
   658 			     size_t __pos,
   659 			     size_t __n) {
   660       typedef char_traits<char> _Traits;
   661 #endif
   662       reset();
   663       size_t __tmp = _Nb;
   664       const size_t __Nbits = (min) (__tmp, (min) (__n, __s.size() - __pos));
   665       for ( size_t __i= 0; __i < __Nbits; ++__i) {
   666         typename _Traits::int_type __k = _Traits::to_int_type(__s[__pos + __Nbits - __i - 1]);
   667         // boris : widen() ?
   668         if (__k == '1')
   669           set(__i);
   670         else if (__k !='0')
   671           __stl_throw_invalid_argument("bitset");
   672       }
   673     }
   674   
   675 # if defined (_STLP_MEMBER_TEMPLATES)
   676   template <class _CharT, class _Traits, class _Alloc>
   677     void _M_copy_to_string(basic_string<_CharT, _Traits, _Alloc>& __s) const
   678 # else
   679     void _M_copy_to_string(string& __s) const
   680 # endif
   681     {
   682       __s.assign(_Nb, '0');
   683       
   684       for (size_t __i = 0; __i < _Nb; ++__i) 
   685 	if (_Unchecked_test(__i))
   686 	  __s[_Nb - 1 - __i] = '1';
   687     }
   688 
   689 # if defined (_STLP_NON_TYPE_TMPL_PARAM_BUG)
   690   bitset<_Nb> operator&(const bitset<_Nb>& __y) const {
   691     bitset<_Nb> __result(*this);
   692     __result &= __y;
   693     return __result;
   694   }
   695   bitset<_Nb> operator|(const bitset<_Nb>& __y) const {
   696     bitset<_Nb> __result(*this);
   697     __result |= __y;
   698     return __result;
   699   }
   700   bitset<_Nb> operator^(const bitset<_Nb>& __y) const {
   701     bitset<_Nb> __result(*this);
   702     __result ^= __y;
   703     return __result;
   704   }
   705 # endif 
   706 
   707 };
   708 
   709 // ------------------------------------------------------------
   710 //
   711 // 23.3.5.3 bitset operations:
   712 //
   713 
   714 # if ! defined (_STLP_NON_TYPE_TMPL_PARAM_BUG)
   715 
   716 template <size_t _Nb>
   717 inline bitset<_Nb>  _STLP_CALL
   718 operator&(const bitset<_Nb>& __x,
   719           const bitset<_Nb>& __y) {
   720   bitset<_Nb> __result(__x);
   721   __result &= __y;
   722   return __result;
   723 }
   724 
   725 
   726 template <size_t _Nb>
   727 inline bitset<_Nb>  _STLP_CALL
   728 operator|(const bitset<_Nb>& __x,
   729           const bitset<_Nb>& __y) {
   730   bitset<_Nb> __result(__x);
   731   __result |= __y;
   732   return __result;
   733 }
   734 
   735 template <size_t _Nb>
   736 inline bitset<_Nb>  _STLP_CALL
   737 operator^(const bitset<_Nb>& __x,
   738           const bitset<_Nb>& __y) {
   739   bitset<_Nb> __result(__x);
   740   __result ^= __y;
   741   return __result;
   742 }
   743 
   744 #if defined ( _STLP_USE_NEW_IOSTREAMS )
   745 
   746 template <class _CharT, class _Traits, size_t _Nb>
   747 basic_istream<_CharT, _Traits>&  _STLP_CALL
   748 operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Nb>& __x);
   749 
   750 
   751 template <class _CharT, class _Traits, size_t _Nb>
   752 basic_ostream<_CharT, _Traits>& _STLP_CALL
   753 operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Nb>& __x);
   754 
   755 #elif ! defined ( _STLP_USE_NO_IOSTREAMS )
   756 
   757 // (reg) For Watcom IO, this tells if ostream class is in .exe or in .dll
   758 template <size_t _Nb>
   759 _ISTREAM_DLL& _STLP_CALL
   760 operator>>(_ISTREAM_DLL& __is, bitset<_Nb>& __x);
   761 
   762 template <size_t _Nb>
   763 inline _OSTREAM_DLL&  _STLP_CALL operator<<(_OSTREAM_DLL& __os, const bitset<_Nb>& __x) {
   764   string __tmp;
   765   __x._M_copy_to_string(__tmp);
   766   return __os << __tmp;
   767 }
   768 
   769 #endif
   770 
   771 # endif /* _STLP_NON_TYPE_TMPL_PARAM_BUG */
   772 
   773 #  undef  bitset
   774 
   775 
   776 _STLP_END_NAMESPACE
   777 
   778 #  undef __BITS_PER_WORD
   779 #  undef __BITSET_WORDS
   780 
   781 # if !defined (_STLP_LINK_TIME_INSTANTIATION)
   782 #  include <stl/_bitset.c>
   783 # endif
   784 
   785 #endif /* _STLP_BITSET_H */
   786 
   787 
   788 // Local Variables:
   789 // mode:C++
   790 // End:
   791