epoc32/include/stdapis/stlportv5/stl/_bitset.h
branchSymbian3
changeset 4 837f303aceeb
parent 3 e1b950c65cb4
     1.1 --- a/epoc32/include/stdapis/stlportv5/stl/_bitset.h	Wed Mar 31 12:27:01 2010 +0100
     1.2 +++ b/epoc32/include/stdapis/stlportv5/stl/_bitset.h	Wed Mar 31 12:33:34 2010 +0100
     1.3 @@ -1,15 +1,14 @@
     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 + * Copyright (c) 1999
    1.11   * Boris Fomitchev
    1.12   *
    1.13   * This material is provided "as is", with absolutely no warranty expressed
    1.14   * or implied. Any use is at your own risk.
    1.15   *
    1.16 - * Permission to use or copy this software for any purpose is hereby granted 
    1.17 + * Permission to use or copy this software for any purpose is hereby granted
    1.18   * without fee, provided the above notices are retained on all copies.
    1.19   * Permission to modify the code and to distribute modified code is granted,
    1.20   * provided the above notices are retained, and a notice that the code was
    1.21 @@ -20,12 +19,12 @@
    1.22  #ifndef _STLP_BITSET_H
    1.23  #define _STLP_BITSET_H
    1.24  
    1.25 -// A bitset of size N has N % (sizeof(unsigned long) * CHAR_BIT) unused 
    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 +// Most of the actual code isn't contained in bitset<> itself, but in the
    1.33  // base class _Base_bitset.  The base class works with whole words, not with
    1.34  // individual bits.  This allows us to specialize _Base_bitset for the
    1.35  // important special case where the bitset is only a single word.
    1.36 @@ -36,47 +35,74 @@
    1.37  // returns a reference to a bit, again without doing any range checking.
    1.38  
    1.39  
    1.40 -# ifndef _STLP_INTERNAL_ALGOBASE_H
    1.41 +#ifndef _STLP_INTERNAL_ALGOBASE_H
    1.42  #  include <stl/_algobase.h>
    1.43 -# endif
    1.44 +#endif
    1.45  
    1.46 -# ifndef _STLP_INTERNAL_ALLOC_H
    1.47 +#ifndef _STLP_INTERNAL_ALLOC_H
    1.48  #  include <stl/_alloc.h>
    1.49 -# endif
    1.50 +#endif
    1.51  
    1.52 -# ifndef _STLP_INTERNAL_ITERATOR_H
    1.53 +#ifndef _STLP_INTERNAL_ITERATOR_H
    1.54  #  include <stl/_iterator.h>
    1.55 -# endif
    1.56 +#endif
    1.57  
    1.58 -# ifndef _STLP_INTERNAL_UNINITIALIZED_H
    1.59 +#ifndef _STLP_INTERNAL_UNINITIALIZED_H
    1.60  #  include <stl/_uninitialized.h>
    1.61 -# endif
    1.62 +#endif
    1.63  
    1.64 -# ifndef _STLP_RANGE_ERRORS_H
    1.65 +#ifndef _STLP_RANGE_ERRORS_H
    1.66  #  include <stl/_range_errors.h>
    1.67 -# endif
    1.68 +#endif
    1.69  
    1.70 -# ifndef _STLP_STRING
    1.71 -#  include <string>
    1.72 -# endif
    1.73 -
    1.74 -# ifndef _STLP_ISTREAM
    1.75 -#  include <istream>
    1.76 -# endif
    1.77 +#ifndef _STLP_INTERNAL_STRING_H
    1.78 +#  include <stl/_string.h>
    1.79 +#endif
    1.80  
    1.81  #define __BITS_PER_WORD (CHAR_BIT*sizeof(unsigned long))
    1.82  #define __BITSET_WORDS(__n) ((__n + __BITS_PER_WORD - 1)/__BITS_PER_WORD)
    1.83  
    1.84  _STLP_BEGIN_NAMESPACE
    1.85  
    1.86 +_STLP_MOVE_TO_PRIV_NAMESPACE
    1.87 +
    1.88  // structure to aid in counting bits
    1.89 -template<class _Dummy> 
    1.90 -class _Bs_G {
    1.91 -public:
    1.92 -  static const unsigned char _S_bit_count[256];
    1.93 -  // Mapping from 8 bit unsigned integers to the index of the first one
    1.94 -  // bit:
    1.95 -  static const unsigned char _S_first_one[256];
    1.96 +class _STLP_CLASS_DECLSPEC _Bs_G
    1.97 +{
    1.98 +  public:
    1.99 +    //returns the number of bit set within the buffer between __beg and __end.
   1.100 +   #if defined (__SYMBIAN32__)
   1.101 +    _STLP_DECLSPEC 
   1.102 +#endif 
   1.103 +	  static size_t _S_count(const unsigned char *__beg, const unsigned char *__end)
   1.104 +#if defined (_STLP_USE_NO_IOSTREAMS)
   1.105 +    {
   1.106 +      size_t __result = 0;
   1.107 +      for (; __beg != __end; ++__beg) {
   1.108 +        for (size_t i = 0; i < (sizeof(unsigned char) * 8); ++i) {
   1.109 +          if ((*__beg & (1 << i)) != 0) { ++__result; }
   1.110 +        }
   1.111 +      }
   1.112 +      return __result;
   1.113 +    }
   1.114 +#else
   1.115 +      ;
   1.116 +#endif
   1.117 +    // Mapping from 8 bit unsigned integers to the index of the first one bit set:
   1.118 +#if defined (__SYMBIAN32__)
   1.119 +    _STLP_DECLSPEC 
   1.120 +#endif
   1.121 +	static unsigned char _S_first_one(unsigned char __x)
   1.122 +#if defined (_STLP_USE_NO_IOSTREAMS)
   1.123 +    {
   1.124 +      for (unsigned char i = 0; i < (sizeof(unsigned char) * 8); ++i) {
   1.125 +        if ((__x & (1 << i)) != 0) { return i; }
   1.126 +      }
   1.127 +      return 0;
   1.128 +    }
   1.129 +#else
   1.130 +      ;
   1.131 +#endif
   1.132  };
   1.133  
   1.134  //
   1.135 @@ -89,13 +115,13 @@
   1.136  
   1.137    _WordT _M_w[_Nw];                // 0 is the least significant word.
   1.138  
   1.139 -  _Base_bitset( void ) { _M_do_reset(); }
   1.140 +  _Base_bitset() { _M_do_reset(); }
   1.141  
   1.142    _Base_bitset(unsigned long __val) {
   1.143      _M_do_reset();
   1.144      _M_w[0] = __val;
   1.145    }
   1.146 -  
   1.147 +
   1.148    static size_t _STLP_CALL _S_whichword( size_t __pos ) {
   1.149      return __pos / __BITS_PER_WORD;
   1.150    }
   1.151 @@ -149,7 +175,6 @@
   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 @@ -169,18 +194,13 @@
   1.160    }
   1.161  
   1.162    size_t _M_do_count() const {
   1.163 -    size_t __result = 0;
   1.164      const unsigned char* __byte_ptr = (const unsigned char*)_M_w;
   1.165      const unsigned char* __end_ptr = (const unsigned char*)(_M_w+_Nw);
   1.166  
   1.167 -    while ( __byte_ptr < __end_ptr ) {
   1.168 -      __result += _Bs_G<bool>::_S_bit_count[*__byte_ptr];
   1.169 -      __byte_ptr++;
   1.170 -    }
   1.171 -    return __result;
   1.172 +    return _Bs_G::_S_count(__byte_ptr, __end_ptr);
   1.173    }
   1.174  
   1.175 -  unsigned long _M_do_to_ulong() const; 
   1.176 +  unsigned long _M_do_to_ulong() const;
   1.177  
   1.178    // find first "on" bit
   1.179    size_t _M_do_find_first(size_t __not_found) const;
   1.180 @@ -192,7 +212,6 @@
   1.181  //
   1.182  // Base class: specialization for a single word.
   1.183  //
   1.184 -
   1.185  _STLP_TEMPLATE_NULL
   1.186  struct _Base_bitset<1UL> {
   1.187    typedef unsigned long _WordT;
   1.188 @@ -202,7 +221,7 @@
   1.189  
   1.190    _Base_bitset( void ) : _M_w(0) {}
   1.191    _Base_bitset(unsigned long __val) : _M_w(__val) {}
   1.192 -  
   1.193 +
   1.194    static size_t _STLP_CALL _S_whichword( size_t __pos ) {
   1.195      return __pos / __BITS_PER_WORD ;
   1.196    }
   1.197 @@ -222,7 +241,6 @@
   1.198    _WordT& _M_hiword()       { return _M_w; }
   1.199    _WordT  _M_hiword() const { return _M_w; }
   1.200  
   1.201 -
   1.202    void _M_do_and(const _Self& __x) { _M_w &= __x._M_w; }
   1.203    void _M_do_or(const _Self& __x)  { _M_w |= __x._M_w; }
   1.204    void _M_do_xor(const _Self& __x) { _M_w ^= __x._M_w; }
   1.205 @@ -240,14 +258,9 @@
   1.206    }
   1.207  
   1.208    size_t _M_do_count() const {
   1.209 -    size_t __result = 0;
   1.210      const unsigned char* __byte_ptr = (const unsigned char*)&_M_w;
   1.211      const unsigned char* __end_ptr = ((const unsigned char*)&_M_w)+sizeof(_M_w);
   1.212 -    while ( __byte_ptr < __end_ptr ) {
   1.213 -      __result += _Bs_G<bool>::_S_bit_count[*__byte_ptr];
   1.214 -      __byte_ptr++;
   1.215 -    }
   1.216 -    return __result;
   1.217 +    return _Bs_G::_S_count(__byte_ptr, __end_ptr);
   1.218    }
   1.219  
   1.220    unsigned long _M_do_to_ulong() const { return _M_w; }
   1.221 @@ -255,8 +268,7 @@
   1.222    inline size_t _M_do_find_first(size_t __not_found) const;
   1.223  
   1.224    // find the next "on" bit that follows "prev"
   1.225 -  inline size_t _M_do_find_next(size_t __prev, size_t __not_found) const; 
   1.226 -
   1.227 +  inline size_t _M_do_find_next(size_t __prev, size_t __not_found) const;
   1.228  };
   1.229  
   1.230  
   1.231 @@ -265,10 +277,8 @@
   1.232  // Definitions of should-be-non-inline functions from the single-word version of
   1.233  //  _Base_bitset.
   1.234  //
   1.235 -
   1.236 -inline size_t 
   1.237 -_Base_bitset<1UL>::_M_do_find_first(size_t __not_found) const
   1.238 -{
   1.239 +inline size_t
   1.240 +_Base_bitset<1UL>::_M_do_find_first(size_t __not_found) const {
   1.241    //  typedef unsigned long _WordT;
   1.242    _WordT __thisword = _M_w;
   1.243  
   1.244 @@ -278,7 +288,7 @@
   1.245        unsigned char __this_byte
   1.246          = __STATIC_CAST(unsigned char,(__thisword & (~(unsigned char)0)));
   1.247        if ( __this_byte )
   1.248 -        return __j*CHAR_BIT + _Bs_G<bool>::_S_first_one[__this_byte];
   1.249 +        return __j*CHAR_BIT + _Bs_G::_S_first_one(__this_byte);
   1.250  
   1.251        __thisword >>= CHAR_BIT;
   1.252      }
   1.253 @@ -287,10 +297,9 @@
   1.254    return __not_found;
   1.255  }
   1.256  
   1.257 -inline size_t 
   1.258 -_Base_bitset<1UL>::_M_do_find_next(size_t __prev, 
   1.259 -                                   size_t __not_found ) const
   1.260 -{
   1.261 +inline size_t
   1.262 +_Base_bitset<1UL>::_M_do_find_next(size_t __prev,
   1.263 +                                   size_t __not_found ) const {
   1.264    // make bound inclusive
   1.265    ++__prev;
   1.266  
   1.267 @@ -312,7 +321,7 @@
   1.268        unsigned char __this_byte
   1.269          = __STATIC_CAST(unsigned char,(__thisword & (~(unsigned char)0)));
   1.270        if ( __this_byte )
   1.271 -        return __j*CHAR_BIT + _Bs_G<bool>::_S_first_one[__this_byte];
   1.272 +        return __j*CHAR_BIT + _Bs_G::_S_first_one(__this_byte);
   1.273  
   1.274        __thisword >>= CHAR_BIT;
   1.275      }
   1.276 @@ -328,29 +337,28 @@
   1.277  
   1.278  template <size_t _Extrabits> struct _Sanitize {
   1.279    static void _STLP_CALL _M_do_sanitize(unsigned long& __val)
   1.280 -    { __val &= ~((~__STATIC_CAST(unsigned long,0)) << _Extrabits); }
   1.281 +  { __val &= ~((~__STATIC_CAST(unsigned long,0)) << _Extrabits); }
   1.282  };
   1.283  
   1.284  _STLP_TEMPLATE_NULL struct _Sanitize<0UL> {
   1.285    static void _STLP_CALL _M_do_sanitize(unsigned long) {}
   1.286  };
   1.287  
   1.288 +_STLP_MOVE_TO_STD_NAMESPACE
   1.289 +
   1.290  // ------------------------------------------------------------
   1.291  // Class bitset.
   1.292  //   _Nb may be any nonzero number of type size_t.
   1.293 -
   1.294 -
   1.295  template<size_t _Nb>
   1.296 -class bitset : public _Base_bitset<__BITSET_WORDS(_Nb) > 
   1.297 -{
   1.298 +class bitset : public _STLP_PRIV _Base_bitset<__BITSET_WORDS(_Nb) > {
   1.299  public:
   1.300    enum { _Words = __BITSET_WORDS(_Nb) } ;
   1.301  
   1.302  private:
   1.303 -  typedef _Base_bitset< _Words > _Base;
   1.304 +  typedef _STLP_PRIV _Base_bitset< _Words > _Base;
   1.305  
   1.306    void _M_do_sanitize() {
   1.307 -    _Sanitize<_Nb%__BITS_PER_WORD >::_M_do_sanitize(this->_M_hiword());
   1.308 +    _STLP_PRIV _Sanitize<_Nb%__BITS_PER_WORD >::_M_do_sanitize(this->_M_hiword());
   1.309    }
   1.310  public:
   1.311    typedef unsigned long _WordT;
   1.312 @@ -359,7 +367,7 @@
   1.313  
   1.314    // bit reference:
   1.315    struct reference {
   1.316 -  typedef _Base_bitset<_Words > _Bitset_base;
   1.317 +  typedef _STLP_PRIV _Base_bitset<_Words > _Bitset_base;
   1.318    typedef bitset<_Nb> _Bitset;
   1.319      //    friend _Bitset;
   1.320      _WordT *_M_wp;
   1.321 @@ -412,15 +420,14 @@
   1.322    // 23.3.5.1 constructors:
   1.323    bitset() {}
   1.324  
   1.325 -  bitset(unsigned long __val) : _Base_bitset<_Words>(__val) { _M_do_sanitize(); }
   1.326 +  bitset(unsigned long __val) : _STLP_PRIV _Base_bitset<_Words>(__val) { _M_do_sanitize(); }
   1.327  
   1.328 -# ifdef _STLP_MEMBER_TEMPLATES
   1.329 +#if defined (_STLP_MEMBER_TEMPLATES)
   1.330    template<class _CharT, class _Traits, class _Alloc>
   1.331    explicit bitset(const basic_string<_CharT,_Traits,_Alloc>& __s,
   1.332                    size_t __pos = 0)
   1.333 -    : _Base_bitset<_Words >() 
   1.334 -  {
   1.335 -    if (__pos > __s.size()) 
   1.336 +    : _STLP_PRIV _Base_bitset<_Words >() {
   1.337 +    if (__pos > __s.size())
   1.338        __stl_throw_out_of_range("bitset");
   1.339      _M_copy_from_string(__s, __pos,
   1.340                          basic_string<_CharT, _Traits, _Alloc>::npos);
   1.341 @@ -429,19 +436,17 @@
   1.342    bitset(const basic_string<_CharT, _Traits, _Alloc>& __s,
   1.343            size_t __pos,
   1.344            size_t __n)
   1.345 -  : _Base_bitset<_Words >() 
   1.346 -  {
   1.347 -    if (__pos > __s.size()) 
   1.348 +  : _STLP_PRIV _Base_bitset<_Words >() {
   1.349 +    if (__pos > __s.size())
   1.350        __stl_throw_out_of_range("bitset");
   1.351      _M_copy_from_string(__s, __pos, __n);
   1.352    }
   1.353  #else /* _STLP_MEMBER_TEMPLATES */
   1.354    explicit bitset(const string& __s,
   1.355                    size_t __pos = 0,
   1.356 -                  size_t __n = (size_t)-1) 
   1.357 -    : _Base_bitset<_Words >() 
   1.358 -  {
   1.359 -    if (__pos > __s.size()) 
   1.360 +                  size_t __n = (size_t)-1)
   1.361 +    : _STLP_PRIV _Base_bitset<_Words >() {
   1.362 +    if (__pos > __s.size())
   1.363        __stl_throw_out_of_range("bitset");
   1.364      _M_copy_from_string(__s, __pos, __n);
   1.365    }
   1.366 @@ -464,36 +469,14 @@
   1.367    }
   1.368  
   1.369    bitset<_Nb>& operator<<=(size_t __pos) {
   1.370 -#ifdef __SYMBIAN32__
   1.371 -	if(__pos < _Nb)
   1.372 -	{
   1.373 -    	this->_M_do_left_shift(__pos);
   1.374 -    	this->_M_do_sanitize();
   1.375 -	}
   1.376 -	else
   1.377 -		this->_M_do_reset();
   1.378 -#else
   1.379 -	this->_M_do_left_shift(__pos);
   1.380 -	this->_M_do_sanitize();
   1.381 -#endif
   1.382 -
   1.383 +    this->_M_do_left_shift(__pos);
   1.384 +    this->_M_do_sanitize();
   1.385      return *this;
   1.386    }
   1.387  
   1.388    bitset<_Nb>& operator>>=(size_t __pos) {
   1.389 -#ifdef __SYMBIAN32__
   1.390 -	if(__pos < _Nb)
   1.391 -	{
   1.392 -    	this->_M_do_right_shift(__pos);
   1.393 -    	this->_M_do_sanitize();
   1.394 -	}
   1.395 -	else
   1.396 -		this->_M_do_reset();
   1.397 -#else
   1.398 -	this->_M_do_right_shift(__pos);
   1.399 +    this->_M_do_right_shift(__pos);
   1.400      this->_M_do_sanitize();
   1.401 -#endif
   1.402 -
   1.403      return *this;
   1.404    }
   1.405  
   1.406 @@ -503,7 +486,7 @@
   1.407    //
   1.408  
   1.409    bitset<_Nb>& _Unchecked_set(size_t __pos) {
   1.410 -    this->_M_getword(__pos) |= _Base_bitset<_Words > ::_S_maskbit(__pos);
   1.411 +    this->_M_getword(__pos) |= _STLP_PRIV _Base_bitset<_Words > ::_S_maskbit(__pos);
   1.412      return *this;
   1.413    }
   1.414  
   1.415 @@ -575,7 +558,7 @@
   1.416      return _Unchecked_flip(__pos);
   1.417    }
   1.418  
   1.419 -  bitset<_Nb> operator~() const { 
   1.420 +  bitset<_Nb> operator~() const {
   1.421      return bitset<_Nb>(*this).flip();
   1.422    }
   1.423  
   1.424 @@ -586,7 +569,7 @@
   1.425  
   1.426    unsigned long to_ulong() const { return this->_M_do_to_ulong(); }
   1.427  
   1.428 -#if defined (_STLP_MEMBER_TEMPLATES) && !  defined (_STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS)
   1.429 +#if defined (_STLP_MEMBER_TEMPLATES) && !defined (_STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS)
   1.430    template <class _CharT, class _Traits, class _Alloc>
   1.431    basic_string<_CharT, _Traits, _Alloc> to_string() const {
   1.432      basic_string<_CharT, _Traits, _Alloc> __result;
   1.433 @@ -615,78 +598,90 @@
   1.434    bool test(size_t __pos) const {
   1.435      if (__pos >= _Nb)
   1.436        __stl_throw_out_of_range("bitset");
   1.437 -    
   1.438 +
   1.439      return _Unchecked_test(__pos);
   1.440    }
   1.441  
   1.442    bool any() const { return this->_M_is_any(); }
   1.443    bool none() const { return !this->_M_is_any(); }
   1.444  
   1.445 -  bitset<_Nb> operator<<(size_t __pos) const { 
   1.446 +  bitset<_Nb> operator<<(size_t __pos) const {
   1.447      bitset<_Nb> __result(*this);
   1.448 -    __result <<= __pos ;  return __result; 
   1.449 +    __result <<= __pos ;  return __result;
   1.450    }
   1.451 -  bitset<_Nb> operator>>(size_t __pos) const { 
   1.452 +  bitset<_Nb> operator>>(size_t __pos) const {
   1.453      bitset<_Nb> __result(*this);
   1.454 -    __result >>= __pos ;  return __result; 
   1.455 +    __result >>= __pos ;  return __result;
   1.456    }
   1.457  
   1.458 +#if !defined (_STLP_NO_EXTENSIONS)
   1.459    //
   1.460    // EXTENSIONS: bit-find operations.  These operations are
   1.461    // experimental, and are subject to change or removal in future
   1.462    // versions.
   1.463 -  // 
   1.464 +  //
   1.465  
   1.466    // find the index of the first "on" bit
   1.467 -  size_t _Find_first() const 
   1.468 +  size_t _Find_first() const
   1.469      { return this->_M_do_find_first(_Nb); }
   1.470  
   1.471    // find the index of the next "on" bit after prev
   1.472 -  size_t _Find_next( size_t __prev ) const 
   1.473 +  size_t _Find_next( size_t __prev ) const
   1.474      { return this->_M_do_find_next(__prev, _Nb); }
   1.475 +#endif
   1.476  
   1.477  //
   1.478  // Definitions of should-be non-inline member functions.
   1.479  //
   1.480 -# if defined (_STLP_MEMBER_TEMPLATES)
   1.481 +#if defined (_STLP_MEMBER_TEMPLATES)
   1.482    template<class _CharT, class _Traits, class _Alloc>
   1.483 -    void _M_copy_from_string(const basic_string<_CharT,_Traits,_Alloc>& __s,
   1.484 -			     size_t __pos,
   1.485 -			     size_t __n) {
   1.486 +  void _M_copy_from_string(const basic_string<_CharT,_Traits,_Alloc>& __s,
   1.487 +                           size_t __pos, size_t __n) {
   1.488  #else
   1.489 -    void _M_copy_from_string(const string& __s,
   1.490 -			     size_t __pos,
   1.491 -			     size_t __n) {
   1.492 -      typedef char_traits<char> _Traits;
   1.493 +  void _M_copy_from_string(const string& __s,
   1.494 +                           size_t __pos, size_t __n) {
   1.495 +    typedef typename string::traits_type _Traits;
   1.496  #endif
   1.497 -      reset();
   1.498 -      size_t __tmp = _Nb;
   1.499 -      const size_t __Nbits = (min) (__tmp, (min) (__n, __s.size() - __pos));
   1.500 -      for ( size_t __i= 0; __i < __Nbits; ++__i) {
   1.501 -        typename _Traits::int_type __k = _Traits::to_int_type(__s[__pos + __Nbits - __i - 1]);
   1.502 -        // boris : widen() ?
   1.503 -        if (__k == '1')
   1.504 -          set(__i);
   1.505 -        else if (__k !='0')
   1.506 -          __stl_throw_invalid_argument("bitset");
   1.507 -      }
   1.508 +    reset();
   1.509 +    size_t __tmp = _Nb;
   1.510 +    const size_t __Nbits = (min) (__tmp, (min) (__n, __s.size() - __pos));
   1.511 +    for ( size_t __i= 0; __i < __Nbits; ++__i) {
   1.512 +      typename _Traits::int_type __k = _Traits::to_int_type(__s[__pos + __Nbits - __i - 1]);
   1.513 +      // boris : widen() ?
   1.514 +      if (__k == '1')
   1.515 +        set(__i);
   1.516 +      else if (__k != '0')
   1.517 +        __stl_throw_invalid_argument("bitset");
   1.518      }
   1.519 -  
   1.520 -# if defined (_STLP_MEMBER_TEMPLATES)
   1.521 +  }
   1.522 +
   1.523 +#if defined (_STLP_MEMBER_TEMPLATES)
   1.524    template <class _CharT, class _Traits, class _Alloc>
   1.525 -    void _M_copy_to_string(basic_string<_CharT, _Traits, _Alloc>& __s) const
   1.526 -# else
   1.527 -    void _M_copy_to_string(string& __s) const
   1.528 -# endif
   1.529 -    {
   1.530 -      __s.assign(_Nb, '0');
   1.531 -      
   1.532 -      for (size_t __i = 0; __i < _Nb; ++__i) 
   1.533 -	if (_Unchecked_test(__i))
   1.534 -	  __s[_Nb - 1 - __i] = '1';
   1.535 +  void _M_copy_to_string(basic_string<_CharT, _Traits, _Alloc>& __s) const
   1.536 +#else
   1.537 +  void _M_copy_to_string(string& __s) const
   1.538 +#endif
   1.539 +  {
   1.540 +    __s.assign(_Nb, '0');
   1.541 +
   1.542 +    for (size_t __i = 0; __i < _Nb; ++__i) {
   1.543 +      if (_Unchecked_test(__i))
   1.544 +        __s[_Nb - 1 - __i] = '1';
   1.545      }
   1.546 +  }
   1.547  
   1.548 -# if defined (_STLP_NON_TYPE_TMPL_PARAM_BUG)
   1.549 +#if !defined (_STLP_MEMBER_TEMPLATES) && !defined (_STLP_NO_WCHAR_T)
   1.550 +  void _M_copy_to_string(wstring& __s) const {
   1.551 +    __s.assign(_Nb, '0');
   1.552 +
   1.553 +    for (size_t __i = 0; __i < _Nb; ++__i) {
   1.554 +      if (_Unchecked_test(__i))
   1.555 +        __s[_Nb - 1 - __i] = '1';
   1.556 +    }
   1.557 +  }
   1.558 +#endif
   1.559 +
   1.560 +#if defined (_STLP_NON_TYPE_TMPL_PARAM_BUG)
   1.561    bitset<_Nb> operator&(const bitset<_Nb>& __y) const {
   1.562      bitset<_Nb> __result(*this);
   1.563      __result &= __y;
   1.564 @@ -702,17 +697,14 @@
   1.565      __result ^= __y;
   1.566      return __result;
   1.567    }
   1.568 -# endif 
   1.569 -
   1.570 +#endif
   1.571  };
   1.572  
   1.573  // ------------------------------------------------------------
   1.574  //
   1.575  // 23.3.5.3 bitset operations:
   1.576  //
   1.577 -
   1.578 -# if ! defined (_STLP_NON_TYPE_TMPL_PARAM_BUG)
   1.579 -
   1.580 +#if ! defined (_STLP_NON_TYPE_TMPL_PARAM_BUG)
   1.581  template <size_t _Nb>
   1.582  inline bitset<_Nb>  _STLP_CALL
   1.583  operator&(const bitset<_Nb>& __x,
   1.584 @@ -741,51 +733,154 @@
   1.585    return __result;
   1.586  }
   1.587  
   1.588 -#if defined ( _STLP_USE_NEW_IOSTREAMS )
   1.589 +#if !defined (_STLP_USE_NO_IOSTREAMS)
   1.590 +
   1.591 +_STLP_END_NAMESPACE
   1.592 +
   1.593 +#  if !(defined (_STLP_MSVC) && (_STLP_MSVC < 1300)) && \
   1.594 +      !(defined(__SUNPRO_CC) && (__SUNPRO_CC < 0x500))
   1.595 +
   1.596 +#ifndef _STLP_INTERNAL_IOSFWD
   1.597 +#  include <stl/_iosfwd.h>
   1.598 +#endif
   1.599 +
   1.600 +_STLP_BEGIN_NAMESPACE
   1.601  
   1.602  template <class _CharT, class _Traits, size_t _Nb>
   1.603  basic_istream<_CharT, _Traits>&  _STLP_CALL
   1.604  operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Nb>& __x);
   1.605  
   1.606 -
   1.607  template <class _CharT, class _Traits, size_t _Nb>
   1.608  basic_ostream<_CharT, _Traits>& _STLP_CALL
   1.609  operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Nb>& __x);
   1.610  
   1.611 -#elif ! defined ( _STLP_USE_NO_IOSTREAMS )
   1.612 +#  else
   1.613  
   1.614 -// (reg) For Watcom IO, this tells if ostream class is in .exe or in .dll
   1.615 -template <size_t _Nb>
   1.616 -_ISTREAM_DLL& _STLP_CALL
   1.617 -operator>>(_ISTREAM_DLL& __is, bitset<_Nb>& __x);
   1.618 +#ifndef _STLP_STRING_IO_H
   1.619 +#  include <stl/_string_io.h> //includes _istream.h and _ostream.h
   1.620 +#endif
   1.621 +
   1.622 +_STLP_BEGIN_NAMESPACE
   1.623  
   1.624  template <size_t _Nb>
   1.625 -inline _OSTREAM_DLL&  _STLP_CALL operator<<(_OSTREAM_DLL& __os, const bitset<_Nb>& __x) {
   1.626 +istream&  _STLP_CALL
   1.627 +operator>>(istream& __is, bitset<_Nb>& __x) {
   1.628 +  typedef typename string::traits_type _Traits;
   1.629 +  string __tmp;
   1.630 +  __tmp.reserve(_Nb);
   1.631 +
   1.632 +  // Skip whitespace
   1.633 +  typename istream::sentry __sentry(__is);
   1.634 +  if (__sentry) {
   1.635 +    streambuf* __buf = __is.rdbuf();
   1.636 +    for (size_t __i = 0; __i < _Nb; ++__i) {
   1.637 +      static typename _Traits::int_type __eof = _Traits::eof();
   1.638 +
   1.639 +      typename _Traits::int_type __c1 = __buf->sbumpc();
   1.640 +      if (_Traits::eq_int_type(__c1, __eof)) {
   1.641 +        __is.setstate(ios_base::eofbit);
   1.642 +        break;
   1.643 +      }
   1.644 +      else {
   1.645 +        typename _Traits::char_type __c2 = _Traits::to_char_type(__c1);
   1.646 +        char __c  = __is.narrow(__c2, '*');
   1.647 +
   1.648 +        if (__c == '0' || __c == '1')
   1.649 +          __tmp.push_back(__c);
   1.650 +        else if (_Traits::eq_int_type(__buf->sputbackc(__c2), __eof)) {
   1.651 +          __is.setstate(ios_base::failbit);
   1.652 +          break;
   1.653 +        }
   1.654 +      }
   1.655 +    }
   1.656 +
   1.657 +    if (__tmp.empty())
   1.658 +      __is.setstate(ios_base::failbit);
   1.659 +    else
   1.660 +      __x._M_copy_from_string(__tmp, __STATIC_CAST(size_t,0), _Nb);
   1.661 +  }
   1.662 +
   1.663 +  return __is;
   1.664 +}
   1.665 +
   1.666 +template <size_t _Nb>
   1.667 +ostream& _STLP_CALL
   1.668 +operator<<(ostream& __os, const bitset<_Nb>& __x) {
   1.669    string __tmp;
   1.670    __x._M_copy_to_string(__tmp);
   1.671    return __os << __tmp;
   1.672  }
   1.673  
   1.674 +#    if !defined (_STLP_NO_WCHAR_T)
   1.675 +
   1.676 +template <size_t _Nb>
   1.677 +wistream&  _STLP_CALL
   1.678 +operator>>(wistream& __is, bitset<_Nb>& __x) {
   1.679 +  typedef typename wstring::traits_type _Traits;
   1.680 +  wstring __tmp;
   1.681 +  __tmp.reserve(_Nb);
   1.682 +
   1.683 +  // Skip whitespace
   1.684 +  typename wistream::sentry __sentry(__is);
   1.685 +  if (__sentry) {
   1.686 +    wstreambuf* __buf = __is.rdbuf();
   1.687 +    for (size_t __i = 0; __i < _Nb; ++__i) {
   1.688 +      static typename _Traits::int_type __eof = _Traits::eof();
   1.689 +
   1.690 +      typename _Traits::int_type __c1 = __buf->sbumpc();
   1.691 +      if (_Traits::eq_int_type(__c1, __eof)) {
   1.692 +        __is.setstate(ios_base::eofbit);
   1.693 +        break;
   1.694 +      }
   1.695 +      else {
   1.696 +        typename _Traits::char_type __c2 = _Traits::to_char_type(__c1);
   1.697 +        char __c  = __is.narrow(__c2, '*');
   1.698 +
   1.699 +        if (__c == '0' || __c == '1')
   1.700 +          __tmp.push_back(__c);
   1.701 +        else if (_Traits::eq_int_type(__buf->sputbackc(__c2), __eof)) {
   1.702 +          __is.setstate(ios_base::failbit);
   1.703 +          break;
   1.704 +        }
   1.705 +      }
   1.706 +    }
   1.707 +
   1.708 +    if (__tmp.empty())
   1.709 +      __is.setstate(ios_base::failbit);
   1.710 +    else
   1.711 +      __x._M_copy_from_string(__tmp, __STATIC_CAST(size_t,0), _Nb);
   1.712 +  }
   1.713 +
   1.714 +  return __is;
   1.715 +}
   1.716 +
   1.717 +template <size_t _Nb>
   1.718 +wostream& _STLP_CALL
   1.719 +operator<<(wostream& __os, const bitset<_Nb>& __x) {
   1.720 +  wstring __tmp;
   1.721 +  __x._M_copy_to_string(__tmp);
   1.722 +  return __os << __tmp;
   1.723 +}
   1.724 +
   1.725 +#    endif /* _STLP_NO_WCHAR_T */
   1.726 +#  endif
   1.727  #endif
   1.728  
   1.729 -# endif /* _STLP_NON_TYPE_TMPL_PARAM_BUG */
   1.730 +#endif /* _STLP_NON_TYPE_TMPL_PARAM_BUG */
   1.731  
   1.732 -#  undef  bitset
   1.733 -
   1.734 +#undef  bitset
   1.735  
   1.736  _STLP_END_NAMESPACE
   1.737  
   1.738 -#  undef __BITS_PER_WORD
   1.739 -#  undef __BITSET_WORDS
   1.740 +#undef __BITS_PER_WORD
   1.741 +#undef __BITSET_WORDS
   1.742  
   1.743 -# if !defined (_STLP_LINK_TIME_INSTANTIATION)
   1.744 +#if !defined (_STLP_LINK_TIME_INSTANTIATION)
   1.745  #  include <stl/_bitset.c>
   1.746 -# endif
   1.747 +#endif
   1.748  
   1.749  #endif /* _STLP_BITSET_H */
   1.750  
   1.751 -
   1.752  // Local Variables:
   1.753  // mode:C++
   1.754  // End:
   1.755 -