epoc32/include/stdapis/stlportv5/stl/_bitset.h
branchSymbian2
changeset 3 e1b950c65cb4
parent 2 2fe1408b6811
child 4 837f303aceeb
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/epoc32/include/stdapis/stlportv5/stl/_bitset.h	Wed Mar 31 12:27:01 2010 +0100
     1.3 @@ -0,0 +1,791 @@
     1.4 +/*
     1.5 + * © Portions copyright (c) 2006-2007 Nokia Corporation.  All rights reserved.
     1.6 + * Copyright (c) 1998
     1.7 + * Silicon Graphics Computer Systems, Inc.
     1.8 + *
     1.9 + * Copyright (c) 1999 
    1.10 + * Boris Fomitchev
    1.11 + *
    1.12 + * This material is provided "as is", with absolutely no warranty expressed
    1.13 + * or implied. Any use is at your own risk.
    1.14 + *
    1.15 + * Permission to use or copy this software for any purpose is hereby granted 
    1.16 + * without fee, provided the above notices are retained on all copies.
    1.17 + * Permission to modify the code and to distribute modified code is granted,
    1.18 + * provided the above notices are retained, and a notice that the code was
    1.19 + * modified is included with the above copyright notice.
    1.20 + *
    1.21 + */
    1.22 +
    1.23 +#ifndef _STLP_BITSET_H
    1.24 +#define _STLP_BITSET_H
    1.25 +
    1.26 +// A bitset of size N has N % (sizeof(unsigned long) * CHAR_BIT) unused 
    1.27 +// bits.  (They are the high- order bits in the highest word.)  It is
    1.28 +// a class invariant of class bitset<> that those unused bits are
    1.29 +// always zero.
    1.30 +
    1.31 +// Most of the actual code isn't contained in bitset<> itself, but in the 
    1.32 +// base class _Base_bitset.  The base class works with whole words, not with
    1.33 +// individual bits.  This allows us to specialize _Base_bitset for the
    1.34 +// important special case where the bitset is only a single word.
    1.35 +
    1.36 +// The C++ standard does not define the precise semantics of operator[].
    1.37 +// In this implementation the const version of operator[] is equivalent
    1.38 +// to test(), except that it does no range checking.  The non-const version
    1.39 +// returns a reference to a bit, again without doing any range checking.
    1.40 +
    1.41 +
    1.42 +# ifndef _STLP_INTERNAL_ALGOBASE_H
    1.43 +#  include <stl/_algobase.h>
    1.44 +# endif
    1.45 +
    1.46 +# ifndef _STLP_INTERNAL_ALLOC_H
    1.47 +#  include <stl/_alloc.h>
    1.48 +# endif
    1.49 +
    1.50 +# ifndef _STLP_INTERNAL_ITERATOR_H
    1.51 +#  include <stl/_iterator.h>
    1.52 +# endif
    1.53 +
    1.54 +# ifndef _STLP_INTERNAL_UNINITIALIZED_H
    1.55 +#  include <stl/_uninitialized.h>
    1.56 +# endif
    1.57 +
    1.58 +# ifndef _STLP_RANGE_ERRORS_H
    1.59 +#  include <stl/_range_errors.h>
    1.60 +# endif
    1.61 +
    1.62 +# ifndef _STLP_STRING
    1.63 +#  include <string>
    1.64 +# endif
    1.65 +
    1.66 +# ifndef _STLP_ISTREAM
    1.67 +#  include <istream>
    1.68 +# endif
    1.69 +
    1.70 +#define __BITS_PER_WORD (CHAR_BIT*sizeof(unsigned long))
    1.71 +#define __BITSET_WORDS(__n) ((__n + __BITS_PER_WORD - 1)/__BITS_PER_WORD)
    1.72 +
    1.73 +_STLP_BEGIN_NAMESPACE
    1.74 +
    1.75 +// structure to aid in counting bits
    1.76 +template<class _Dummy> 
    1.77 +class _Bs_G {
    1.78 +public:
    1.79 +  static const unsigned char _S_bit_count[256];
    1.80 +  // Mapping from 8 bit unsigned integers to the index of the first one
    1.81 +  // bit:
    1.82 +  static const unsigned char _S_first_one[256];
    1.83 +};
    1.84 +
    1.85 +//
    1.86 +// Base class: general case.
    1.87 +//
    1.88 +
    1.89 +template<size_t _Nw>
    1.90 +struct _Base_bitset {
    1.91 +  typedef unsigned long _WordT;
    1.92 +
    1.93 +  _WordT _M_w[_Nw];                // 0 is the least significant word.
    1.94 +
    1.95 +  _Base_bitset( void ) { _M_do_reset(); }
    1.96 +
    1.97 +  _Base_bitset(unsigned long __val) {
    1.98 +    _M_do_reset();
    1.99 +    _M_w[0] = __val;
   1.100 +  }
   1.101 +  
   1.102 +  static size_t _STLP_CALL _S_whichword( size_t __pos ) {
   1.103 +    return __pos / __BITS_PER_WORD;
   1.104 +  }
   1.105 +  static size_t _STLP_CALL _S_whichbyte( size_t __pos ) {
   1.106 +    return (__pos % __BITS_PER_WORD) / CHAR_BIT;
   1.107 +  }
   1.108 +  static size_t _STLP_CALL _S_whichbit( size_t __pos ) {
   1.109 +    return __pos % __BITS_PER_WORD;
   1.110 +  }
   1.111 +  static _WordT _STLP_CALL _S_maskbit( size_t __pos ) {
   1.112 +    return __STATIC_CAST(_WordT,1) << _S_whichbit(__pos);
   1.113 +  }
   1.114 +
   1.115 +  _WordT& _M_getword(size_t __pos)       { return _M_w[_S_whichword(__pos)]; }
   1.116 +  _WordT  _M_getword(size_t __pos) const { return _M_w[_S_whichword(__pos)]; }
   1.117 +
   1.118 +  _WordT& _M_hiword()       { return _M_w[_Nw - 1]; }
   1.119 +  _WordT  _M_hiword() const { return _M_w[_Nw - 1]; }
   1.120 +
   1.121 +  void _M_do_and(const _Base_bitset<_Nw>& __x) {
   1.122 +    for ( size_t __i = 0; __i < _Nw; __i++ ) {
   1.123 +      _M_w[__i] &= __x._M_w[__i];
   1.124 +    }
   1.125 +  }
   1.126 +
   1.127 +  void _M_do_or(const _Base_bitset<_Nw>& __x) {
   1.128 +    for ( size_t __i = 0; __i < _Nw; __i++ ) {
   1.129 +      _M_w[__i] |= __x._M_w[__i];
   1.130 +    }
   1.131 +  }
   1.132 +
   1.133 +  void _M_do_xor(const _Base_bitset<_Nw>& __x) {
   1.134 +    for ( size_t __i = 0; __i < _Nw; __i++ ) {
   1.135 +      _M_w[__i] ^= __x._M_w[__i];
   1.136 +    }
   1.137 +  }
   1.138 +
   1.139 +  void _M_do_left_shift(size_t __shift);
   1.140 +
   1.141 +  void _M_do_right_shift(size_t __shift);
   1.142 +
   1.143 +  void _M_do_flip() {
   1.144 +    for ( size_t __i = 0; __i < _Nw; __i++ ) {
   1.145 +      _M_w[__i] = ~_M_w[__i];
   1.146 +    }
   1.147 +  }
   1.148 +
   1.149 +  void _M_do_set() {
   1.150 +    for ( size_t __i = 0; __i < _Nw; __i++ ) {
   1.151 +      _M_w[__i] = ~__STATIC_CAST(_WordT,0);
   1.152 +    }
   1.153 +  }
   1.154 +
   1.155 +
   1.156 +  void _M_do_reset() { memset(_M_w, 0, _Nw * sizeof(_WordT)); }
   1.157 +
   1.158 +  bool _M_is_equal(const _Base_bitset<_Nw>& __x) const {
   1.159 +    for (size_t __i = 0; __i < _Nw; ++__i) {
   1.160 +      if (_M_w[__i] != __x._M_w[__i])
   1.161 +        return false;
   1.162 +    }
   1.163 +    return true;
   1.164 +  }
   1.165 +
   1.166 +  bool _M_is_any() const {
   1.167 +    for ( size_t __i = 0; __i < _Nw ; __i++ ) {
   1.168 +      if ( _M_w[__i] != __STATIC_CAST(_WordT,0) )
   1.169 +        return true;
   1.170 +    }
   1.171 +    return false;
   1.172 +  }
   1.173 +
   1.174 +  size_t _M_do_count() const {
   1.175 +    size_t __result = 0;
   1.176 +    const unsigned char* __byte_ptr = (const unsigned char*)_M_w;
   1.177 +    const unsigned char* __end_ptr = (const unsigned char*)(_M_w+_Nw);
   1.178 +
   1.179 +    while ( __byte_ptr < __end_ptr ) {
   1.180 +      __result += _Bs_G<bool>::_S_bit_count[*__byte_ptr];
   1.181 +      __byte_ptr++;
   1.182 +    }
   1.183 +    return __result;
   1.184 +  }
   1.185 +
   1.186 +  unsigned long _M_do_to_ulong() const; 
   1.187 +
   1.188 +  // find first "on" bit
   1.189 +  size_t _M_do_find_first(size_t __not_found) const;
   1.190 +
   1.191 +  // find the next "on" bit that follows "prev"
   1.192 +  size_t _M_do_find_next(size_t __prev, size_t __not_found) const;
   1.193 +};
   1.194 +
   1.195 +//
   1.196 +// Base class: specialization for a single word.
   1.197 +//
   1.198 +
   1.199 +_STLP_TEMPLATE_NULL
   1.200 +struct _Base_bitset<1UL> {
   1.201 +  typedef unsigned long _WordT;
   1.202 +  typedef _Base_bitset<1UL> _Self;
   1.203 +
   1.204 +  _WordT _M_w;
   1.205 +
   1.206 +  _Base_bitset( void ) : _M_w(0) {}
   1.207 +  _Base_bitset(unsigned long __val) : _M_w(__val) {}
   1.208 +  
   1.209 +  static size_t _STLP_CALL _S_whichword( size_t __pos ) {
   1.210 +    return __pos / __BITS_PER_WORD ;
   1.211 +  }
   1.212 +  static size_t _STLP_CALL _S_whichbyte( size_t __pos ) {
   1.213 +    return (__pos % __BITS_PER_WORD) / CHAR_BIT;
   1.214 +  }
   1.215 +  static size_t _STLP_CALL _S_whichbit( size_t __pos ) {
   1.216 +    return __pos % __BITS_PER_WORD;
   1.217 +  }
   1.218 +  static _WordT _STLP_CALL _S_maskbit( size_t __pos ) {
   1.219 +    return (__STATIC_CAST(_WordT,1)) << _S_whichbit(__pos);
   1.220 +  }
   1.221 +
   1.222 +  _WordT& _M_getword(size_t)       { return _M_w; }
   1.223 +  _WordT  _M_getword(size_t) const { return _M_w; }
   1.224 +
   1.225 +  _WordT& _M_hiword()       { return _M_w; }
   1.226 +  _WordT  _M_hiword() const { return _M_w; }
   1.227 +
   1.228 +
   1.229 +  void _M_do_and(const _Self& __x) { _M_w &= __x._M_w; }
   1.230 +  void _M_do_or(const _Self& __x)  { _M_w |= __x._M_w; }
   1.231 +  void _M_do_xor(const _Self& __x) { _M_w ^= __x._M_w; }
   1.232 +  void _M_do_left_shift(size_t __shift)     { _M_w <<= __shift; }
   1.233 +  void _M_do_right_shift(size_t __shift)    { _M_w >>= __shift; }
   1.234 +  void _M_do_flip()                       { _M_w = ~_M_w; }
   1.235 +  void _M_do_set()                        { _M_w = ~__STATIC_CAST(_WordT,0); }
   1.236 +  void _M_do_reset()                      { _M_w = 0; }
   1.237 +
   1.238 +  bool _M_is_equal(const _Self& __x) const {
   1.239 +    return _M_w == __x._M_w;
   1.240 +  }
   1.241 +  bool _M_is_any() const {
   1.242 +    return _M_w != 0;
   1.243 +  }
   1.244 +
   1.245 +  size_t _M_do_count() const {
   1.246 +    size_t __result = 0;
   1.247 +    const unsigned char* __byte_ptr = (const unsigned char*)&_M_w;
   1.248 +    const unsigned char* __end_ptr = ((const unsigned char*)&_M_w)+sizeof(_M_w);
   1.249 +    while ( __byte_ptr < __end_ptr ) {
   1.250 +      __result += _Bs_G<bool>::_S_bit_count[*__byte_ptr];
   1.251 +      __byte_ptr++;
   1.252 +    }
   1.253 +    return __result;
   1.254 +  }
   1.255 +
   1.256 +  unsigned long _M_do_to_ulong() const { return _M_w; }
   1.257 +
   1.258 +  inline size_t _M_do_find_first(size_t __not_found) const;
   1.259 +
   1.260 +  // find the next "on" bit that follows "prev"
   1.261 +  inline size_t _M_do_find_next(size_t __prev, size_t __not_found) const; 
   1.262 +
   1.263 +};
   1.264 +
   1.265 +
   1.266 +// ------------------------------------------------------------
   1.267 +//
   1.268 +// Definitions of should-be-non-inline functions from the single-word version of
   1.269 +//  _Base_bitset.
   1.270 +//
   1.271 +
   1.272 +inline size_t 
   1.273 +_Base_bitset<1UL>::_M_do_find_first(size_t __not_found) const
   1.274 +{
   1.275 +  //  typedef unsigned long _WordT;
   1.276 +  _WordT __thisword = _M_w;
   1.277 +
   1.278 +  if ( __thisword != __STATIC_CAST(_WordT,0) ) {
   1.279 +    // find byte within word
   1.280 +    for ( size_t __j = 0; __j < sizeof(_WordT); __j++ ) {
   1.281 +      unsigned char __this_byte
   1.282 +        = __STATIC_CAST(unsigned char,(__thisword & (~(unsigned char)0)));
   1.283 +      if ( __this_byte )
   1.284 +        return __j*CHAR_BIT + _Bs_G<bool>::_S_first_one[__this_byte];
   1.285 +
   1.286 +      __thisword >>= CHAR_BIT;
   1.287 +    }
   1.288 +  }
   1.289 +  // not found, so return a value that indicates failure.
   1.290 +  return __not_found;
   1.291 +}
   1.292 +
   1.293 +inline size_t 
   1.294 +_Base_bitset<1UL>::_M_do_find_next(size_t __prev, 
   1.295 +                                   size_t __not_found ) const
   1.296 +{
   1.297 +  // make bound inclusive
   1.298 +  ++__prev;
   1.299 +
   1.300 +  // check out of bounds
   1.301 +  if ( __prev >= __BITS_PER_WORD )
   1.302 +    return __not_found;
   1.303 +
   1.304 +    // search first (and only) word
   1.305 +  _WordT __thisword = _M_w;
   1.306 +
   1.307 +  // mask off bits below bound
   1.308 +  __thisword &= (~__STATIC_CAST(_WordT,0)) << _S_whichbit(__prev);
   1.309 +
   1.310 +  if ( __thisword != __STATIC_CAST(_WordT,0) ) {
   1.311 +    // find byte within word
   1.312 +    // get first byte into place
   1.313 +    __thisword >>= _S_whichbyte(__prev) * CHAR_BIT;
   1.314 +    for ( size_t __j = _S_whichbyte(__prev); __j < sizeof(_WordT); __j++ ) {
   1.315 +      unsigned char __this_byte
   1.316 +        = __STATIC_CAST(unsigned char,(__thisword & (~(unsigned char)0)));
   1.317 +      if ( __this_byte )
   1.318 +        return __j*CHAR_BIT + _Bs_G<bool>::_S_first_one[__this_byte];
   1.319 +
   1.320 +      __thisword >>= CHAR_BIT;
   1.321 +    }
   1.322 +  }
   1.323 +
   1.324 +  // not found, so return a value that indicates failure.
   1.325 +  return __not_found;
   1.326 +} // end _M_do_find_next
   1.327 +
   1.328 +
   1.329 +// ------------------------------------------------------------
   1.330 +// Helper class to zero out the unused high-order bits in the highest word.
   1.331 +
   1.332 +template <size_t _Extrabits> struct _Sanitize {
   1.333 +  static void _STLP_CALL _M_do_sanitize(unsigned long& __val)
   1.334 +    { __val &= ~((~__STATIC_CAST(unsigned long,0)) << _Extrabits); }
   1.335 +};
   1.336 +
   1.337 +_STLP_TEMPLATE_NULL struct _Sanitize<0UL> {
   1.338 +  static void _STLP_CALL _M_do_sanitize(unsigned long) {}
   1.339 +};
   1.340 +
   1.341 +// ------------------------------------------------------------
   1.342 +// Class bitset.
   1.343 +//   _Nb may be any nonzero number of type size_t.
   1.344 +
   1.345 +
   1.346 +template<size_t _Nb>
   1.347 +class bitset : public _Base_bitset<__BITSET_WORDS(_Nb) > 
   1.348 +{
   1.349 +public:
   1.350 +  enum { _Words = __BITSET_WORDS(_Nb) } ;
   1.351 +
   1.352 +private:
   1.353 +  typedef _Base_bitset< _Words > _Base;
   1.354 +
   1.355 +  void _M_do_sanitize() {
   1.356 +    _Sanitize<_Nb%__BITS_PER_WORD >::_M_do_sanitize(this->_M_hiword());
   1.357 +  }
   1.358 +public:
   1.359 +  typedef unsigned long _WordT;
   1.360 +  struct reference;
   1.361 +  friend struct reference;
   1.362 +
   1.363 +  // bit reference:
   1.364 +  struct reference {
   1.365 +  typedef _Base_bitset<_Words > _Bitset_base;
   1.366 +  typedef bitset<_Nb> _Bitset;
   1.367 +    //    friend _Bitset;
   1.368 +    _WordT *_M_wp;
   1.369 +    size_t _M_bpos;
   1.370 +
   1.371 +    // should be left undefined
   1.372 +    reference() {}
   1.373 +
   1.374 +    reference( _Bitset& __b, size_t __pos ) {
   1.375 +      _M_wp = &__b._M_getword(__pos);
   1.376 +      _M_bpos = _Bitset_base::_S_whichbit(__pos);
   1.377 +    }
   1.378 +
   1.379 +  public:
   1.380 +    ~reference() {}
   1.381 +
   1.382 +    // for b[i] = __x;
   1.383 +    reference& operator=(bool __x) {
   1.384 +      if ( __x )
   1.385 +        *_M_wp |= _Bitset_base::_S_maskbit(_M_bpos);
   1.386 +      else
   1.387 +        *_M_wp &= ~_Bitset_base::_S_maskbit(_M_bpos);
   1.388 +
   1.389 +      return *this;
   1.390 +    }
   1.391 +
   1.392 +    // for b[i] = b[__j];
   1.393 +    reference& operator=(const reference& __j) {
   1.394 +      if ( (*(__j._M_wp) & _Bitset_base::_S_maskbit(__j._M_bpos)) )
   1.395 +        *_M_wp |= _Bitset_base::_S_maskbit(_M_bpos);
   1.396 +      else
   1.397 +        *_M_wp &= ~_Bitset_base::_S_maskbit(_M_bpos);
   1.398 +
   1.399 +      return *this;
   1.400 +    }
   1.401 +
   1.402 +    // flips the bit
   1.403 +    bool operator~() const { return (*(_M_wp) & _Bitset_base::_S_maskbit(_M_bpos)) == 0; }
   1.404 +
   1.405 +    // for __x = b[i];
   1.406 +    operator bool() const { return (*(_M_wp) & _Bitset_base::_S_maskbit(_M_bpos)) != 0; }
   1.407 +
   1.408 +    // for b[i].flip();
   1.409 +    reference& flip() {
   1.410 +      *_M_wp ^= _Bitset_base::_S_maskbit(_M_bpos);
   1.411 +      return *this;
   1.412 +    }
   1.413 +  };
   1.414 +
   1.415 +  // 23.3.5.1 constructors:
   1.416 +  bitset() {}
   1.417 +
   1.418 +  bitset(unsigned long __val) : _Base_bitset<_Words>(__val) { _M_do_sanitize(); }
   1.419 +
   1.420 +# ifdef _STLP_MEMBER_TEMPLATES
   1.421 +  template<class _CharT, class _Traits, class _Alloc>
   1.422 +  explicit bitset(const basic_string<_CharT,_Traits,_Alloc>& __s,
   1.423 +                  size_t __pos = 0)
   1.424 +    : _Base_bitset<_Words >() 
   1.425 +  {
   1.426 +    if (__pos > __s.size()) 
   1.427 +      __stl_throw_out_of_range("bitset");
   1.428 +    _M_copy_from_string(__s, __pos,
   1.429 +                        basic_string<_CharT, _Traits, _Alloc>::npos);
   1.430 +  }
   1.431 +  template<class _CharT, class _Traits, class _Alloc>
   1.432 +  bitset(const basic_string<_CharT, _Traits, _Alloc>& __s,
   1.433 +          size_t __pos,
   1.434 +          size_t __n)
   1.435 +  : _Base_bitset<_Words >() 
   1.436 +  {
   1.437 +    if (__pos > __s.size()) 
   1.438 +      __stl_throw_out_of_range("bitset");
   1.439 +    _M_copy_from_string(__s, __pos, __n);
   1.440 +  }
   1.441 +#else /* _STLP_MEMBER_TEMPLATES */
   1.442 +  explicit bitset(const string& __s,
   1.443 +                  size_t __pos = 0,
   1.444 +                  size_t __n = (size_t)-1) 
   1.445 +    : _Base_bitset<_Words >() 
   1.446 +  {
   1.447 +    if (__pos > __s.size()) 
   1.448 +      __stl_throw_out_of_range("bitset");
   1.449 +    _M_copy_from_string(__s, __pos, __n);
   1.450 +  }
   1.451 +#endif /* _STLP_MEMBER_TEMPLATES */
   1.452 +
   1.453 +  // 23.3.5.2 bitset operations:
   1.454 +  bitset<_Nb>& operator&=(const bitset<_Nb>& __rhs) {
   1.455 +    this->_M_do_and(__rhs);
   1.456 +    return *this;
   1.457 +  }
   1.458 +
   1.459 +  bitset<_Nb>& operator|=(const bitset<_Nb>& __rhs) {
   1.460 +    this->_M_do_or(__rhs);
   1.461 +    return *this;
   1.462 +  }
   1.463 +
   1.464 +  bitset<_Nb>& operator^=(const bitset<_Nb>& __rhs) {
   1.465 +    this->_M_do_xor(__rhs);
   1.466 +    return *this;
   1.467 +  }
   1.468 +
   1.469 +  bitset<_Nb>& operator<<=(size_t __pos) {
   1.470 +#ifdef __SYMBIAN32__
   1.471 +	if(__pos < _Nb)
   1.472 +	{
   1.473 +    	this->_M_do_left_shift(__pos);
   1.474 +    	this->_M_do_sanitize();
   1.475 +	}
   1.476 +	else
   1.477 +		this->_M_do_reset();
   1.478 +#else
   1.479 +	this->_M_do_left_shift(__pos);
   1.480 +	this->_M_do_sanitize();
   1.481 +#endif
   1.482 +
   1.483 +    return *this;
   1.484 +  }
   1.485 +
   1.486 +  bitset<_Nb>& operator>>=(size_t __pos) {
   1.487 +#ifdef __SYMBIAN32__
   1.488 +	if(__pos < _Nb)
   1.489 +	{
   1.490 +    	this->_M_do_right_shift(__pos);
   1.491 +    	this->_M_do_sanitize();
   1.492 +	}
   1.493 +	else
   1.494 +		this->_M_do_reset();
   1.495 +#else
   1.496 +	this->_M_do_right_shift(__pos);
   1.497 +    this->_M_do_sanitize();
   1.498 +#endif
   1.499 +
   1.500 +    return *this;
   1.501 +  }
   1.502 +
   1.503 +  //
   1.504 +  // Extension:
   1.505 +  // Versions of single-bit set, reset, flip, test with no range checking.
   1.506 +  //
   1.507 +
   1.508 +  bitset<_Nb>& _Unchecked_set(size_t __pos) {
   1.509 +    this->_M_getword(__pos) |= _Base_bitset<_Words > ::_S_maskbit(__pos);
   1.510 +    return *this;
   1.511 +  }
   1.512 +
   1.513 +  bitset<_Nb>& _Unchecked_set(size_t __pos, int __val) {
   1.514 +    if (__val)
   1.515 +      this->_M_getword(__pos) |= this->_S_maskbit(__pos);
   1.516 +    else
   1.517 +      this->_M_getword(__pos) &= ~ this->_S_maskbit(__pos);
   1.518 +
   1.519 +    return *this;
   1.520 +  }
   1.521 +
   1.522 +  bitset<_Nb>& _Unchecked_reset(size_t __pos) {
   1.523 +    this->_M_getword(__pos) &= ~ this->_S_maskbit(__pos);
   1.524 +    return *this;
   1.525 +  }
   1.526 +
   1.527 +  bitset<_Nb>& _Unchecked_flip(size_t __pos) {
   1.528 +    this->_M_getword(__pos) ^= this->_S_maskbit(__pos);
   1.529 +    return *this;
   1.530 +  }
   1.531 +
   1.532 +  bool _Unchecked_test(size_t __pos) const {
   1.533 +    return (this->_M_getword(__pos) & this->_S_maskbit(__pos)) != __STATIC_CAST(_WordT,0);
   1.534 +  }
   1.535 +
   1.536 +  // Set, reset, and flip.
   1.537 +
   1.538 +  bitset<_Nb>& set() {
   1.539 +    this->_M_do_set();
   1.540 +    this->_M_do_sanitize();
   1.541 +    return *this;
   1.542 +  }
   1.543 +
   1.544 +  bitset<_Nb>& set(size_t __pos) {
   1.545 +    if (__pos >= _Nb)
   1.546 +      __stl_throw_out_of_range("bitset");
   1.547 +    return _Unchecked_set(__pos);
   1.548 +  }
   1.549 +
   1.550 +  bitset<_Nb>& set(size_t __pos, int __val) {
   1.551 +    if (__pos >= _Nb)
   1.552 +      __stl_throw_out_of_range("bitset");
   1.553 +    return _Unchecked_set(__pos, __val);
   1.554 +  }
   1.555 +
   1.556 +  bitset<_Nb>& reset() {
   1.557 +    this->_M_do_reset();
   1.558 +    return *this;
   1.559 +  }
   1.560 +
   1.561 +  bitset<_Nb>& reset(size_t __pos) {
   1.562 +    if (__pos >= _Nb)
   1.563 +      __stl_throw_out_of_range("bitset");
   1.564 +
   1.565 +    return _Unchecked_reset(__pos);
   1.566 +  }
   1.567 +
   1.568 +  bitset<_Nb>& flip() {
   1.569 +    this->_M_do_flip();
   1.570 +    this->_M_do_sanitize();
   1.571 +    return *this;
   1.572 +  }
   1.573 +
   1.574 +  bitset<_Nb>& flip(size_t __pos) {
   1.575 +    if (__pos >= _Nb)
   1.576 +      __stl_throw_out_of_range("bitset");
   1.577 +
   1.578 +    return _Unchecked_flip(__pos);
   1.579 +  }
   1.580 +
   1.581 +  bitset<_Nb> operator~() const { 
   1.582 +    return bitset<_Nb>(*this).flip();
   1.583 +  }
   1.584 +
   1.585 +  // element access:
   1.586 +  //for b[i];
   1.587 +  reference operator[](size_t __pos) { return reference(*this,__pos); }
   1.588 +  bool operator[](size_t __pos) const { return _Unchecked_test(__pos); }
   1.589 +
   1.590 +  unsigned long to_ulong() const { return this->_M_do_to_ulong(); }
   1.591 +
   1.592 +#if defined (_STLP_MEMBER_TEMPLATES) && !  defined (_STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS)
   1.593 +  template <class _CharT, class _Traits, class _Alloc>
   1.594 +  basic_string<_CharT, _Traits, _Alloc> to_string() const {
   1.595 +    basic_string<_CharT, _Traits, _Alloc> __result;
   1.596 +    _M_copy_to_string(__result);
   1.597 +    return __result;
   1.598 +  }
   1.599 +#else
   1.600 +  string to_string() const {
   1.601 +    string __result;
   1.602 +    _M_copy_to_string(__result);
   1.603 +    return __result;
   1.604 +  }
   1.605 +#endif /* _STLP_EXPLICIT_FUNCTION_TMPL_ARGS */
   1.606 +
   1.607 +  size_t count() const { return this->_M_do_count(); }
   1.608 +
   1.609 +  size_t size() const { return _Nb; }
   1.610 +
   1.611 +  bool operator==(const bitset<_Nb>& __rhs) const {
   1.612 +    return this->_M_is_equal(__rhs);
   1.613 +  }
   1.614 +  bool operator!=(const bitset<_Nb>& __rhs) const {
   1.615 +    return !this->_M_is_equal(__rhs);
   1.616 +  }
   1.617 +
   1.618 +  bool test(size_t __pos) const {
   1.619 +    if (__pos >= _Nb)
   1.620 +      __stl_throw_out_of_range("bitset");
   1.621 +    
   1.622 +    return _Unchecked_test(__pos);
   1.623 +  }
   1.624 +
   1.625 +  bool any() const { return this->_M_is_any(); }
   1.626 +  bool none() const { return !this->_M_is_any(); }
   1.627 +
   1.628 +  bitset<_Nb> operator<<(size_t __pos) const { 
   1.629 +    bitset<_Nb> __result(*this);
   1.630 +    __result <<= __pos ;  return __result; 
   1.631 +  }
   1.632 +  bitset<_Nb> operator>>(size_t __pos) const { 
   1.633 +    bitset<_Nb> __result(*this);
   1.634 +    __result >>= __pos ;  return __result; 
   1.635 +  }
   1.636 +
   1.637 +  //
   1.638 +  // EXTENSIONS: bit-find operations.  These operations are
   1.639 +  // experimental, and are subject to change or removal in future
   1.640 +  // versions.
   1.641 +  // 
   1.642 +
   1.643 +  // find the index of the first "on" bit
   1.644 +  size_t _Find_first() const 
   1.645 +    { return this->_M_do_find_first(_Nb); }
   1.646 +
   1.647 +  // find the index of the next "on" bit after prev
   1.648 +  size_t _Find_next( size_t __prev ) const 
   1.649 +    { return this->_M_do_find_next(__prev, _Nb); }
   1.650 +
   1.651 +//
   1.652 +// Definitions of should-be non-inline member functions.
   1.653 +//
   1.654 +# if defined (_STLP_MEMBER_TEMPLATES)
   1.655 +  template<class _CharT, class _Traits, class _Alloc>
   1.656 +    void _M_copy_from_string(const basic_string<_CharT,_Traits,_Alloc>& __s,
   1.657 +			     size_t __pos,
   1.658 +			     size_t __n) {
   1.659 +#else
   1.660 +    void _M_copy_from_string(const string& __s,
   1.661 +			     size_t __pos,
   1.662 +			     size_t __n) {
   1.663 +      typedef char_traits<char> _Traits;
   1.664 +#endif
   1.665 +      reset();
   1.666 +      size_t __tmp = _Nb;
   1.667 +      const size_t __Nbits = (min) (__tmp, (min) (__n, __s.size() - __pos));
   1.668 +      for ( size_t __i= 0; __i < __Nbits; ++__i) {
   1.669 +        typename _Traits::int_type __k = _Traits::to_int_type(__s[__pos + __Nbits - __i - 1]);
   1.670 +        // boris : widen() ?
   1.671 +        if (__k == '1')
   1.672 +          set(__i);
   1.673 +        else if (__k !='0')
   1.674 +          __stl_throw_invalid_argument("bitset");
   1.675 +      }
   1.676 +    }
   1.677 +  
   1.678 +# if defined (_STLP_MEMBER_TEMPLATES)
   1.679 +  template <class _CharT, class _Traits, class _Alloc>
   1.680 +    void _M_copy_to_string(basic_string<_CharT, _Traits, _Alloc>& __s) const
   1.681 +# else
   1.682 +    void _M_copy_to_string(string& __s) const
   1.683 +# endif
   1.684 +    {
   1.685 +      __s.assign(_Nb, '0');
   1.686 +      
   1.687 +      for (size_t __i = 0; __i < _Nb; ++__i) 
   1.688 +	if (_Unchecked_test(__i))
   1.689 +	  __s[_Nb - 1 - __i] = '1';
   1.690 +    }
   1.691 +
   1.692 +# if defined (_STLP_NON_TYPE_TMPL_PARAM_BUG)
   1.693 +  bitset<_Nb> operator&(const bitset<_Nb>& __y) const {
   1.694 +    bitset<_Nb> __result(*this);
   1.695 +    __result &= __y;
   1.696 +    return __result;
   1.697 +  }
   1.698 +  bitset<_Nb> operator|(const bitset<_Nb>& __y) const {
   1.699 +    bitset<_Nb> __result(*this);
   1.700 +    __result |= __y;
   1.701 +    return __result;
   1.702 +  }
   1.703 +  bitset<_Nb> operator^(const bitset<_Nb>& __y) const {
   1.704 +    bitset<_Nb> __result(*this);
   1.705 +    __result ^= __y;
   1.706 +    return __result;
   1.707 +  }
   1.708 +# endif 
   1.709 +
   1.710 +};
   1.711 +
   1.712 +// ------------------------------------------------------------
   1.713 +//
   1.714 +// 23.3.5.3 bitset operations:
   1.715 +//
   1.716 +
   1.717 +# if ! defined (_STLP_NON_TYPE_TMPL_PARAM_BUG)
   1.718 +
   1.719 +template <size_t _Nb>
   1.720 +inline bitset<_Nb>  _STLP_CALL
   1.721 +operator&(const bitset<_Nb>& __x,
   1.722 +          const bitset<_Nb>& __y) {
   1.723 +  bitset<_Nb> __result(__x);
   1.724 +  __result &= __y;
   1.725 +  return __result;
   1.726 +}
   1.727 +
   1.728 +
   1.729 +template <size_t _Nb>
   1.730 +inline bitset<_Nb>  _STLP_CALL
   1.731 +operator|(const bitset<_Nb>& __x,
   1.732 +          const bitset<_Nb>& __y) {
   1.733 +  bitset<_Nb> __result(__x);
   1.734 +  __result |= __y;
   1.735 +  return __result;
   1.736 +}
   1.737 +
   1.738 +template <size_t _Nb>
   1.739 +inline bitset<_Nb>  _STLP_CALL
   1.740 +operator^(const bitset<_Nb>& __x,
   1.741 +          const bitset<_Nb>& __y) {
   1.742 +  bitset<_Nb> __result(__x);
   1.743 +  __result ^= __y;
   1.744 +  return __result;
   1.745 +}
   1.746 +
   1.747 +#if defined ( _STLP_USE_NEW_IOSTREAMS )
   1.748 +
   1.749 +template <class _CharT, class _Traits, size_t _Nb>
   1.750 +basic_istream<_CharT, _Traits>&  _STLP_CALL
   1.751 +operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Nb>& __x);
   1.752 +
   1.753 +
   1.754 +template <class _CharT, class _Traits, size_t _Nb>
   1.755 +basic_ostream<_CharT, _Traits>& _STLP_CALL
   1.756 +operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Nb>& __x);
   1.757 +
   1.758 +#elif ! defined ( _STLP_USE_NO_IOSTREAMS )
   1.759 +
   1.760 +// (reg) For Watcom IO, this tells if ostream class is in .exe or in .dll
   1.761 +template <size_t _Nb>
   1.762 +_ISTREAM_DLL& _STLP_CALL
   1.763 +operator>>(_ISTREAM_DLL& __is, bitset<_Nb>& __x);
   1.764 +
   1.765 +template <size_t _Nb>
   1.766 +inline _OSTREAM_DLL&  _STLP_CALL operator<<(_OSTREAM_DLL& __os, const bitset<_Nb>& __x) {
   1.767 +  string __tmp;
   1.768 +  __x._M_copy_to_string(__tmp);
   1.769 +  return __os << __tmp;
   1.770 +}
   1.771 +
   1.772 +#endif
   1.773 +
   1.774 +# endif /* _STLP_NON_TYPE_TMPL_PARAM_BUG */
   1.775 +
   1.776 +#  undef  bitset
   1.777 +
   1.778 +
   1.779 +_STLP_END_NAMESPACE
   1.780 +
   1.781 +#  undef __BITS_PER_WORD
   1.782 +#  undef __BITSET_WORDS
   1.783 +
   1.784 +# if !defined (_STLP_LINK_TIME_INSTANTIATION)
   1.785 +#  include <stl/_bitset.c>
   1.786 +# endif
   1.787 +
   1.788 +#endif /* _STLP_BITSET_H */
   1.789 +
   1.790 +
   1.791 +// Local Variables:
   1.792 +// mode:C++
   1.793 +// End:
   1.794 +