ReactOS 0.4.15-dev-8145-ga541a46
_bitset.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 1998
3 * Silicon Graphics Computer Systems, Inc.
4 *
5 * Copyright (c) 1999
6 * Boris Fomitchev
7 *
8 * This material is provided "as is", with absolutely no warranty expressed
9 * or implied. Any use is at your own risk.
10 *
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.
16 *
17 */
18
19#ifndef _STLP_BITSET_H
20#define _STLP_BITSET_H
21
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
25// always zero.
26
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.
31
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.
36
37
38#ifndef _STLP_INTERNAL_ALGOBASE_H
39# include <stl/_algobase.h>
40#endif
41
42#ifndef _STLP_INTERNAL_ALLOC_H
43# include <stl/_alloc.h>
44#endif
45
46#ifndef _STLP_INTERNAL_ITERATOR_H
47# include <stl/_iterator.h>
48#endif
49
50#ifndef _STLP_INTERNAL_UNINITIALIZED_H
51# include <stl/_uninitialized.h>
52#endif
53
54#ifndef _STLP_RANGE_ERRORS_H
55# include <stl/_range_errors.h>
56#endif
57
58#ifndef _STLP_INTERNAL_STRING_H
59# include <stl/_string.h>
60#endif
61
62#define __BITS_PER_WORD (CHAR_BIT*sizeof(unsigned long))
63#define __BITSET_WORDS(__n) ((__n + __BITS_PER_WORD - 1)/__BITS_PER_WORD)
64
66
68
69// structure to aid in counting bits
71{
72 public:
73 //returns the number of bit set within the buffer between __beg and __end.
74 static size_t _S_count(const unsigned char *__beg, const unsigned char *__end)
75#if defined (_STLP_USE_NO_IOSTREAMS)
76 {
77 size_t __result = 0;
78 for (; __beg != __end; ++__beg) {
79 for (size_t i = 0; i < (sizeof(unsigned char) * 8); ++i) {
80 if ((*__beg & (1 << i)) != 0) { ++__result; }
81 }
82 }
83 return __result;
84 }
85#else
86 ;
87#endif
88 // Mapping from 8 bit unsigned integers to the index of the first one bit set:
89 static unsigned char _S_first_one(unsigned char __x)
90#if defined (_STLP_USE_NO_IOSTREAMS)
91 {
92 for (unsigned char i = 0; i < (sizeof(unsigned char) * 8); ++i) {
93 if ((__x & (1 << i)) != 0) { return i; }
94 }
95 return 0;
96 }
97#else
98 ;
99#endif
100};
101
102//
103// Base class: general case.
104//
105
106template<size_t _Nw>
108 typedef unsigned long _WordT;
109
110 _WordT _M_w[_Nw]; // 0 is the least significant word.
111
113
114 _Base_bitset(unsigned long __val) {
115 _M_do_reset();
116 _M_w[0] = __val;
117 }
118
119 static size_t _STLP_CALL _S_whichword( size_t __pos ) {
120 return __pos / __BITS_PER_WORD;
121 }
122 static size_t _STLP_CALL _S_whichbyte( size_t __pos ) {
123 return (__pos % __BITS_PER_WORD) / CHAR_BIT;
124 }
125 static size_t _STLP_CALL _S_whichbit( size_t __pos ) {
126 return __pos % __BITS_PER_WORD;
127 }
128 static _WordT _STLP_CALL _S_maskbit( size_t __pos ) {
129 return __STATIC_CAST(_WordT,1) << _S_whichbit(__pos);
130 }
131
132 _WordT& _M_getword(size_t __pos) { return _M_w[_S_whichword(__pos)]; }
133 _WordT _M_getword(size_t __pos) const { return _M_w[_S_whichword(__pos)]; }
134
135 _WordT& _M_hiword() { return _M_w[_Nw - 1]; }
136 _WordT _M_hiword() const { return _M_w[_Nw - 1]; }
137
138 void _M_do_and(const _Base_bitset<_Nw>& __x) {
139 for ( size_t __i = 0; __i < _Nw; __i++ ) {
140 _M_w[__i] &= __x._M_w[__i];
141 }
142 }
143
144 void _M_do_or(const _Base_bitset<_Nw>& __x) {
145 for ( size_t __i = 0; __i < _Nw; __i++ ) {
146 _M_w[__i] |= __x._M_w[__i];
147 }
148 }
149
150 void _M_do_xor(const _Base_bitset<_Nw>& __x) {
151 for ( size_t __i = 0; __i < _Nw; __i++ ) {
152 _M_w[__i] ^= __x._M_w[__i];
153 }
154 }
155
156 void _M_do_left_shift(size_t __shift);
157
158 void _M_do_right_shift(size_t __shift);
159
160 void _M_do_flip() {
161 for ( size_t __i = 0; __i < _Nw; __i++ ) {
162 _M_w[__i] = ~_M_w[__i];
163 }
164 }
165
166 void _M_do_set() {
167 for ( size_t __i = 0; __i < _Nw; __i++ ) {
168 _M_w[__i] = ~__STATIC_CAST(_WordT,0);
169 }
170 }
171
172 void _M_do_reset() { memset(_M_w, 0, _Nw * sizeof(_WordT)); }
173
174 bool _M_is_equal(const _Base_bitset<_Nw>& __x) const {
175 for (size_t __i = 0; __i < _Nw; ++__i) {
176 if (_M_w[__i] != __x._M_w[__i])
177 return false;
178 }
179 return true;
180 }
181
182 bool _M_is_any() const {
183 for ( size_t __i = 0; __i < _Nw ; __i++ ) {
184 if ( _M_w[__i] != __STATIC_CAST(_WordT,0) )
185 return true;
186 }
187 return false;
188 }
189
190 size_t _M_do_count() const {
191 const unsigned char* __byte_ptr = (const unsigned char*)_M_w;
192 const unsigned char* __end_ptr = (const unsigned char*)(_M_w+_Nw);
193
194 return _Bs_G::_S_count(__byte_ptr, __end_ptr);
195 }
196
197 unsigned long _M_do_to_ulong() const;
198
199 // find first "on" bit
200 size_t _M_do_find_first(size_t __not_found) const;
201
202 // find the next "on" bit that follows "prev"
203 size_t _M_do_find_next(size_t __prev, size_t __not_found) const;
204};
205
206//
207// Base class: specialization for a single word.
208//
210struct _Base_bitset<1UL> {
211 typedef unsigned long _WordT;
213
215
216 _Base_bitset( void ) : _M_w(0) {}
217 _Base_bitset(unsigned long __val) : _M_w(__val) {}
218
219 static size_t _STLP_CALL _S_whichword( size_t __pos ) {
220 return __pos / __BITS_PER_WORD ;
221 }
222 static size_t _STLP_CALL _S_whichbyte( size_t __pos ) {
223 return (__pos % __BITS_PER_WORD) / CHAR_BIT;
224 }
225 static size_t _STLP_CALL _S_whichbit( size_t __pos ) {
226 return __pos % __BITS_PER_WORD;
227 }
228 static _WordT _STLP_CALL _S_maskbit( size_t __pos ) {
229 return (__STATIC_CAST(_WordT,1)) << _S_whichbit(__pos);
230 }
231
232 _WordT& _M_getword(size_t) { return _M_w; }
233 _WordT _M_getword(size_t) const { return _M_w; }
234
235 _WordT& _M_hiword() { return _M_w; }
236 _WordT _M_hiword() const { return _M_w; }
237
238 void _M_do_and(const _Self& __x) { _M_w &= __x._M_w; }
239 void _M_do_or(const _Self& __x) { _M_w |= __x._M_w; }
240 void _M_do_xor(const _Self& __x) { _M_w ^= __x._M_w; }
241 void _M_do_left_shift(size_t __shift) { _M_w <<= __shift; }
242 void _M_do_right_shift(size_t __shift) { _M_w >>= __shift; }
243 void _M_do_flip() { _M_w = ~_M_w; }
244 void _M_do_set() { _M_w = ~__STATIC_CAST(_WordT,0); }
245 void _M_do_reset() { _M_w = 0; }
246
247 bool _M_is_equal(const _Self& __x) const {
248 return _M_w == __x._M_w;
249 }
250 bool _M_is_any() const {
251 return _M_w != 0;
252 }
253
254 size_t _M_do_count() const {
255 const unsigned char* __byte_ptr = (const unsigned char*)&_M_w;
256 const unsigned char* __end_ptr = ((const unsigned char*)&_M_w)+sizeof(_M_w);
257 return _Bs_G::_S_count(__byte_ptr, __end_ptr);
258 }
259
260 unsigned long _M_do_to_ulong() const { return _M_w; }
261
262 inline size_t _M_do_find_first(size_t __not_found) const;
263
264 // find the next "on" bit that follows "prev"
265 inline size_t _M_do_find_next(size_t __prev, size_t __not_found) const;
266};
267
268
269// ------------------------------------------------------------
270//
271// Definitions of should-be-non-inline functions from the single-word version of
272// _Base_bitset.
273//
274inline size_t
275_Base_bitset<1UL>::_M_do_find_first(size_t __not_found) const {
276 // typedef unsigned long _WordT;
277 _WordT __thisword = _M_w;
278
279 if ( __thisword != __STATIC_CAST(_WordT,0) ) {
280 // find byte within word
281 for ( size_t __j = 0; __j < sizeof(_WordT); __j++ ) {
282 unsigned char __this_byte
283 = __STATIC_CAST(unsigned char,(__thisword & (~(unsigned char)0)));
284 if ( __this_byte )
285 return __j*CHAR_BIT + _Bs_G::_S_first_one(__this_byte);
286
287 __thisword >>= CHAR_BIT;
288 }
289 }
290 // not found, so return a value that indicates failure.
291 return __not_found;
292}
293
294inline size_t
296 size_t __not_found ) const {
297 // make bound inclusive
298 ++__prev;
299
300 // check out of bounds
301 if ( __prev >= __BITS_PER_WORD )
302 return __not_found;
303
304 // search first (and only) word
305 _WordT __thisword = _M_w;
306
307 // mask off bits below bound
308 __thisword &= (~__STATIC_CAST(_WordT,0)) << _S_whichbit(__prev);
309
310 if ( __thisword != __STATIC_CAST(_WordT,0) ) {
311 // find byte within word
312 // get first byte into place
313 __thisword >>= _S_whichbyte(__prev) * CHAR_BIT;
314 for ( size_t __j = _S_whichbyte(__prev); __j < sizeof(_WordT); __j++ ) {
315 unsigned char __this_byte
316 = __STATIC_CAST(unsigned char,(__thisword & (~(unsigned char)0)));
317 if ( __this_byte )
318 return __j*CHAR_BIT + _Bs_G::_S_first_one(__this_byte);
319
320 __thisword >>= CHAR_BIT;
321 }
322 }
323
324 // not found, so return a value that indicates failure.
325 return __not_found;
326} // end _M_do_find_next
327
328
329// ------------------------------------------------------------
330// Helper class to zero out the unused high-order bits in the highest word.
331
332template <size_t _Extrabits> struct _Sanitize {
333 static void _STLP_CALL _M_do_sanitize(unsigned long& __val)
334 { __val &= ~((~__STATIC_CAST(unsigned long,0)) << _Extrabits); }
335};
336
338 static void _STLP_CALL _M_do_sanitize(unsigned long) {}
339};
340
342
343// ------------------------------------------------------------
344// Class bitset.
345// _Nb may be any nonzero number of type size_t.
346template<size_t _Nb>
347class bitset : public _STLP_PRIV _Base_bitset<__BITSET_WORDS(_Nb) > {
348public:
349 enum { _Words = __BITSET_WORDS(_Nb) } ;
350
351private:
353
356 }
357public:
358 typedef unsigned long _WordT;
359 struct reference;
360 friend struct reference;
361
362 // bit reference:
363 struct reference {
366 // friend _Bitset;
368 size_t _M_bpos;
369
370 // should be left undefined
372
373 reference( _Bitset& __b, size_t __pos ) {
374 _M_wp = &__b._M_getword(__pos);
375 _M_bpos = _Bitset_base::_S_whichbit(__pos);
376 }
377
378 public:
380
381 // for b[i] = __x;
382 reference& operator=(bool __x) {
383 if ( __x )
384 *_M_wp |= _Bitset_base::_S_maskbit(_M_bpos);
385 else
386 *_M_wp &= ~_Bitset_base::_S_maskbit(_M_bpos);
387
388 return *this;
389 }
390
391 // for b[i] = b[__j];
393 if ( (*(__j._M_wp) & _Bitset_base::_S_maskbit(__j._M_bpos)) )
394 *_M_wp |= _Bitset_base::_S_maskbit(_M_bpos);
395 else
396 *_M_wp &= ~_Bitset_base::_S_maskbit(_M_bpos);
397
398 return *this;
399 }
400
401 // flips the bit
402 bool operator~() const { return (*(_M_wp) & _Bitset_base::_S_maskbit(_M_bpos)) == 0; }
403
404 // for __x = b[i];
405 operator bool() const { return (*(_M_wp) & _Bitset_base::_S_maskbit(_M_bpos)) != 0; }
406
407 // for b[i].flip();
409 *_M_wp ^= _Bitset_base::_S_maskbit(_M_bpos);
410 return *this;
411 }
412 };
413
414 // 23.3.5.1 constructors:
416
418
419#if defined (_STLP_MEMBER_TEMPLATES)
420 template<class _CharT, class _Traits, class _Alloc>
422 size_t __pos = 0)
424 if (__pos > __s.size())
425 __stl_throw_out_of_range("bitset");
426 _M_copy_from_string(__s, __pos,
428 }
429 template<class _CharT, class _Traits, class _Alloc>
431 size_t __pos,
432 size_t __n)
434 if (__pos > __s.size())
435 __stl_throw_out_of_range("bitset");
436 _M_copy_from_string(__s, __pos, __n);
437 }
438#else /* _STLP_MEMBER_TEMPLATES */
439 explicit bitset(const string& __s,
440 size_t __pos = 0,
441 size_t __n = (size_t)-1)
443 if (__pos > __s.size())
444 __stl_throw_out_of_range("bitset");
445 _M_copy_from_string(__s, __pos, __n);
446 }
447#endif /* _STLP_MEMBER_TEMPLATES */
448
449 // 23.3.5.2 bitset operations:
451 this->_M_do_and(__rhs);
452 return *this;
453 }
454
456 this->_M_do_or(__rhs);
457 return *this;
458 }
459
461 this->_M_do_xor(__rhs);
462 return *this;
463 }
464
465 bitset<_Nb>& operator<<=(size_t __pos) {
466 this->_M_do_left_shift(__pos);
467 this->_M_do_sanitize();
468 return *this;
469 }
470
471 bitset<_Nb>& operator>>=(size_t __pos) {
472 this->_M_do_right_shift(__pos);
473 this->_M_do_sanitize();
474 return *this;
475 }
476
477 //
478 // Extension:
479 // Versions of single-bit set, reset, flip, test with no range checking.
480 //
481
483 this->_M_getword(__pos) |= _STLP_PRIV _Base_bitset<_Words > ::_S_maskbit(__pos);
484 return *this;
485 }
486
487 bitset<_Nb>& _Unchecked_set(size_t __pos, int __val) {
488 if (__val)
489 this->_M_getword(__pos) |= this->_S_maskbit(__pos);
490 else
491 this->_M_getword(__pos) &= ~ this->_S_maskbit(__pos);
492
493 return *this;
494 }
495
497 this->_M_getword(__pos) &= ~ this->_S_maskbit(__pos);
498 return *this;
499 }
500
502 this->_M_getword(__pos) ^= this->_S_maskbit(__pos);
503 return *this;
504 }
505
506 bool _Unchecked_test(size_t __pos) const {
507 return (this->_M_getword(__pos) & this->_S_maskbit(__pos)) != __STATIC_CAST(_WordT,0);
508 }
509
510 // Set, reset, and flip.
511
513 this->_M_do_set();
514 this->_M_do_sanitize();
515 return *this;
516 }
517
518 bitset<_Nb>& set(size_t __pos) {
519 if (__pos >= _Nb)
520 __stl_throw_out_of_range("bitset");
521 return _Unchecked_set(__pos);
522 }
523
524 bitset<_Nb>& set(size_t __pos, int __val) {
525 if (__pos >= _Nb)
526 __stl_throw_out_of_range("bitset");
527 return _Unchecked_set(__pos, __val);
528 }
529
531 this->_M_do_reset();
532 return *this;
533 }
534
535 bitset<_Nb>& reset(size_t __pos) {
536 if (__pos >= _Nb)
537 __stl_throw_out_of_range("bitset");
538
539 return _Unchecked_reset(__pos);
540 }
541
543 this->_M_do_flip();
544 this->_M_do_sanitize();
545 return *this;
546 }
547
548 bitset<_Nb>& flip(size_t __pos) {
549 if (__pos >= _Nb)
550 __stl_throw_out_of_range("bitset");
551
552 return _Unchecked_flip(__pos);
553 }
554
556 return bitset<_Nb>(*this).flip();
557 }
558
559 // element access:
560 //for b[i];
561 reference operator[](size_t __pos) { return reference(*this,__pos); }
562 bool operator[](size_t __pos) const { return _Unchecked_test(__pos); }
563
564 unsigned long to_ulong() const { return this->_M_do_to_ulong(); }
565
566#if defined (_STLP_MEMBER_TEMPLATES) && !defined (_STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS)
567 template <class _CharT, class _Traits, class _Alloc>
570 _M_copy_to_string(__result);
571 return __result;
572 }
573#else
574 string to_string() const {
575 string __result;
576 _M_copy_to_string(__result);
577 return __result;
578 }
579#endif /* _STLP_EXPLICIT_FUNCTION_TMPL_ARGS */
580
581 size_t count() const { return this->_M_do_count(); }
582
583 size_t size() const { return _Nb; }
584
585 bool operator==(const bitset<_Nb>& __rhs) const {
586 return this->_M_is_equal(__rhs);
587 }
588 bool operator!=(const bitset<_Nb>& __rhs) const {
589 return !this->_M_is_equal(__rhs);
590 }
591
592 bool test(size_t __pos) const {
593 if (__pos >= _Nb)
594 __stl_throw_out_of_range("bitset");
595
596 return _Unchecked_test(__pos);
597 }
598
599 bool any() const { return this->_M_is_any(); }
600 bool none() const { return !this->_M_is_any(); }
601
602 bitset<_Nb> operator<<(size_t __pos) const {
603 bitset<_Nb> __result(*this);
604 __result <<= __pos ; return __result;
605 }
606 bitset<_Nb> operator>>(size_t __pos) const {
607 bitset<_Nb> __result(*this);
608 __result >>= __pos ; return __result;
609 }
610
611#if !defined (_STLP_NO_EXTENSIONS)
612 //
613 // EXTENSIONS: bit-find operations. These operations are
614 // experimental, and are subject to change or removal in future
615 // versions.
616 //
617
618 // find the index of the first "on" bit
619 size_t _Find_first() const
620 { return this->_M_do_find_first(_Nb); }
621
622 // find the index of the next "on" bit after prev
623 size_t _Find_next( size_t __prev ) const
624 { return this->_M_do_find_next(__prev, _Nb); }
625#endif
626
627//
628// Definitions of should-be non-inline member functions.
629//
630#if defined (_STLP_MEMBER_TEMPLATES)
631 template<class _CharT, class _Traits, class _Alloc>
633 size_t __pos, size_t __n) {
634#else
635 void _M_copy_from_string(const string& __s,
636 size_t __pos, size_t __n) {
637 typedef typename string::traits_type _Traits;
638#endif
639 reset();
640 size_t __tmp = _Nb;
641 const size_t __Nbits = (min) (__tmp, (min) (__n, __s.size() - __pos));
642 for ( size_t __i= 0; __i < __Nbits; ++__i) {
643 typename _Traits::int_type __k = _Traits::to_int_type(__s[__pos + __Nbits - __i - 1]);
644 // boris : widen() ?
645 if (__k == '1')
646 set(__i);
647 else if (__k != '0')
649 }
650 }
651
652#if defined (_STLP_MEMBER_TEMPLATES)
653 template <class _CharT, class _Traits, class _Alloc>
655#else
656 void _M_copy_to_string(string& __s) const
657#endif
658 {
659 __s.assign(_Nb, '0');
660
661 for (size_t __i = 0; __i < _Nb; ++__i) {
662 if (_Unchecked_test(__i))
663 __s[_Nb - 1 - __i] = '1';
664 }
665 }
666
667#if !defined (_STLP_MEMBER_TEMPLATES) && !defined (_STLP_NO_WCHAR_T)
668 void _M_copy_to_string(wstring& __s) const {
669 __s.assign(_Nb, '0');
670
671 for (size_t __i = 0; __i < _Nb; ++__i) {
672 if (_Unchecked_test(__i))
673 __s[_Nb - 1 - __i] = '1';
674 }
675 }
676#endif
677
678#if defined (_STLP_NON_TYPE_TMPL_PARAM_BUG)
679 bitset<_Nb> operator&(const bitset<_Nb>& __y) const {
680 bitset<_Nb> __result(*this);
681 __result &= __y;
682 return __result;
683 }
684 bitset<_Nb> operator|(const bitset<_Nb>& __y) const {
685 bitset<_Nb> __result(*this);
686 __result |= __y;
687 return __result;
688 }
689 bitset<_Nb> operator^(const bitset<_Nb>& __y) const {
690 bitset<_Nb> __result(*this);
691 __result ^= __y;
692 return __result;
693 }
694#endif
695};
696
697// ------------------------------------------------------------
698//
699// 23.3.5.3 bitset operations:
700//
701#if ! defined (_STLP_NON_TYPE_TMPL_PARAM_BUG)
702template <size_t _Nb>
705 const bitset<_Nb>& __y) {
706 bitset<_Nb> __result(__x);
707 __result &= __y;
708 return __result;
709}
710
711
712template <size_t _Nb>
715 const bitset<_Nb>& __y) {
716 bitset<_Nb> __result(__x);
717 __result |= __y;
718 return __result;
719}
720
721template <size_t _Nb>
724 const bitset<_Nb>& __y) {
725 bitset<_Nb> __result(__x);
726 __result ^= __y;
727 return __result;
728}
729
730#if !defined (_STLP_USE_NO_IOSTREAMS)
731
733
734# if !(defined (_STLP_MSVC) && (_STLP_MSVC < 1300)) && \
735 !(defined(__SUNPRO_CC) && (__SUNPRO_CC < 0x500))
736
737#ifndef _STLP_INTERNAL_IOSFWD
738# include <stl/_iosfwd.h>
739#endif
740
742
743template <class _CharT, class _Traits, size_t _Nb>
746
747template <class _CharT, class _Traits, size_t _Nb>
750
751# else
752
753#ifndef _STLP_STRING_IO_H
754# include <stl/_string_io.h> //includes _istream.h and _ostream.h
755#endif
756
758
759template <size_t _Nb>
761operator>>(istream& __is, bitset<_Nb>& __x) {
762 typedef typename string::traits_type _Traits;
763 string __tmp;
764 __tmp.reserve(_Nb);
765
766 // Skip whitespace
767 typename istream::sentry __sentry(__is);
768 if (__sentry) {
769 streambuf* __buf = __is.rdbuf();
770 for (size_t __i = 0; __i < _Nb; ++__i) {
771 static typename _Traits::int_type __eof = _Traits::eof();
772
773 typename _Traits::int_type __c1 = __buf->sbumpc();
774 if (_Traits::eq_int_type(__c1, __eof)) {
775 __is.setstate(ios_base::eofbit);
776 break;
777 }
778 else {
779 typename _Traits::char_type __c2 = _Traits::to_char_type(__c1);
780 char __c = __is.narrow(__c2, '*');
781
782 if (__c == '0' || __c == '1')
783 __tmp.push_back(__c);
784 else if (_Traits::eq_int_type(__buf->sputbackc(__c2), __eof)) {
785 __is.setstate(ios_base::failbit);
786 break;
787 }
788 }
789 }
790
791 if (__tmp.empty())
792 __is.setstate(ios_base::failbit);
793 else
794 __x._M_copy_from_string(__tmp, __STATIC_CAST(size_t,0), _Nb);
795 }
796
797 return __is;
798}
799
800template <size_t _Nb>
802operator<<(ostream& __os, const bitset<_Nb>& __x) {
803 string __tmp;
804 __x._M_copy_to_string(__tmp);
805 return __os << __tmp;
806}
807
808# if !defined (_STLP_NO_WCHAR_T)
809
810template <size_t _Nb>
812operator>>(wistream& __is, bitset<_Nb>& __x) {
813 typedef typename wstring::traits_type _Traits;
814 wstring __tmp;
815 __tmp.reserve(_Nb);
816
817 // Skip whitespace
818 typename wistream::sentry __sentry(__is);
819 if (__sentry) {
820 wstreambuf* __buf = __is.rdbuf();
821 for (size_t __i = 0; __i < _Nb; ++__i) {
822 static typename _Traits::int_type __eof = _Traits::eof();
823
824 typename _Traits::int_type __c1 = __buf->sbumpc();
825 if (_Traits::eq_int_type(__c1, __eof)) {
826 __is.setstate(ios_base::eofbit);
827 break;
828 }
829 else {
830 typename _Traits::char_type __c2 = _Traits::to_char_type(__c1);
831 char __c = __is.narrow(__c2, '*');
832
833 if (__c == '0' || __c == '1')
834 __tmp.push_back(__c);
835 else if (_Traits::eq_int_type(__buf->sputbackc(__c2), __eof)) {
836 __is.setstate(ios_base::failbit);
837 break;
838 }
839 }
840 }
841
842 if (__tmp.empty())
843 __is.setstate(ios_base::failbit);
844 else
845 __x._M_copy_from_string(__tmp, __STATIC_CAST(size_t,0), _Nb);
846 }
847
848 return __is;
849}
850
851template <size_t _Nb>
853operator<<(wostream& __os, const bitset<_Nb>& __x) {
854 wstring __tmp;
855 __x._M_copy_to_string(__tmp);
856 return __os << __tmp;
857}
858
859# endif /* _STLP_NO_WCHAR_T */
860# endif
861#endif
862
863#endif /* _STLP_NON_TYPE_TMPL_PARAM_BUG */
864
865#undef bitset
866
868
869#undef __BITS_PER_WORD
870#undef __BITSET_WORDS
871
872#if !defined (_STLP_LINK_TIME_INSTANTIATION)
873# include <stl/_bitset.c>
874#endif
875
876#endif /* _STLP_BITSET_H */
877
878// Local Variables:
879// mode:C++
880// End:
return __n
Definition: _algo.h:75
_STLP_INLINE_LOOP _InputIter const _Tp & __val
Definition: _algobase.h:656
#define _STLP_CALL
Definition: _bc.h:131
#define __BITS_PER_WORD
Definition: _bitset.h:62
bitset< _Nb > _STLP_CALL operator^(const bitset< _Nb > &__x, const bitset< _Nb > &__y)
Definition: _bitset.h:723
bitset< _Nb > _STLP_CALL operator&(const bitset< _Nb > &__x, const bitset< _Nb > &__y)
Definition: _bitset.h:704
#define __BITSET_WORDS(__n)
Definition: _bitset.h:63
bitset< _Nb > _STLP_CALL operator|(const bitset< _Nb > &__x, const bitset< _Nb > &__y)
Definition: _bitset.h:714
#define _STLP_PRIV
Definition: _dm.h:70
_STLP_THROW_FUNCT_SPEC _STLP_CALL __stl_throw_invalid_argument(const char *__msg)
Definition: _range_errors.c:75
_STLP_THROW_FUNCT_SPEC _STLP_CALL __stl_throw_out_of_range(const char *__msg)
Definition: _range_errors.c:69
Definition: _bitset.h:71
static unsigned char _S_first_one(unsigned char __x)
Definition: bitset.cpp:95
static size_t _S_count(const unsigned char *__beg, const unsigned char *__end)
Definition: bitset.cpp:30
basic_streambuf< _CharT, _Traits > * rdbuf() const
Definition: _ios.h:72
void setstate(iostate __state)
Definition: _ios.h:95
char narrow(_CharT, char) const
Definition: _ios.h:145
int_type sputbackc(char_type __c)
Definition: _streambuf.h:241
int_type sbumpc()
Definition: _streambuf.h:227
void reserve(size_type=0)
Definition: _string.c:158
_Self & assign(const _Self &__s)
Definition: _string.h:548
bool empty() const
Definition: _string.h:428
size_type size() const
Definition: _string.h:400
void push_back(_CharT __c)
Definition: _string.h:534
bitset< _Nb > & _Unchecked_set(size_t __pos, int __val)
Definition: _bitset.h:487
bitset< _Nb > & flip(size_t __pos)
Definition: _bitset.h:548
bitset< _Nb > operator~() const
Definition: _bitset.h:555
_STLP_PRIV _Base_bitset< _Words > _Base
Definition: _bitset.h:352
unsigned long _WordT
Definition: _bitset.h:358
size_t _Find_next(size_t __prev) const
Definition: _bitset.h:623
bitset< _Nb > operator>>(size_t __pos) const
Definition: _bitset.h:606
bitset< _Nb > & operator>>=(size_t __pos)
Definition: _bitset.h:471
string to_string() const
Definition: _bitset.h:574
bitset< _Nb > & reset(size_t __pos)
Definition: _bitset.h:535
size_t size() const
Definition: _bitset.h:583
bitset< _Nb > operator<<(size_t __pos) const
Definition: _bitset.h:602
void _M_copy_from_string(const string &__s, size_t __pos, size_t __n)
Definition: _bitset.h:635
bitset()
Definition: _bitset.h:415
bitset(unsigned long __val)
Definition: _bitset.h:417
bool none() const
Definition: _bitset.h:600
bitset< _Nb > & set(size_t __pos, int __val)
Definition: _bitset.h:524
bitset< _Nb > & _Unchecked_set(size_t __pos)
Definition: _bitset.h:482
bitset< _Nb > & reset()
Definition: _bitset.h:530
bitset< _Nb > & flip()
Definition: _bitset.h:542
bitset< _Nb > & set()
Definition: _bitset.h:512
bitset< _Nb > & _Unchecked_reset(size_t __pos)
Definition: _bitset.h:496
unsigned long to_ulong() const
Definition: _bitset.h:564
void _M_do_sanitize()
Definition: _bitset.h:354
void _M_copy_to_string(string &__s) const
Definition: _bitset.h:656
bitset< _Nb > & set(size_t __pos)
Definition: _bitset.h:518
void _M_copy_to_string(wstring &__s) const
Definition: _bitset.h:668
size_t _Find_first() const
Definition: _bitset.h:619
bool operator!=(const bitset< _Nb > &__rhs) const
Definition: _bitset.h:588
bitset< _Nb > & operator^=(const bitset< _Nb > &__rhs)
Definition: _bitset.h:460
bitset< _Nb > & operator|=(const bitset< _Nb > &__rhs)
Definition: _bitset.h:455
bitset< _Nb > & _Unchecked_flip(size_t __pos)
Definition: _bitset.h:501
@ _Words
Definition: _bitset.h:349
bitset(const string &__s, size_t __pos=0, size_t __n=(size_t) -1)
Definition: _bitset.h:439
bool operator==(const bitset< _Nb > &__rhs) const
Definition: _bitset.h:585
bitset< _Nb > & operator&=(const bitset< _Nb > &__rhs)
Definition: _bitset.h:450
size_t count() const
Definition: _bitset.h:581
bool any() const
Definition: _bitset.h:599
reference operator[](size_t __pos)
Definition: _bitset.h:561
bool test(size_t __pos) const
Definition: _bitset.h:592
bool operator[](size_t __pos) const
Definition: _bitset.h:562
bool _Unchecked_test(size_t __pos) const
Definition: _bitset.h:506
bitset< _Nb > & operator<<=(size_t __pos)
Definition: _bitset.h:465
unsigned char
Definition: typeof.h:29
#define CHAR_BIT
Definition: urlcache.c:62
#define _STLP_TEMPLATE_NULL
Definition: features.h:652
#define _STLP_MOVE_TO_STD_NAMESPACE
Definition: features.h:525
#define __STATIC_CAST(__x, __y)
Definition: features.h:585
#define _STLP_CLASS_DECLSPEC
Definition: features.h:983
#define _STLP_BEGIN_NAMESPACE
Definition: features.h:501
#define _STLP_END_NAMESPACE
Definition: features.h:503
#define _STLP_MOVE_TO_PRIV_NAMESPACE
Definition: features.h:524
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define min(a, b)
Definition: monoChain.cc:55
#define bool
Definition: nsiface.idl:72
#define __c
Definition: schilyio.h:209
#define memset(x, y, z)
Definition: compat.h:39
void _M_do_left_shift(size_t __shift)
Definition: _bitset.h:241
unsigned long _M_do_to_ulong() const
Definition: _bitset.h:260
_Base_bitset< 1UL > _Self
Definition: _bitset.h:212
static size_t _STLP_CALL _S_whichbyte(size_t __pos)
Definition: _bitset.h:222
size_t _M_do_count() const
Definition: _bitset.h:254
_WordT _M_getword(size_t) const
Definition: _bitset.h:233
static _WordT _STLP_CALL _S_maskbit(size_t __pos)
Definition: _bitset.h:228
void _M_do_reset()
Definition: _bitset.h:245
_WordT _M_hiword() const
Definition: _bitset.h:236
void _M_do_or(const _Self &__x)
Definition: _bitset.h:239
void _M_do_right_shift(size_t __shift)
Definition: _bitset.h:242
_WordT & _M_hiword()
Definition: _bitset.h:235
_WordT & _M_getword(size_t)
Definition: _bitset.h:232
static size_t _STLP_CALL _S_whichword(size_t __pos)
Definition: _bitset.h:219
void _M_do_and(const _Self &__x)
Definition: _bitset.h:238
static size_t _STLP_CALL _S_whichbit(size_t __pos)
Definition: _bitset.h:225
void _M_do_xor(const _Self &__x)
Definition: _bitset.h:240
unsigned long _WordT
Definition: _bitset.h:211
_Base_bitset(unsigned long __val)
Definition: _bitset.h:217
bool _M_is_any() const
Definition: _bitset.h:250
bool _M_is_equal(const _Self &__x) const
Definition: _bitset.h:247
void _M_do_or(const _Base_bitset< _Nw > &__x)
Definition: _bitset.h:144
size_t _M_do_count() const
Definition: _bitset.h:190
void _M_do_left_shift(size_t __shift)
Definition: _bitset.c:35
static size_t _STLP_CALL _S_whichbyte(size_t __pos)
Definition: _bitset.h:122
_WordT _M_hiword() const
Definition: _bitset.h:136
size_t _M_do_find_next(size_t __prev, size_t __not_found) const
Definition: _bitset.c:110
static _WordT _STLP_CALL _S_maskbit(size_t __pos)
Definition: _bitset.h:128
unsigned long _WordT
Definition: _bitset.h:108
void _M_do_reset()
Definition: _bitset.h:172
void _M_do_xor(const _Base_bitset< _Nw > &__x)
Definition: _bitset.h:150
bool _M_is_any() const
Definition: _bitset.h:182
_Base_bitset(unsigned long __val)
Definition: _bitset.h:114
void _M_do_flip()
Definition: _bitset.h:160
void _M_do_set()
Definition: _bitset.h:166
void _M_do_right_shift(size_t __shift)
Definition: _bitset.c:57
unsigned long _M_do_to_ulong() const
Definition: _bitset.c:80
_WordT & _M_getword(size_t __pos)
Definition: _bitset.h:132
_WordT _M_w[_Nw]
Definition: _bitset.h:110
void _M_do_and(const _Base_bitset< _Nw > &__x)
Definition: _bitset.h:138
size_t _M_do_find_first(size_t __not_found) const
Definition: _bitset.c:88
_WordT _M_getword(size_t __pos) const
Definition: _bitset.h:133
_WordT & _M_hiword()
Definition: _bitset.h:135
bool _M_is_equal(const _Base_bitset< _Nw > &__x) const
Definition: _bitset.h:174
static size_t _STLP_CALL _S_whichword(size_t __pos)
Definition: _bitset.h:119
static size_t _STLP_CALL _S_whichbit(size_t __pos)
Definition: _bitset.h:125
_Base_bitset()
Definition: _bitset.h:112
static void _STLP_CALL _M_do_sanitize(unsigned long)
Definition: _bitset.h:338
static void _STLP_CALL _M_do_sanitize(unsigned long &__val)
Definition: _bitset.h:333
reference(_Bitset &__b, size_t __pos)
Definition: _bitset.h:373
_WordT * _M_wp
Definition: _bitset.h:367
size_t _M_bpos
Definition: _bitset.h:368
_STLP_PRIV _Base_bitset< _Words > _Bitset_base
Definition: _bitset.h:364
reference & operator=(bool __x)
Definition: _bitset.h:382
reference & operator=(const reference &__j)
Definition: _bitset.h:392
bitset< _Nb > _Bitset
Definition: _bitset.h:365
bool operator~() const
Definition: _bitset.h:402
reference & flip()
Definition: _bitset.h:408
#define UL
Definition: tui.h:165