3 * Silicon Graphics Computer Systems, Inc.
8 * This material is provided "as is", with absolutely no warranty expressed
9 * or implied. Any use is at your own risk.
11 * Permission to use or copy this software for any purpose is hereby granted
12 * without fee, provided the above notices are retained on all copies.
13 * Permission to modify the code and to distribute modified code is granted,
14 * provided the above notices are retained, and a notice that the code was
15 * modified is included with the above copyright notice.
19 #ifndef _STLP_BITSET_H
20 #define _STLP_BITSET_H
22 // A bitset of size N has N % (sizeof(unsigned long) * CHAR_BIT) unused
23 // bits. (They are the high- order bits in the highest word.) It is
24 // a class invariant of class bitset<> that those unused bits are
27 // Most of the actual code isn't contained in bitset<> itself, but in the
28 // base class _Base_bitset. The base class works with whole words, not with
29 // individual bits. This allows us to specialize _Base_bitset for the
30 // important special case where the bitset is only a single word.
32 // The C++ standard does not define the precise semantics of operator[].
33 // In this implementation the const version of operator[] is equivalent
34 // to test(), except that it does no range checking. The non-const version
35 // returns a reference to a bit, again without doing any range checking.
38 #ifndef _STLP_INTERNAL_ALGOBASE_H
39 # include <stl/_algobase.h>
42 #ifndef _STLP_INTERNAL_ALLOC_H
43 # include <stl/_alloc.h>
46 #ifndef _STLP_INTERNAL_ITERATOR_H
47 # include <stl/_iterator.h>
50 #ifndef _STLP_INTERNAL_UNINITIALIZED_H
51 # include <stl/_uninitialized.h>
54 #ifndef _STLP_RANGE_ERRORS_H
55 # include <stl/_range_errors.h>
58 #ifndef _STLP_INTERNAL_STRING_H
59 # include <stl/_string.h>
62 #define __BITS_PER_WORD (CHAR_BIT*sizeof(unsigned long))
63 #define __BITSET_WORDS(__n) ((__n + __BITS_PER_WORD - 1)/__BITS_PER_WORD)
67 _STLP_MOVE_TO_PRIV_NAMESPACE
69 // structure to aid in counting bits
70 class _STLP_CLASS_DECLSPEC _Bs_G
73 //returns the number of bit set within the buffer between __beg and __end.
74 #if defined (__SYMBIAN32__)
77 static size_t _S_count(const unsigned char *__beg, const unsigned char *__end)
78 #if defined (_STLP_USE_NO_IOSTREAMS)
81 for (; __beg != __end; ++__beg) {
82 for (size_t i = 0; i < (sizeof(unsigned char) * 8); ++i) {
83 if ((*__beg & (1 << i)) != 0) { ++__result; }
91 // Mapping from 8 bit unsigned integers to the index of the first one bit set:
92 #if defined (__SYMBIAN32__)
95 static unsigned char _S_first_one(unsigned char __x)
96 #if defined (_STLP_USE_NO_IOSTREAMS)
98 for (unsigned char i = 0; i < (sizeof(unsigned char) * 8); ++i) {
99 if ((__x & (1 << i)) != 0) { return i; }
109 // Base class: general case.
113 struct _Base_bitset {
114 typedef unsigned long _WordT;
116 _WordT _M_w[_Nw]; // 0 is the least significant word.
118 _Base_bitset() { _M_do_reset(); }
120 _Base_bitset(unsigned long __val) {
125 static size_t _STLP_CALL _S_whichword( size_t __pos ) {
126 return __pos / __BITS_PER_WORD;
128 static size_t _STLP_CALL _S_whichbyte( size_t __pos ) {
129 return (__pos % __BITS_PER_WORD) / CHAR_BIT;
131 static size_t _STLP_CALL _S_whichbit( size_t __pos ) {
132 return __pos % __BITS_PER_WORD;
134 static _WordT _STLP_CALL _S_maskbit( size_t __pos ) {
135 return __STATIC_CAST(_WordT,1) << _S_whichbit(__pos);
138 _WordT& _M_getword(size_t __pos) { return _M_w[_S_whichword(__pos)]; }
139 _WordT _M_getword(size_t __pos) const { return _M_w[_S_whichword(__pos)]; }
141 _WordT& _M_hiword() { return _M_w[_Nw - 1]; }
142 _WordT _M_hiword() const { return _M_w[_Nw - 1]; }
144 void _M_do_and(const _Base_bitset<_Nw>& __x) {
145 for ( size_t __i = 0; __i < _Nw; __i++ ) {
146 _M_w[__i] &= __x._M_w[__i];
150 void _M_do_or(const _Base_bitset<_Nw>& __x) {
151 for ( size_t __i = 0; __i < _Nw; __i++ ) {
152 _M_w[__i] |= __x._M_w[__i];
156 void _M_do_xor(const _Base_bitset<_Nw>& __x) {
157 for ( size_t __i = 0; __i < _Nw; __i++ ) {
158 _M_w[__i] ^= __x._M_w[__i];
162 void _M_do_left_shift(size_t __shift);
164 void _M_do_right_shift(size_t __shift);
167 for ( size_t __i = 0; __i < _Nw; __i++ ) {
168 _M_w[__i] = ~_M_w[__i];
173 for ( size_t __i = 0; __i < _Nw; __i++ ) {
174 _M_w[__i] = ~__STATIC_CAST(_WordT,0);
178 void _M_do_reset() { memset(_M_w, 0, _Nw * sizeof(_WordT)); }
180 bool _M_is_equal(const _Base_bitset<_Nw>& __x) const {
181 for (size_t __i = 0; __i < _Nw; ++__i) {
182 if (_M_w[__i] != __x._M_w[__i])
188 bool _M_is_any() const {
189 for ( size_t __i = 0; __i < _Nw ; __i++ ) {
190 if ( _M_w[__i] != __STATIC_CAST(_WordT,0) )
196 size_t _M_do_count() const {
197 const unsigned char* __byte_ptr = (const unsigned char*)_M_w;
198 const unsigned char* __end_ptr = (const unsigned char*)(_M_w+_Nw);
200 return _Bs_G::_S_count(__byte_ptr, __end_ptr);
203 unsigned long _M_do_to_ulong() const;
205 // find first "on" bit
206 size_t _M_do_find_first(size_t __not_found) const;
208 // find the next "on" bit that follows "prev"
209 size_t _M_do_find_next(size_t __prev, size_t __not_found) const;
213 // Base class: specialization for a single word.
216 struct _Base_bitset<1UL> {
217 typedef unsigned long _WordT;
218 typedef _Base_bitset<1UL> _Self;
222 _Base_bitset( void ) : _M_w(0) {}
223 _Base_bitset(unsigned long __val) : _M_w(__val) {}
225 static size_t _STLP_CALL _S_whichword( size_t __pos ) {
226 return __pos / __BITS_PER_WORD ;
228 static size_t _STLP_CALL _S_whichbyte( size_t __pos ) {
229 return (__pos % __BITS_PER_WORD) / CHAR_BIT;
231 static size_t _STLP_CALL _S_whichbit( size_t __pos ) {
232 return __pos % __BITS_PER_WORD;
234 static _WordT _STLP_CALL _S_maskbit( size_t __pos ) {
235 return (__STATIC_CAST(_WordT,1)) << _S_whichbit(__pos);
238 _WordT& _M_getword(size_t) { return _M_w; }
239 _WordT _M_getword(size_t) const { return _M_w; }
241 _WordT& _M_hiword() { return _M_w; }
242 _WordT _M_hiword() const { return _M_w; }
244 void _M_do_and(const _Self& __x) { _M_w &= __x._M_w; }
245 void _M_do_or(const _Self& __x) { _M_w |= __x._M_w; }
246 void _M_do_xor(const _Self& __x) { _M_w ^= __x._M_w; }
247 void _M_do_left_shift(size_t __shift) { _M_w <<= __shift; }
248 void _M_do_right_shift(size_t __shift) { _M_w >>= __shift; }
249 void _M_do_flip() { _M_w = ~_M_w; }
250 void _M_do_set() { _M_w = ~__STATIC_CAST(_WordT,0); }
251 void _M_do_reset() { _M_w = 0; }
253 bool _M_is_equal(const _Self& __x) const {
254 return _M_w == __x._M_w;
256 bool _M_is_any() const {
260 size_t _M_do_count() const {
261 const unsigned char* __byte_ptr = (const unsigned char*)&_M_w;
262 const unsigned char* __end_ptr = ((const unsigned char*)&_M_w)+sizeof(_M_w);
263 return _Bs_G::_S_count(__byte_ptr, __end_ptr);
266 unsigned long _M_do_to_ulong() const { return _M_w; }
268 inline size_t _M_do_find_first(size_t __not_found) const;
270 // find the next "on" bit that follows "prev"
271 inline size_t _M_do_find_next(size_t __prev, size_t __not_found) const;
275 // ------------------------------------------------------------
277 // Definitions of should-be-non-inline functions from the single-word version of
281 _Base_bitset<1UL>::_M_do_find_first(size_t __not_found) const {
282 // typedef unsigned long _WordT;
283 _WordT __thisword = _M_w;
285 if ( __thisword != __STATIC_CAST(_WordT,0) ) {
286 // find byte within word
287 for ( size_t __j = 0; __j < sizeof(_WordT); __j++ ) {
288 unsigned char __this_byte
289 = __STATIC_CAST(unsigned char,(__thisword & (~(unsigned char)0)));
291 return __j*CHAR_BIT + _Bs_G::_S_first_one(__this_byte);
293 __thisword >>= CHAR_BIT;
296 // not found, so return a value that indicates failure.
301 _Base_bitset<1UL>::_M_do_find_next(size_t __prev,
302 size_t __not_found ) const {
303 // make bound inclusive
306 // check out of bounds
307 if ( __prev >= __BITS_PER_WORD )
310 // search first (and only) word
311 _WordT __thisword = _M_w;
313 // mask off bits below bound
314 __thisword &= (~__STATIC_CAST(_WordT,0)) << _S_whichbit(__prev);
316 if ( __thisword != __STATIC_CAST(_WordT,0) ) {
317 // find byte within word
318 // get first byte into place
319 __thisword >>= _S_whichbyte(__prev) * CHAR_BIT;
320 for ( size_t __j = _S_whichbyte(__prev); __j < sizeof(_WordT); __j++ ) {
321 unsigned char __this_byte
322 = __STATIC_CAST(unsigned char,(__thisword & (~(unsigned char)0)));
324 return __j*CHAR_BIT + _Bs_G::_S_first_one(__this_byte);
326 __thisword >>= CHAR_BIT;
330 // not found, so return a value that indicates failure.
332 } // end _M_do_find_next
335 // ------------------------------------------------------------
336 // Helper class to zero out the unused high-order bits in the highest word.
338 template <size_t _Extrabits> struct _Sanitize {
339 static void _STLP_CALL _M_do_sanitize(unsigned long& __val)
340 { __val &= ~((~__STATIC_CAST(unsigned long,0)) << _Extrabits); }
343 _STLP_TEMPLATE_NULL struct _Sanitize<0UL> {
344 static void _STLP_CALL _M_do_sanitize(unsigned long) {}
347 _STLP_MOVE_TO_STD_NAMESPACE
349 // ------------------------------------------------------------
351 // _Nb may be any nonzero number of type size_t.
353 class bitset : public _STLP_PRIV _Base_bitset<__BITSET_WORDS(_Nb) > {
355 enum { _Words = __BITSET_WORDS(_Nb) } ;
358 typedef _STLP_PRIV _Base_bitset< _Words > _Base;
360 void _M_do_sanitize() {
361 _STLP_PRIV _Sanitize<_Nb%__BITS_PER_WORD >::_M_do_sanitize(this->_M_hiword());
364 typedef unsigned long _WordT;
366 friend struct reference;
370 typedef _STLP_PRIV _Base_bitset<_Words > _Bitset_base;
371 typedef bitset<_Nb> _Bitset;
376 // should be left undefined
379 reference( _Bitset& __b, size_t __pos ) {
380 _M_wp = &__b._M_getword(__pos);
381 _M_bpos = _Bitset_base::_S_whichbit(__pos);
388 reference& operator=(bool __x) {
390 *_M_wp |= _Bitset_base::_S_maskbit(_M_bpos);
392 *_M_wp &= ~_Bitset_base::_S_maskbit(_M_bpos);
397 // for b[i] = b[__j];
398 reference& operator=(const reference& __j) {
399 if ( (*(__j._M_wp) & _Bitset_base::_S_maskbit(__j._M_bpos)) )
400 *_M_wp |= _Bitset_base::_S_maskbit(_M_bpos);
402 *_M_wp &= ~_Bitset_base::_S_maskbit(_M_bpos);
408 bool operator~() const { return (*(_M_wp) & _Bitset_base::_S_maskbit(_M_bpos)) == 0; }
411 operator bool() const { return (*(_M_wp) & _Bitset_base::_S_maskbit(_M_bpos)) != 0; }
415 *_M_wp ^= _Bitset_base::_S_maskbit(_M_bpos);
420 // 23.3.5.1 constructors:
423 bitset(unsigned long __val) : _STLP_PRIV _Base_bitset<_Words>(__val) { _M_do_sanitize(); }
425 #if defined (_STLP_MEMBER_TEMPLATES)
426 template<class _CharT, class _Traits, class _Alloc>
427 explicit bitset(const basic_string<_CharT,_Traits,_Alloc>& __s,
429 : _STLP_PRIV _Base_bitset<_Words >() {
430 if (__pos > __s.size())
431 __stl_throw_out_of_range("bitset");
432 _M_copy_from_string(__s, __pos,
433 basic_string<_CharT, _Traits, _Alloc>::npos);
435 template<class _CharT, class _Traits, class _Alloc>
436 bitset(const basic_string<_CharT, _Traits, _Alloc>& __s,
439 : _STLP_PRIV _Base_bitset<_Words >() {
440 if (__pos > __s.size())
441 __stl_throw_out_of_range("bitset");
442 _M_copy_from_string(__s, __pos, __n);
444 #else /* _STLP_MEMBER_TEMPLATES */
445 explicit bitset(const string& __s,
447 size_t __n = (size_t)-1)
448 : _STLP_PRIV _Base_bitset<_Words >() {
449 if (__pos > __s.size())
450 __stl_throw_out_of_range("bitset");
451 _M_copy_from_string(__s, __pos, __n);
453 #endif /* _STLP_MEMBER_TEMPLATES */
455 // 23.3.5.2 bitset operations:
456 bitset<_Nb>& operator&=(const bitset<_Nb>& __rhs) {
457 this->_M_do_and(__rhs);
461 bitset<_Nb>& operator|=(const bitset<_Nb>& __rhs) {
462 this->_M_do_or(__rhs);
466 bitset<_Nb>& operator^=(const bitset<_Nb>& __rhs) {
467 this->_M_do_xor(__rhs);
471 bitset<_Nb>& operator<<=(size_t __pos) {
472 this->_M_do_left_shift(__pos);
473 this->_M_do_sanitize();
477 bitset<_Nb>& operator>>=(size_t __pos) {
478 this->_M_do_right_shift(__pos);
479 this->_M_do_sanitize();
485 // Versions of single-bit set, reset, flip, test with no range checking.
488 bitset<_Nb>& _Unchecked_set(size_t __pos) {
489 this->_M_getword(__pos) |= _STLP_PRIV _Base_bitset<_Words > ::_S_maskbit(__pos);
493 bitset<_Nb>& _Unchecked_set(size_t __pos, int __val) {
495 this->_M_getword(__pos) |= this->_S_maskbit(__pos);
497 this->_M_getword(__pos) &= ~ this->_S_maskbit(__pos);
502 bitset<_Nb>& _Unchecked_reset(size_t __pos) {
503 this->_M_getword(__pos) &= ~ this->_S_maskbit(__pos);
507 bitset<_Nb>& _Unchecked_flip(size_t __pos) {
508 this->_M_getword(__pos) ^= this->_S_maskbit(__pos);
512 bool _Unchecked_test(size_t __pos) const {
513 return (this->_M_getword(__pos) & this->_S_maskbit(__pos)) != __STATIC_CAST(_WordT,0);
516 // Set, reset, and flip.
520 this->_M_do_sanitize();
524 bitset<_Nb>& set(size_t __pos) {
526 __stl_throw_out_of_range("bitset");
527 return _Unchecked_set(__pos);
530 bitset<_Nb>& set(size_t __pos, int __val) {
532 __stl_throw_out_of_range("bitset");
533 return _Unchecked_set(__pos, __val);
536 bitset<_Nb>& reset() {
541 bitset<_Nb>& reset(size_t __pos) {
543 __stl_throw_out_of_range("bitset");
545 return _Unchecked_reset(__pos);
548 bitset<_Nb>& flip() {
550 this->_M_do_sanitize();
554 bitset<_Nb>& flip(size_t __pos) {
556 __stl_throw_out_of_range("bitset");
558 return _Unchecked_flip(__pos);
561 bitset<_Nb> operator~() const {
562 return bitset<_Nb>(*this).flip();
567 reference operator[](size_t __pos) { return reference(*this,__pos); }
568 bool operator[](size_t __pos) const { return _Unchecked_test(__pos); }
570 unsigned long to_ulong() const { return this->_M_do_to_ulong(); }
572 #if defined (_STLP_MEMBER_TEMPLATES) && !defined (_STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS)
573 template <class _CharT, class _Traits, class _Alloc>
574 basic_string<_CharT, _Traits, _Alloc> to_string() const {
575 basic_string<_CharT, _Traits, _Alloc> __result;
576 _M_copy_to_string(__result);
580 string to_string() const {
582 _M_copy_to_string(__result);
585 #endif /* _STLP_EXPLICIT_FUNCTION_TMPL_ARGS */
587 size_t count() const { return this->_M_do_count(); }
589 size_t size() const { return _Nb; }
591 bool operator==(const bitset<_Nb>& __rhs) const {
592 return this->_M_is_equal(__rhs);
594 bool operator!=(const bitset<_Nb>& __rhs) const {
595 return !this->_M_is_equal(__rhs);
598 bool test(size_t __pos) const {
600 __stl_throw_out_of_range("bitset");
602 return _Unchecked_test(__pos);
605 bool any() const { return this->_M_is_any(); }
606 bool none() const { return !this->_M_is_any(); }
608 bitset<_Nb> operator<<(size_t __pos) const {
609 bitset<_Nb> __result(*this);
610 __result <<= __pos ; return __result;
612 bitset<_Nb> operator>>(size_t __pos) const {
613 bitset<_Nb> __result(*this);
614 __result >>= __pos ; return __result;
617 #if !defined (_STLP_NO_EXTENSIONS)
619 // EXTENSIONS: bit-find operations. These operations are
620 // experimental, and are subject to change or removal in future
624 // find the index of the first "on" bit
625 size_t _Find_first() const
626 { return this->_M_do_find_first(_Nb); }
628 // find the index of the next "on" bit after prev
629 size_t _Find_next( size_t __prev ) const
630 { return this->_M_do_find_next(__prev, _Nb); }
634 // Definitions of should-be non-inline member functions.
636 #if defined (_STLP_MEMBER_TEMPLATES)
637 template<class _CharT, class _Traits, class _Alloc>
638 void _M_copy_from_string(const basic_string<_CharT,_Traits,_Alloc>& __s,
639 size_t __pos, size_t __n) {
641 void _M_copy_from_string(const string& __s,
642 size_t __pos, size_t __n) {
643 typedef typename string::traits_type _Traits;
647 const size_t __Nbits = (min) (__tmp, (min) (__n, __s.size() - __pos));
648 for ( size_t __i= 0; __i < __Nbits; ++__i) {
649 typename _Traits::int_type __k = _Traits::to_int_type(__s[__pos + __Nbits - __i - 1]);
654 __stl_throw_invalid_argument("bitset");
658 #if defined (_STLP_MEMBER_TEMPLATES)
659 template <class _CharT, class _Traits, class _Alloc>
660 void _M_copy_to_string(basic_string<_CharT, _Traits, _Alloc>& __s) const
662 void _M_copy_to_string(string& __s) const
665 __s.assign(_Nb, '0');
667 for (size_t __i = 0; __i < _Nb; ++__i) {
668 if (_Unchecked_test(__i))
669 __s[_Nb - 1 - __i] = '1';
673 #if !defined (_STLP_MEMBER_TEMPLATES) && !defined (_STLP_NO_WCHAR_T)
674 void _M_copy_to_string(wstring& __s) const {
675 __s.assign(_Nb, '0');
677 for (size_t __i = 0; __i < _Nb; ++__i) {
678 if (_Unchecked_test(__i))
679 __s[_Nb - 1 - __i] = '1';
684 #if defined (_STLP_NON_TYPE_TMPL_PARAM_BUG)
685 bitset<_Nb> operator&(const bitset<_Nb>& __y) const {
686 bitset<_Nb> __result(*this);
690 bitset<_Nb> operator|(const bitset<_Nb>& __y) const {
691 bitset<_Nb> __result(*this);
695 bitset<_Nb> operator^(const bitset<_Nb>& __y) const {
696 bitset<_Nb> __result(*this);
703 // ------------------------------------------------------------
705 // 23.3.5.3 bitset operations:
707 #if ! defined (_STLP_NON_TYPE_TMPL_PARAM_BUG)
708 template <size_t _Nb>
709 inline bitset<_Nb> _STLP_CALL
710 operator&(const bitset<_Nb>& __x,
711 const bitset<_Nb>& __y) {
712 bitset<_Nb> __result(__x);
718 template <size_t _Nb>
719 inline bitset<_Nb> _STLP_CALL
720 operator|(const bitset<_Nb>& __x,
721 const bitset<_Nb>& __y) {
722 bitset<_Nb> __result(__x);
727 template <size_t _Nb>
728 inline bitset<_Nb> _STLP_CALL
729 operator^(const bitset<_Nb>& __x,
730 const bitset<_Nb>& __y) {
731 bitset<_Nb> __result(__x);
736 #if !defined (_STLP_USE_NO_IOSTREAMS)
740 # if !(defined (_STLP_MSVC) && (_STLP_MSVC < 1300)) && \
741 !(defined(__SUNPRO_CC) && (__SUNPRO_CC < 0x500))
743 #ifndef _STLP_INTERNAL_IOSFWD
744 # include <stl/_iosfwd.h>
747 _STLP_BEGIN_NAMESPACE
749 template <class _CharT, class _Traits, size_t _Nb>
750 basic_istream<_CharT, _Traits>& _STLP_CALL
751 operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Nb>& __x);
753 template <class _CharT, class _Traits, size_t _Nb>
754 basic_ostream<_CharT, _Traits>& _STLP_CALL
755 operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Nb>& __x);
759 #ifndef _STLP_STRING_IO_H
760 # include <stl/_string_io.h> //includes _istream.h and _ostream.h
763 _STLP_BEGIN_NAMESPACE
765 template <size_t _Nb>
767 operator>>(istream& __is, bitset<_Nb>& __x) {
768 typedef typename string::traits_type _Traits;
773 typename istream::sentry __sentry(__is);
775 streambuf* __buf = __is.rdbuf();
776 for (size_t __i = 0; __i < _Nb; ++__i) {
777 static typename _Traits::int_type __eof = _Traits::eof();
779 typename _Traits::int_type __c1 = __buf->sbumpc();
780 if (_Traits::eq_int_type(__c1, __eof)) {
781 __is.setstate(ios_base::eofbit);
785 typename _Traits::char_type __c2 = _Traits::to_char_type(__c1);
786 char __c = __is.narrow(__c2, '*');
788 if (__c == '0' || __c == '1')
789 __tmp.push_back(__c);
790 else if (_Traits::eq_int_type(__buf->sputbackc(__c2), __eof)) {
791 __is.setstate(ios_base::failbit);
798 __is.setstate(ios_base::failbit);
800 __x._M_copy_from_string(__tmp, __STATIC_CAST(size_t,0), _Nb);
806 template <size_t _Nb>
808 operator<<(ostream& __os, const bitset<_Nb>& __x) {
810 __x._M_copy_to_string(__tmp);
811 return __os << __tmp;
814 # if !defined (_STLP_NO_WCHAR_T)
816 template <size_t _Nb>
818 operator>>(wistream& __is, bitset<_Nb>& __x) {
819 typedef typename wstring::traits_type _Traits;
824 typename wistream::sentry __sentry(__is);
826 wstreambuf* __buf = __is.rdbuf();
827 for (size_t __i = 0; __i < _Nb; ++__i) {
828 static typename _Traits::int_type __eof = _Traits::eof();
830 typename _Traits::int_type __c1 = __buf->sbumpc();
831 if (_Traits::eq_int_type(__c1, __eof)) {
832 __is.setstate(ios_base::eofbit);
836 typename _Traits::char_type __c2 = _Traits::to_char_type(__c1);
837 char __c = __is.narrow(__c2, '*');
839 if (__c == '0' || __c == '1')
840 __tmp.push_back(__c);
841 else if (_Traits::eq_int_type(__buf->sputbackc(__c2), __eof)) {
842 __is.setstate(ios_base::failbit);
849 __is.setstate(ios_base::failbit);
851 __x._M_copy_from_string(__tmp, __STATIC_CAST(size_t,0), _Nb);
857 template <size_t _Nb>
859 operator<<(wostream& __os, const bitset<_Nb>& __x) {
861 __x._M_copy_to_string(__tmp);
862 return __os << __tmp;
865 # endif /* _STLP_NO_WCHAR_T */
869 #endif /* _STLP_NON_TYPE_TMPL_PARAM_BUG */
875 #undef __BITS_PER_WORD
876 #undef __BITSET_WORDS
878 #if !defined (_STLP_LINK_TIME_INSTANTIATION)
879 # include <stl/_bitset.c>
882 #endif /* _STLP_BITSET_H */