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