1 // <bitset> -*- C++ -*-
3 // Copyright (C) 2001 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
32 * Silicon Graphics Computer Systems, Inc.
34 * Permission to use, copy, modify, distribute and sell this software
35 * and its documentation for any purpose is hereby granted without fee,
36 * provided that the above copyright notice appear in all copies and
37 * that both that copyright notice and this permission notice appear
38 * in supporting documentation. Silicon Graphics makes no
39 * representations about the suitability of this software for any
40 * purpose. It is provided "as is" without express or implied warranty.
43 /** @file std_bitset.h
44 * This is an internal header file, included by other library headers.
45 * You should not attempt to use it directly.
48 #ifndef __GLIBCPP_BITSET
49 #define __GLIBCPP_BITSET
51 #pragma GCC system_header
53 // A bitset of size N has N % (sizeof(unsigned long) * CHAR_BIT) unused
54 // bits. (They are the high- order bits in the highest word.) It is
55 // a class invariant of class bitset<> that those unused bits are
58 // Most of the actual code isn't contained in bitset<> itself, but in the
59 // base class _Base_bitset. The base class works with whole words, not with
60 // individual bits. This allows us to specialize _Base_bitset for the
61 // important special case where the bitset is only a single word.
64 #include <bits/std_cstddef.h> // for size_t
65 #include <bits/std_cstring.h> // for memset
66 #include <bits/std_string.h>
67 #include <bits/std_stdexcept.h>
68 #include <bits/functexcept.h> // for invalid_argument, out_of_range,
70 #include <bits/std_ostream.h> // for ostream (operator<<)
71 #include <bits/std_istream.h> // for istream (operator>>)
73 #define _GLIBCPP_BITSET_BITS_PER_WORD (CHAR_BIT*sizeof(unsigned long))
74 #define __BITSET_WORDS(__n) \
75 ((__n) < 1 ? 1 : ((__n) + _GLIBCPP_BITSET_BITS_PER_WORD - 1)/_GLIBCPP_BITSET_BITS_PER_WORD)
80 // structure to aid in counting bits
81 template<bool __dummy
>
83 static unsigned char _S_bit_count
[256];
86 // Mapping from 8 bit unsigned integers to the index of the first one
88 template<bool __dummy
>
90 static unsigned char _S_first_one
[256];
94 // Base class: general case.
99 typedef unsigned long _WordT
;
101 _WordT _M_w
[_Nw
]; // 0 is the least significant word.
103 _Base_bitset( void ) { _M_do_reset(); }
104 _Base_bitset(unsigned long __val
) {
109 static size_t _S_whichword( size_t __pos
)
110 { return __pos
/ _GLIBCPP_BITSET_BITS_PER_WORD
; }
111 static size_t _S_whichbyte( size_t __pos
)
112 { return (__pos
% _GLIBCPP_BITSET_BITS_PER_WORD
) / CHAR_BIT
; }
113 static size_t _S_whichbit( size_t __pos
)
114 { return __pos
% _GLIBCPP_BITSET_BITS_PER_WORD
; }
115 static _WordT
_S_maskbit( size_t __pos
)
116 { return (static_cast<_WordT
>(1)) << _S_whichbit(__pos
); }
118 _WordT
& _M_getword(size_t __pos
) { return _M_w
[_S_whichword(__pos
)]; }
119 _WordT
_M_getword(size_t __pos
) const { return _M_w
[_S_whichword(__pos
)]; }
121 _WordT
& _M_hiword() { return _M_w
[_Nw
- 1]; }
122 _WordT
_M_hiword() const { return _M_w
[_Nw
- 1]; }
124 void _M_do_and(const _Base_bitset
<_Nw
>& __x
) {
125 for ( size_t __i
= 0; __i
< _Nw
; __i
++ ) {
126 _M_w
[__i
] &= __x
._M_w
[__i
];
130 void _M_do_or(const _Base_bitset
<_Nw
>& __x
) {
131 for ( size_t __i
= 0; __i
< _Nw
; __i
++ ) {
132 _M_w
[__i
] |= __x
._M_w
[__i
];
136 void _M_do_xor(const _Base_bitset
<_Nw
>& __x
) {
137 for ( size_t __i
= 0; __i
< _Nw
; __i
++ ) {
138 _M_w
[__i
] ^= __x
._M_w
[__i
];
142 void _M_do_left_shift(size_t __shift
);
143 void _M_do_right_shift(size_t __shift
);
146 for ( size_t __i
= 0; __i
< _Nw
; __i
++ ) {
147 _M_w
[__i
] = ~_M_w
[__i
];
152 for ( size_t __i
= 0; __i
< _Nw
; __i
++ ) {
153 _M_w
[__i
] = ~static_cast<_WordT
>(0);
157 void _M_do_reset() { memset(_M_w
, 0, _Nw
* sizeof(_WordT
)); }
159 bool _M_is_equal(const _Base_bitset
<_Nw
>& __x
) const {
160 for (size_t __i
= 0; __i
< _Nw
; ++__i
) {
161 if (_M_w
[__i
] != __x
._M_w
[__i
])
167 bool _M_is_any() const {
168 for ( size_t __i
= 0; __i
< _Nw
; __i
++ ) {
169 if ( _M_w
[__i
] != static_cast<_WordT
>(0) )
175 size_t _M_do_count() const {
177 const unsigned char* __byte_ptr
= (const unsigned char*)_M_w
;
178 const unsigned char* __end_ptr
= (const unsigned char*)(_M_w
+_Nw
);
180 while ( __byte_ptr
< __end_ptr
) {
181 __result
+= _Bit_count
<true>::_S_bit_count
[*__byte_ptr
];
187 unsigned long _M_do_to_ulong() const;
189 // find first "on" bit
190 size_t _M_do_find_first(size_t __not_found
) const;
192 // find the next "on" bit that follows "prev"
193 size_t _M_do_find_next(size_t __prev
, size_t __not_found
) const;
197 // Definitions of non-inline functions from _Base_bitset.
201 void _Base_bitset
<_Nw
>::_M_do_left_shift(size_t __shift
)
204 const size_t __wshift
= __shift
/ _GLIBCPP_BITSET_BITS_PER_WORD
;
205 const size_t __offset
= __shift
% _GLIBCPP_BITSET_BITS_PER_WORD
;
208 for (size_t __n
= _Nw
- 1; __n
>= __wshift
; --__n
)
209 _M_w
[__n
] = _M_w
[__n
- __wshift
];
212 const size_t __sub_offset
= _GLIBCPP_BITSET_BITS_PER_WORD
- __offset
;
213 for (size_t __n
= _Nw
- 1; __n
> __wshift
; --__n
)
214 _M_w
[__n
] = (_M_w
[__n
- __wshift
] << __offset
) |
215 (_M_w
[__n
- __wshift
- 1] >> __sub_offset
);
216 _M_w
[__wshift
] = _M_w
[0] << __offset
;
219 fill(_M_w
+ 0, _M_w
+ __wshift
, static_cast<_WordT
>(0));
224 void _Base_bitset
<_Nw
>::_M_do_right_shift(size_t __shift
)
227 const size_t __wshift
= __shift
/ _GLIBCPP_BITSET_BITS_PER_WORD
;
228 const size_t __offset
= __shift
% _GLIBCPP_BITSET_BITS_PER_WORD
;
229 const size_t __limit
= _Nw
- __wshift
- 1;
232 for (size_t __n
= 0; __n
<= __limit
; ++__n
)
233 _M_w
[__n
] = _M_w
[__n
+ __wshift
];
236 const size_t __sub_offset
= _GLIBCPP_BITSET_BITS_PER_WORD
- __offset
;
237 for (size_t __n
= 0; __n
< __limit
; ++__n
)
238 _M_w
[__n
] = (_M_w
[__n
+ __wshift
] >> __offset
) |
239 (_M_w
[__n
+ __wshift
+ 1] << __sub_offset
);
240 _M_w
[__limit
] = _M_w
[_Nw
-1] >> __offset
;
243 fill(_M_w
+ __limit
+ 1, _M_w
+ _Nw
, static_cast<_WordT
>(0));
248 unsigned long _Base_bitset
<_Nw
>::_M_do_to_ulong() const
250 for (size_t __i
= 1; __i
< _Nw
; ++__i
)
252 __throw_overflow_error("bitset");
258 size_t _Base_bitset
<_Nw
>::_M_do_find_first(size_t __not_found
) const
260 for ( size_t __i
= 0; __i
< _Nw
; __i
++ ) {
261 _WordT __thisword
= _M_w
[__i
];
262 if ( __thisword
!= static_cast<_WordT
>(0) ) {
263 // find byte within word
264 for ( size_t __j
= 0; __j
< sizeof(_WordT
); __j
++ ) {
265 unsigned char __this_byte
266 = static_cast<unsigned char>(__thisword
& (~(unsigned char)0));
268 return __i
*_GLIBCPP_BITSET_BITS_PER_WORD
+ __j
*CHAR_BIT
+
269 _First_one
<true>::_S_first_one
[__this_byte
];
271 __thisword
>>= CHAR_BIT
;
275 // not found, so return an indication of failure.
281 _Base_bitset
<_Nw
>::_M_do_find_next(size_t __prev
, size_t __not_found
) const
283 // make bound inclusive
286 // check out of bounds
287 if ( __prev
>= _Nw
* _GLIBCPP_BITSET_BITS_PER_WORD
)
291 size_t __i
= _S_whichword(__prev
);
292 _WordT __thisword
= _M_w
[__i
];
294 // mask off bits below bound
295 __thisword
&= (~static_cast<_WordT
>(0)) << _S_whichbit(__prev
);
297 if ( __thisword
!= static_cast<_WordT
>(0) ) {
298 // find byte within word
299 // get first byte into place
300 __thisword
>>= _S_whichbyte(__prev
) * CHAR_BIT
;
301 for ( size_t __j
= _S_whichbyte(__prev
); __j
< sizeof(_WordT
); __j
++ ) {
302 unsigned char __this_byte
303 = static_cast<unsigned char>(__thisword
& (~(unsigned char)0));
305 return __i
*_GLIBCPP_BITSET_BITS_PER_WORD
+ __j
*CHAR_BIT
+
306 _First_one
<true>::_S_first_one
[__this_byte
];
308 __thisword
>>= CHAR_BIT
;
312 // check subsequent words
314 for ( ; __i
< _Nw
; __i
++ ) {
315 __thisword
= _M_w
[__i
];
316 if ( __thisword
!= static_cast<_WordT
>(0) ) {
317 // find byte within word
318 for ( size_t __j
= 0; __j
< sizeof(_WordT
); __j
++ ) {
319 unsigned char __this_byte
320 = static_cast<unsigned char>(__thisword
& (~(unsigned char)0));
322 return __i
*_GLIBCPP_BITSET_BITS_PER_WORD
+ __j
*CHAR_BIT
+
323 _First_one
<true>::_S_first_one
[__this_byte
];
325 __thisword
>>= CHAR_BIT
;
330 // not found, so return an indication of failure.
332 } // end _M_do_find_next
335 // ------------------------------------------------------------
338 // Base class: specialization for a single word.
341 template<> struct _Base_bitset
<1> {
342 typedef unsigned long _WordT
;
345 _Base_bitset( void ) : _M_w(0) {}
346 _Base_bitset(unsigned long __val
) : _M_w(__val
) {}
348 static size_t _S_whichword( size_t __pos
)
349 { return __pos
/ _GLIBCPP_BITSET_BITS_PER_WORD
; }
350 static size_t _S_whichbyte( size_t __pos
)
351 { return (__pos
% _GLIBCPP_BITSET_BITS_PER_WORD
) / CHAR_BIT
; }
352 static size_t _S_whichbit( size_t __pos
)
353 { return __pos
% _GLIBCPP_BITSET_BITS_PER_WORD
; }
354 static _WordT
_S_maskbit( size_t __pos
)
355 { return (static_cast<_WordT
>(1)) << _S_whichbit(__pos
); }
357 _WordT
& _M_getword(size_t) { return _M_w
; }
358 _WordT
_M_getword(size_t) const { return _M_w
; }
360 _WordT
& _M_hiword() { return _M_w
; }
361 _WordT
_M_hiword() const { return _M_w
; }
363 void _M_do_and(const _Base_bitset
<1>& __x
) { _M_w
&= __x
._M_w
; }
364 void _M_do_or(const _Base_bitset
<1>& __x
) { _M_w
|= __x
._M_w
; }
365 void _M_do_xor(const _Base_bitset
<1>& __x
) { _M_w
^= __x
._M_w
; }
366 void _M_do_left_shift(size_t __shift
) { _M_w
<<= __shift
; }
367 void _M_do_right_shift(size_t __shift
) { _M_w
>>= __shift
; }
368 void _M_do_flip() { _M_w
= ~_M_w
; }
369 void _M_do_set() { _M_w
= ~static_cast<_WordT
>(0); }
370 void _M_do_reset() { _M_w
= 0; }
372 bool _M_is_equal(const _Base_bitset
<1>& __x
) const
373 { return _M_w
== __x
._M_w
; }
374 bool _M_is_any() const
375 { return _M_w
!= 0; }
377 size_t _M_do_count() const {
379 const unsigned char* __byte_ptr
= (const unsigned char*)&_M_w
;
380 const unsigned char* __end_ptr
381 = ((const unsigned char*)&_M_w
)+sizeof(_M_w
);
382 while ( __byte_ptr
< __end_ptr
) {
383 __result
+= _Bit_count
<true>::_S_bit_count
[*__byte_ptr
];
389 unsigned long _M_do_to_ulong() const { return _M_w
; }
391 size_t _M_do_find_first(size_t __not_found
) const;
393 // find the next "on" bit that follows "prev"
394 size_t _M_do_find_next(size_t __prev
, size_t __not_found
) const;
399 // ------------------------------------------------------------
400 // Helper class to zero out the unused high-order bits in the highest word.
402 template <size_t _Extrabits
> struct _Sanitize
{
403 static void _M_do_sanitize(unsigned long& __val
)
404 { __val
&= ~((~static_cast<unsigned long>(0)) << _Extrabits
); }
407 template<> struct _Sanitize
<0> {
408 static void _M_do_sanitize(unsigned long) {}
413 // ------------------------------------------------------------
415 // _Nb may be any nonzero number of type size_t.
418 class bitset
: private _Base_bitset
<__BITSET_WORDS(_Nb
)>
421 typedef _Base_bitset
<__BITSET_WORDS(_Nb
)> _Base
;
422 typedef unsigned long _WordT
;
425 void _M_do_sanitize() {
426 _Sanitize
<_Nb
%_GLIBCPP_BITSET_BITS_PER_WORD
>::_M_do_sanitize(this->_M_hiword());
433 friend class reference
;
445 reference( bitset
& __b
, size_t __pos
) {
446 _M_wp
= &__b
._M_getword(__pos
);
447 _M_bpos
= _Base::_S_whichbit(__pos
);
453 reference
& operator=(bool __x
) {
455 *_M_wp
|= _Base::_S_maskbit(_M_bpos
);
457 *_M_wp
&= ~_Base::_S_maskbit(_M_bpos
);
462 // for b[i] = b[__j];
463 reference
& operator=(const reference
& __j
) {
464 if ( (*(__j
._M_wp
) & _Base::_S_maskbit(__j
._M_bpos
)) )
465 *_M_wp
|= _Base::_S_maskbit(_M_bpos
);
467 *_M_wp
&= ~_Base::_S_maskbit(_M_bpos
);
473 bool operator~() const
474 { return (*(_M_wp
) & _Base::_S_maskbit(_M_bpos
)) == 0; }
477 operator bool() const
478 { return (*(_M_wp
) & _Base::_S_maskbit(_M_bpos
)) != 0; }
482 *_M_wp
^= _Base::_S_maskbit(_M_bpos
);
487 // 23.3.5.1 constructors:
489 bitset(unsigned long __val
) : _Base_bitset
<__BITSET_WORDS(_Nb
)>(__val
)
490 { _M_do_sanitize(); }
492 template<class _CharT
, class _Traits
, class _Alloc
>
493 explicit bitset(const basic_string
<_CharT
, _Traits
, _Alloc
>& __s
,
497 if (__pos
> __s
.size())
498 __throw_out_of_range("bitset");
499 _M_copy_from_string(__s
, __pos
,
500 basic_string
<_CharT
, _Traits
, _Alloc
>::npos
);
502 template<class _CharT
, class _Traits
, class _Alloc
>
503 bitset(const basic_string
<_CharT
, _Traits
, _Alloc
>& __s
,
508 if (__pos
> __s
.size())
509 __throw_out_of_range("bitset");
510 _M_copy_from_string(__s
, __pos
, __n
);
513 // 23.3.5.2 bitset operations:
514 bitset
<_Nb
>& operator&=(const bitset
<_Nb
>& __rhs
) {
515 this->_M_do_and(__rhs
);
519 bitset
<_Nb
>& operator|=(const bitset
<_Nb
>& __rhs
) {
520 this->_M_do_or(__rhs
);
524 bitset
<_Nb
>& operator^=(const bitset
<_Nb
>& __rhs
) {
525 this->_M_do_xor(__rhs
);
529 bitset
<_Nb
>& operator<<=(size_t __pos
) {
530 this->_M_do_left_shift(__pos
);
531 this->_M_do_sanitize();
535 bitset
<_Nb
>& operator>>=(size_t __pos
) {
536 this->_M_do_right_shift(__pos
);
537 this->_M_do_sanitize();
543 // Versions of single-bit set, reset, flip, test with no range checking.
546 bitset
<_Nb
>& _Unchecked_set(size_t __pos
) {
547 this->_M_getword(__pos
) |= _Base::_S_maskbit(__pos
);
551 bitset
<_Nb
>& _Unchecked_set(size_t __pos
, int __val
) {
553 this->_M_getword(__pos
) |= _Base::_S_maskbit(__pos
);
555 this->_M_getword(__pos
) &= ~_Base::_S_maskbit(__pos
);
560 bitset
<_Nb
>& _Unchecked_reset(size_t __pos
) {
561 this->_M_getword(__pos
) &= ~_Base::_S_maskbit(__pos
);
565 bitset
<_Nb
>& _Unchecked_flip(size_t __pos
) {
566 this->_M_getword(__pos
) ^= _Base::_S_maskbit(__pos
);
570 bool _Unchecked_test(size_t __pos
) const {
571 return (this->_M_getword(__pos
) & _Base::_S_maskbit(__pos
))
572 != static_cast<_WordT
>(0);
575 // Set, reset, and flip.
579 this->_M_do_sanitize();
583 bitset
<_Nb
>& set(size_t __pos
, bool __val
= true) {
585 __throw_out_of_range("bitset");
587 return _Unchecked_set(__pos
, __val
);
590 bitset
<_Nb
>& reset() {
595 bitset
<_Nb
>& reset(size_t __pos
) {
597 __throw_out_of_range("bitset");
599 return _Unchecked_reset(__pos
);
602 bitset
<_Nb
>& flip() {
604 this->_M_do_sanitize();
608 bitset
<_Nb
>& flip(size_t __pos
) {
610 __throw_out_of_range("bitset");
612 return _Unchecked_flip(__pos
);
615 bitset
<_Nb
> operator~() const {
616 return bitset
<_Nb
>(*this).flip();
621 // _GLIBCPP_RESOLVE_LIB_DEFECTS Note that this implementation already
622 // resolves DR 11 (items 1 and 2), but does not do the range-checking
623 // required by that DR's resolution. -pme
624 reference
operator[](size_t __pos
) { return reference(*this,__pos
); }
625 bool operator[](size_t __pos
) const { return _Unchecked_test(__pos
); }
627 unsigned long to_ulong() const { return this->_M_do_to_ulong(); }
629 template <class _CharT
, class _Traits
, class _Alloc
>
630 basic_string
<_CharT
, _Traits
, _Alloc
> to_string() const {
631 basic_string
<_CharT
, _Traits
, _Alloc
> __result
;
632 _M_copy_to_string(__result
);
636 // Helper functions for string operations.
637 template<class _CharT
, class _Traits
, class _Alloc
>
638 void _M_copy_from_string(const basic_string
<_CharT
,_Traits
,_Alloc
>& __s
,
642 template<class _CharT
, class _Traits
, class _Alloc
>
643 void _M_copy_to_string(basic_string
<_CharT
,_Traits
,_Alloc
>&) const;
645 size_t count() const { return this->_M_do_count(); }
647 size_t size() const { return _Nb
; }
649 bool operator==(const bitset
<_Nb
>& __rhs
) const {
650 return this->_M_is_equal(__rhs
);
652 bool operator!=(const bitset
<_Nb
>& __rhs
) const {
653 return !this->_M_is_equal(__rhs
);
656 bool test(size_t __pos
) const {
658 __throw_out_of_range("bitset");
660 return _Unchecked_test(__pos
);
663 bool any() const { return this->_M_is_any(); }
664 bool none() const { return !this->_M_is_any(); }
666 bitset
<_Nb
> operator<<(size_t __pos
) const
667 { return bitset
<_Nb
>(*this) <<= __pos
; }
668 bitset
<_Nb
> operator>>(size_t __pos
) const
669 { return bitset
<_Nb
>(*this) >>= __pos
; }
672 // EXTENSIONS: bit-find operations. These operations are
673 // experimental, and are subject to change or removal in future
677 // find the index of the first "on" bit
678 size_t _Find_first() const
679 { return this->_M_do_find_first(_Nb
); }
681 // find the index of the next "on" bit after prev
682 size_t _Find_next( size_t __prev
) const
683 { return this->_M_do_find_next(__prev
, _Nb
); }
688 // Definitions of non-inline member functions.
691 template <size_t _Nb
>
692 template<class _CharT
, class _Traits
, class _Alloc
>
694 ::_M_copy_from_string(const basic_string
<_CharT
,_Traits
,_Alloc
>& __s
,
699 const size_t __nbits
= min(_Nb
, min(__n
, __s
.size() - __pos
));
700 for (size_t __i
= 0; __i
< __nbits
; ++__i
) {
701 switch(__s
[__pos
+ __nbits
- __i
- 1]) {
708 __throw_invalid_argument("bitset");
713 template <size_t _Nb
>
714 template <class _CharT
, class _Traits
, class _Alloc
>
716 ::_M_copy_to_string(basic_string
<_CharT
, _Traits
, _Alloc
>& __s
) const
718 __s
.assign(_Nb
, '0');
720 for (size_t __i
= 0; __i
< _Nb
; ++__i
)
721 if (_Unchecked_test(__i
))
722 __s
[_Nb
- 1 - __i
] = '1';
725 // ------------------------------------------------------------
728 // 23.3.5.3 bitset operations:
731 template <size_t _Nb
>
732 inline bitset
<_Nb
> operator&(const bitset
<_Nb
>& __x
, const bitset
<_Nb
>& __y
) {
733 bitset
<_Nb
> __result(__x
);
739 template <size_t _Nb
>
740 inline bitset
<_Nb
> operator|(const bitset
<_Nb
>& __x
, const bitset
<_Nb
>& __y
) {
741 bitset
<_Nb
> __result(__x
);
746 template <size_t _Nb
>
747 inline bitset
<_Nb
> operator^(const bitset
<_Nb
>& __x
, const bitset
<_Nb
>& __y
) {
748 bitset
<_Nb
> __result(__x
);
753 template <class _CharT
, class _Traits
, size_t _Nb
>
754 basic_istream
<_CharT
, _Traits
>&
755 operator>>(basic_istream
<_CharT
, _Traits
>& __is
, bitset
<_Nb
>& __x
)
757 typedef typename
_Traits::char_type char_type
;
758 basic_string
<_CharT
, _Traits
> __tmp
;
762 typename basic_istream
<_CharT
, _Traits
>::sentry
__sentry(__is
);
764 basic_streambuf
<_CharT
, _Traits
>* __buf
= __is
.rdbuf();
765 for (size_t __i
= 0; __i
< _Nb
; ++__i
) {
766 static typename
_Traits::int_type __eof
= _Traits::eof();
768 typename
_Traits::int_type __c1
= __buf
->sbumpc();
769 if (_Traits::eq_int_type(__c1
, __eof
)) {
770 __is
.setstate(ios_base::eofbit
);
774 char_type __c2
= _Traits::to_char_type(__c1
);
775 char_type __c
= __is
.narrow(__c2
, '*');
777 if (__c
== '0' || __c
== '1')
778 __tmp
.push_back(__c
);
779 else if (_Traits::eq_int_type(__buf
->sputbackc(__c2
), __eof
)) {
780 __is
.setstate(ios_base::failbit
);
787 __is
.setstate(ios_base::failbit
);
789 __x
._M_copy_from_string(__tmp
, static_cast<size_t>(0), _Nb
);
795 template <class _CharT
, class _Traits
, size_t _Nb
>
796 basic_ostream
<_CharT
, _Traits
>&
797 operator<<(basic_ostream
<_CharT
, _Traits
>& __os
, const bitset
<_Nb
>& __x
)
799 basic_string
<_CharT
, _Traits
> __tmp
;
800 __x
._M_copy_to_string(__tmp
);
801 return __os
<< __tmp
;
806 #undef __BITSET_WORDS
808 #endif /* __GLIBCPP_BITSET */