2 //===---------------------------- bitset ----------------------------------===//
4 // The LLVM Compiler Infrastructure
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 #ifndef _LIBCPP_BITSET
12 #define _LIBCPP_BITSET
32 ~reference() noexcept;
33 reference& operator=(bool x) noexcept; // for b[i] = x;
34 reference& operator=(const reference&) noexcept; // for b[i] = b[j];
35 bool operator~() const noexcept; // flips the bit
36 operator bool() const noexcept; // for x = b[i];
37 reference& flip() noexcept; // for b[i].flip();
40 // 23.3.5.1 constructors:
41 constexpr bitset() noexcept;
42 constexpr bitset(unsigned long long val) noexcept;
43 template <class charT>
44 explicit bitset(const charT* str,
45 typename basic_string<charT>::size_type n = basic_string<charT>::npos,
46 charT zero = charT('0'), charT one = charT('1'));
47 template<class charT, class traits, class Allocator>
48 explicit bitset(const basic_string<charT,traits,Allocator>& str,
49 typename basic_string<charT,traits,Allocator>::size_type pos = 0,
50 typename basic_string<charT,traits,Allocator>::size_type n =
51 basic_string<charT,traits,Allocator>::npos,
52 charT zero = charT('0'), charT one = charT('1'));
54 // 23.3.5.2 bitset operations:
55 bitset& operator&=(const bitset& rhs) noexcept;
56 bitset& operator|=(const bitset& rhs) noexcept;
57 bitset& operator^=(const bitset& rhs) noexcept;
58 bitset& operator<<=(size_t pos) noexcept;
59 bitset& operator>>=(size_t pos) noexcept;
60 bitset& set() noexcept;
61 bitset& set(size_t pos, bool val = true);
62 bitset& reset() noexcept;
63 bitset& reset(size_t pos);
64 bitset operator~() const noexcept;
65 bitset& flip() noexcept;
66 bitset& flip(size_t pos);
69 constexpr bool operator[](size_t pos) const; // for b[i];
70 reference operator[](size_t pos); // for b[i];
71 unsigned long to_ulong() const;
72 unsigned long long to_ullong() const;
73 template <class charT, class traits, class Allocator>
74 basic_string<charT, traits, Allocator> to_string(charT zero = charT('0'), charT one = charT('1')) const;
75 template <class charT, class traits>
76 basic_string<charT, traits, allocator<charT> > to_string(charT zero = charT('0'), charT one = charT('1')) const;
77 template <class charT>
78 basic_string<charT, char_traits<charT>, allocator<charT> > to_string(charT zero = charT('0'), charT one = charT('1')) const;
79 basic_string<char, char_traits<char>, allocator<char> > to_string(char zero = '0', char one = '1') const;
80 size_t count() const noexcept;
81 constexpr size_t size() const noexcept;
82 bool operator==(const bitset& rhs) const noexcept;
83 bool operator!=(const bitset& rhs) const noexcept;
84 bool test(size_t pos) const;
85 bool all() const noexcept;
86 bool any() const noexcept;
87 bool none() const noexcept;
88 bitset operator<<(size_t pos) const noexcept;
89 bitset operator>>(size_t pos) const noexcept;
92 // 23.3.5.3 bitset operators:
94 bitset<N> operator&(const bitset<N>&, const bitset<N>&) noexcept;
97 bitset<N> operator|(const bitset<N>&, const bitset<N>&) noexcept;
100 bitset<N> operator^(const bitset<N>&, const bitset<N>&) noexcept;
102 template <class charT, class traits, size_t N>
103 basic_istream<charT, traits>&
104 operator>>(basic_istream<charT, traits>& is, bitset<N>& x);
106 template <class charT, class traits, size_t N>
107 basic_ostream<charT, traits>&
108 operator<<(basic_ostream<charT, traits>& os, const bitset<N>& x);
110 template <size_t N> struct hash<std::bitset<N>>;
116 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
117 #pragma GCC system_header
121 #include <__bit_reference>
127 #include <__functional_base>
128 #if defined(_LIBCPP_NO_EXCEPTIONS)
132 #include <__undef_min_max>
134 _LIBCPP_BEGIN_NAMESPACE_STD
136 template <size_t _N_words, size_t _Size>
139 template <size_t _N_words, size_t _Size>
140 struct __has_storage_type<__bitset<_N_words, _Size> >
142 static const bool value = true;
145 template <size_t _N_words, size_t _Size>
149 typedef ptrdiff_t difference_type;
150 typedef size_t size_type;
151 typedef size_type __storage_type;
153 typedef __bitset __self;
154 typedef __storage_type* __storage_pointer;
155 typedef const __storage_type* __const_storage_pointer;
156 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
158 friend class __bit_reference<__bitset>;
159 friend class __bit_const_reference<__bitset>;
160 friend class __bit_iterator<__bitset, false>;
161 friend class __bit_iterator<__bitset, true>;
162 friend struct __bit_array<__bitset>;
164 __storage_type __first_[_N_words];
166 typedef __bit_reference<__bitset> reference;
167 typedef __bit_const_reference<__bitset> const_reference;
168 typedef __bit_iterator<__bitset, false> iterator;
169 typedef __bit_iterator<__bitset, true> const_iterator;
171 _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
172 explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT;
174 _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t __pos) _NOEXCEPT
175 {return reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
176 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT
177 {return const_reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
178 _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t __pos) _NOEXCEPT
179 {return iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
180 _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t __pos) const _NOEXCEPT
181 {return const_iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
183 void operator&=(const __bitset& __v) _NOEXCEPT;
184 void operator|=(const __bitset& __v) _NOEXCEPT;
185 void operator^=(const __bitset& __v) _NOEXCEPT;
187 void flip() _NOEXCEPT;
188 _LIBCPP_INLINE_VISIBILITY unsigned long to_ulong() const
189 {return to_ulong(integral_constant<bool, _Size < sizeof(unsigned long) * CHAR_BIT>());}
190 _LIBCPP_INLINE_VISIBILITY unsigned long long to_ullong() const
191 {return to_ullong(integral_constant<bool, _Size < sizeof(unsigned long long) * CHAR_BIT>());}
193 bool all() const _NOEXCEPT;
194 bool any() const _NOEXCEPT;
195 size_t __hash_code() const _NOEXCEPT;
197 #ifdef _LIBCPP_HAS_NO_CONSTEXPR
198 void __init(unsigned long long __v, false_type) _NOEXCEPT;
199 void __init(unsigned long long __v, true_type) _NOEXCEPT;
200 #endif // _LIBCPP_HAS_NO_CONSTEXPR
201 unsigned long to_ulong(false_type) const;
202 unsigned long to_ulong(true_type) const;
203 unsigned long long to_ullong(false_type) const;
204 unsigned long long to_ullong(true_type) const;
205 unsigned long long to_ullong(true_type, false_type) const;
206 unsigned long long to_ullong(true_type, true_type) const;
209 template <size_t _N_words, size_t _Size>
210 inline _LIBCPP_INLINE_VISIBILITY
212 __bitset<_N_words, _Size>::__bitset() _NOEXCEPT
213 #ifndef _LIBCPP_HAS_NO_CONSTEXPR
217 #ifdef _LIBCPP_HAS_NO_CONSTEXPR
218 _VSTD::fill_n(__first_, _N_words, __storage_type(0));
222 #ifdef _LIBCPP_HAS_NO_CONSTEXPR
224 template <size_t _N_words, size_t _Size>
226 __bitset<_N_words, _Size>::__init(unsigned long long __v, false_type) _NOEXCEPT
228 __storage_type __t[sizeof(unsigned long long) / sizeof(__storage_type)];
229 for (size_t __i = 0; __i < sizeof(__t)/sizeof(__t[0]); ++__i, __v >>= __bits_per_word)
230 __t[__i] = static_cast<__storage_type>(__v);
231 _VSTD::copy(__t, __t + sizeof(__t)/sizeof(__t[0]), __first_);
232 _VSTD::fill(__first_ + sizeof(__t)/sizeof(__t[0]), __first_ + sizeof(__first_)/sizeof(__first_[0]),
236 template <size_t _N_words, size_t _Size>
237 inline _LIBCPP_INLINE_VISIBILITY
239 __bitset<_N_words, _Size>::__init(unsigned long long __v, true_type) _NOEXCEPT
242 _VSTD::fill(__first_ + 1, __first_ + sizeof(__first_)/sizeof(__first_[0]), __storage_type(0));
245 #endif // _LIBCPP_HAS_NO_CONSTEXPR
247 template <size_t _N_words, size_t _Size>
248 inline _LIBCPP_INLINE_VISIBILITY
250 __bitset<_N_words, _Size>::__bitset(unsigned long long __v) _NOEXCEPT
251 #ifndef _LIBCPP_HAS_NO_CONSTEXPR
252 #if __SIZEOF_SIZE_T__ == 8
254 #elif __SIZEOF_SIZE_T__ == 4
255 : __first_{__v, __v >> __bits_per_word}
257 #error This constructor has not been ported to this platform
261 #ifdef _LIBCPP_HAS_NO_CONSTEXPR
262 __init(__v, integral_constant<bool, sizeof(unsigned long long) == sizeof(__storage_type)>());
266 template <size_t _N_words, size_t _Size>
267 inline _LIBCPP_INLINE_VISIBILITY
269 __bitset<_N_words, _Size>::operator&=(const __bitset& __v) _NOEXCEPT
271 for (size_type __i = 0; __i < _N_words; ++__i)
272 __first_[__i] &= __v.__first_[__i];
275 template <size_t _N_words, size_t _Size>
276 inline _LIBCPP_INLINE_VISIBILITY
278 __bitset<_N_words, _Size>::operator|=(const __bitset& __v) _NOEXCEPT
280 for (size_type __i = 0; __i < _N_words; ++__i)
281 __first_[__i] |= __v.__first_[__i];
284 template <size_t _N_words, size_t _Size>
285 inline _LIBCPP_INLINE_VISIBILITY
287 __bitset<_N_words, _Size>::operator^=(const __bitset& __v) _NOEXCEPT
289 for (size_type __i = 0; __i < _N_words; ++__i)
290 __first_[__i] ^= __v.__first_[__i];
293 template <size_t _N_words, size_t _Size>
295 __bitset<_N_words, _Size>::flip() _NOEXCEPT
297 // do middle whole words
298 size_type __n = _Size;
299 __storage_pointer __p = __first_;
300 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
302 // do last partial word
305 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
306 __storage_type __b = *__p & __m;
312 template <size_t _N_words, size_t _Size>
314 __bitset<_N_words, _Size>::to_ulong(false_type) const
316 const_iterator __e = __make_iter(_Size);
317 const_iterator __i = _VSTD::find(__make_iter(sizeof(unsigned long) * CHAR_BIT), __e, true);
319 #ifndef _LIBCPP_NO_EXCEPTIONS
320 throw overflow_error("bitset to_ulong overflow error");
322 assert(!"bitset to_ulong overflow error");
327 template <size_t _N_words, size_t _Size>
328 inline _LIBCPP_INLINE_VISIBILITY
330 __bitset<_N_words, _Size>::to_ulong(true_type) const
335 template <size_t _N_words, size_t _Size>
337 __bitset<_N_words, _Size>::to_ullong(false_type) const
339 const_iterator __e = __make_iter(_Size);
340 const_iterator __i = _VSTD::find(__make_iter(sizeof(unsigned long long) * CHAR_BIT), __e, true);
342 #ifndef _LIBCPP_NO_EXCEPTIONS
343 throw overflow_error("bitset to_ullong overflow error");
345 assert(!"bitset to_ullong overflow error");
347 return to_ullong(true_type());
350 template <size_t _N_words, size_t _Size>
351 inline _LIBCPP_INLINE_VISIBILITY
353 __bitset<_N_words, _Size>::to_ullong(true_type) const
355 return to_ullong(true_type(), integral_constant<bool, sizeof(__storage_type) < sizeof(unsigned long long)>());
358 template <size_t _N_words, size_t _Size>
359 inline _LIBCPP_INLINE_VISIBILITY
361 __bitset<_N_words, _Size>::to_ullong(true_type, false_type) const
366 template <size_t _N_words, size_t _Size>
368 __bitset<_N_words, _Size>::to_ullong(true_type, true_type) const
370 unsigned long long __r = __first_[0];
371 for (std::size_t __i = 1; __i < sizeof(unsigned long long) / sizeof(__storage_type); ++__i)
372 __r |= static_cast<unsigned long long>(__first_[__i]) << (sizeof(__storage_type) * CHAR_BIT);
376 template <size_t _N_words, size_t _Size>
378 __bitset<_N_words, _Size>::all() const _NOEXCEPT
380 // do middle whole words
381 size_type __n = _Size;
382 __const_storage_pointer __p = __first_;
383 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
386 // do last partial word
389 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
396 template <size_t _N_words, size_t _Size>
398 __bitset<_N_words, _Size>::any() const _NOEXCEPT
400 // do middle whole words
401 size_type __n = _Size;
402 __const_storage_pointer __p = __first_;
403 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
406 // do last partial word
409 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
416 template <size_t _N_words, size_t _Size>
417 inline _LIBCPP_INLINE_VISIBILITY
419 __bitset<_N_words, _Size>::__hash_code() const _NOEXCEPT
422 for (size_type __i = 0; __i < _N_words; ++__i)
423 __h ^= __first_[__i];
427 template <size_t _Size>
428 class __bitset<1, _Size>
431 typedef ptrdiff_t difference_type;
432 typedef size_t size_type;
433 typedef size_type __storage_type;
435 typedef __bitset __self;
436 typedef __storage_type* __storage_pointer;
437 typedef const __storage_type* __const_storage_pointer;
438 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
440 friend class __bit_reference<__bitset>;
441 friend class __bit_const_reference<__bitset>;
442 friend class __bit_iterator<__bitset, false>;
443 friend class __bit_iterator<__bitset, true>;
444 friend struct __bit_array<__bitset>;
446 __storage_type __first_;
448 typedef __bit_reference<__bitset> reference;
449 typedef __bit_const_reference<__bitset> const_reference;
450 typedef __bit_iterator<__bitset, false> iterator;
451 typedef __bit_iterator<__bitset, true> const_iterator;
453 _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
454 explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT;
456 _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t __pos) _NOEXCEPT
457 {return reference(&__first_, __storage_type(1) << __pos);}
458 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT
459 {return const_reference(&__first_, __storage_type(1) << __pos);}
460 _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t __pos) _NOEXCEPT
461 {return iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
462 _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t __pos) const _NOEXCEPT
463 {return const_iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
465 void operator&=(const __bitset& __v) _NOEXCEPT;
466 void operator|=(const __bitset& __v) _NOEXCEPT;
467 void operator^=(const __bitset& __v) _NOEXCEPT;
469 void flip() _NOEXCEPT;
471 unsigned long to_ulong() const;
472 unsigned long long to_ullong() const;
474 bool all() const _NOEXCEPT;
475 bool any() const _NOEXCEPT;
477 size_t __hash_code() const _NOEXCEPT;
480 template <size_t _Size>
481 inline _LIBCPP_INLINE_VISIBILITY
483 __bitset<1, _Size>::__bitset() _NOEXCEPT
488 template <size_t _Size>
489 inline _LIBCPP_INLINE_VISIBILITY
491 __bitset<1, _Size>::__bitset(unsigned long long __v) _NOEXCEPT
492 : __first_(static_cast<__storage_type>(__v))
496 template <size_t _Size>
497 inline _LIBCPP_INLINE_VISIBILITY
499 __bitset<1, _Size>::operator&=(const __bitset& __v) _NOEXCEPT
501 __first_ &= __v.__first_;
504 template <size_t _Size>
505 inline _LIBCPP_INLINE_VISIBILITY
507 __bitset<1, _Size>::operator|=(const __bitset& __v) _NOEXCEPT
509 __first_ |= __v.__first_;
512 template <size_t _Size>
513 inline _LIBCPP_INLINE_VISIBILITY
515 __bitset<1, _Size>::operator^=(const __bitset& __v) _NOEXCEPT
517 __first_ ^= __v.__first_;
520 template <size_t _Size>
521 inline _LIBCPP_INLINE_VISIBILITY
523 __bitset<1, _Size>::flip() _NOEXCEPT
525 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
526 __first_ = ~__first_;
530 template <size_t _Size>
531 inline _LIBCPP_INLINE_VISIBILITY
533 __bitset<1, _Size>::to_ulong() const
538 template <size_t _Size>
539 inline _LIBCPP_INLINE_VISIBILITY
541 __bitset<1, _Size>::to_ullong() const
546 template <size_t _Size>
547 inline _LIBCPP_INLINE_VISIBILITY
549 __bitset<1, _Size>::all() const _NOEXCEPT
551 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
552 return !(~__first_ & __m);
555 template <size_t _Size>
556 inline _LIBCPP_INLINE_VISIBILITY
558 __bitset<1, _Size>::any() const _NOEXCEPT
560 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
561 return __first_ & __m;
564 template <size_t _Size>
565 inline _LIBCPP_INLINE_VISIBILITY
567 __bitset<1, _Size>::__hash_code() const _NOEXCEPT
576 typedef ptrdiff_t difference_type;
577 typedef size_t size_type;
578 typedef size_type __storage_type;
580 typedef __bitset __self;
581 typedef __storage_type* __storage_pointer;
582 typedef const __storage_type* __const_storage_pointer;
583 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
585 friend class __bit_reference<__bitset>;
586 friend class __bit_const_reference<__bitset>;
587 friend class __bit_iterator<__bitset, false>;
588 friend class __bit_iterator<__bitset, true>;
589 friend struct __bit_array<__bitset>;
591 typedef __bit_reference<__bitset> reference;
592 typedef __bit_const_reference<__bitset> const_reference;
593 typedef __bit_iterator<__bitset, false> iterator;
594 typedef __bit_iterator<__bitset, true> const_iterator;
596 _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
597 explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long) _NOEXCEPT;
599 _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t) _NOEXCEPT
600 {return reference(0, 1);}
601 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t) const _NOEXCEPT
602 {return const_reference(0, 1);}
603 _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t) _NOEXCEPT
604 {return iterator(0, 0);}
605 _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t) const _NOEXCEPT
606 {return const_iterator(0, 0);}
608 _LIBCPP_INLINE_VISIBILITY void operator&=(const __bitset&) _NOEXCEPT {}
609 _LIBCPP_INLINE_VISIBILITY void operator|=(const __bitset&) _NOEXCEPT {}
610 _LIBCPP_INLINE_VISIBILITY void operator^=(const __bitset&) _NOEXCEPT {}
612 _LIBCPP_INLINE_VISIBILITY void flip() _NOEXCEPT {}
614 _LIBCPP_INLINE_VISIBILITY unsigned long to_ulong() const {return 0;}
615 _LIBCPP_INLINE_VISIBILITY unsigned long long to_ullong() const {return 0;}
617 _LIBCPP_INLINE_VISIBILITY bool all() const _NOEXCEPT {return true;}
618 _LIBCPP_INLINE_VISIBILITY bool any() const _NOEXCEPT {return false;}
620 _LIBCPP_INLINE_VISIBILITY size_t __hash_code() const _NOEXCEPT {return 0;}
623 inline _LIBCPP_INLINE_VISIBILITY
625 __bitset<0, 0>::__bitset() _NOEXCEPT
629 inline _LIBCPP_INLINE_VISIBILITY
631 __bitset<0, 0>::__bitset(unsigned long long) _NOEXCEPT
635 template <size_t _Size> class _LIBCPP_TYPE_VIS_ONLY bitset;
636 template <size_t _Size> struct _LIBCPP_TYPE_VIS_ONLY hash<bitset<_Size> >;
638 template <size_t _Size>
639 class _LIBCPP_TYPE_VIS_ONLY bitset
640 : private __bitset<_Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1, _Size>
643 static const unsigned __n_words = _Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1;
644 typedef __bitset<__n_words, _Size> base;
647 typedef typename base::reference reference;
648 typedef typename base::const_reference const_reference;
650 // 23.3.5.1 constructors:
651 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bitset() _NOEXCEPT {}
652 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
653 bitset(unsigned long long __v) _NOEXCEPT : base(__v) {}
654 template<class _CharT>
655 explicit bitset(const _CharT* __str,
656 typename basic_string<_CharT>::size_type __n = basic_string<_CharT>::npos,
657 _CharT __zero = _CharT('0'), _CharT __one = _CharT('1'));
658 template<class _CharT, class _Traits, class _Allocator>
659 explicit bitset(const basic_string<_CharT,_Traits,_Allocator>& __str,
660 typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos = 0,
661 typename basic_string<_CharT,_Traits,_Allocator>::size_type __n =
662 (basic_string<_CharT,_Traits,_Allocator>::npos),
663 _CharT __zero = _CharT('0'), _CharT __one = _CharT('1'));
665 // 23.3.5.2 bitset operations:
666 bitset& operator&=(const bitset& __rhs) _NOEXCEPT;
667 bitset& operator|=(const bitset& __rhs) _NOEXCEPT;
668 bitset& operator^=(const bitset& __rhs) _NOEXCEPT;
669 bitset& operator<<=(size_t __pos) _NOEXCEPT;
670 bitset& operator>>=(size_t __pos) _NOEXCEPT;
671 bitset& set() _NOEXCEPT;
672 bitset& set(size_t __pos, bool __val = true);
673 bitset& reset() _NOEXCEPT;
674 bitset& reset(size_t __pos);
675 bitset operator~() const _NOEXCEPT;
676 bitset& flip() _NOEXCEPT;
677 bitset& flip(size_t __pos);
680 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
681 const_reference operator[](size_t __p) const {return base::__make_ref(__p);}
682 _LIBCPP_INLINE_VISIBILITY reference operator[](size_t __p) {return base::__make_ref(__p);}
683 unsigned long to_ulong() const;
684 unsigned long long to_ullong() const;
685 template <class _CharT, class _Traits, class _Allocator>
686 basic_string<_CharT, _Traits, _Allocator> to_string(_CharT __zero = _CharT('0'),
687 _CharT __one = _CharT('1')) const;
688 template <class _CharT, class _Traits>
689 basic_string<_CharT, _Traits, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'),
690 _CharT __one = _CharT('1')) const;
691 template <class _CharT>
692 basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'),
693 _CharT __one = _CharT('1')) const;
694 basic_string<char, char_traits<char>, allocator<char> > to_string(char __zero = '0',
695 char __one = '1') const;
696 size_t count() const _NOEXCEPT;
697 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR size_t size() const _NOEXCEPT {return _Size;}
698 bool operator==(const bitset& __rhs) const _NOEXCEPT;
699 bool operator!=(const bitset& __rhs) const _NOEXCEPT;
700 bool test(size_t __pos) const;
701 bool all() const _NOEXCEPT;
702 bool any() const _NOEXCEPT;
703 _LIBCPP_INLINE_VISIBILITY bool none() const _NOEXCEPT {return !any();}
704 bitset operator<<(size_t __pos) const _NOEXCEPT;
705 bitset operator>>(size_t __pos) const _NOEXCEPT;
709 _LIBCPP_INLINE_VISIBILITY
710 size_t __hash_code() const _NOEXCEPT {return base::__hash_code();}
712 friend struct hash<bitset>;
715 template <size_t _Size>
716 template<class _CharT>
717 bitset<_Size>::bitset(const _CharT* __str,
718 typename basic_string<_CharT>::size_type __n,
719 _CharT __zero, _CharT __one)
721 size_t __rlen = _VSTD::min(__n, char_traits<_CharT>::length(__str));
722 for (size_t __i = 0; __i < __rlen; ++__i)
723 if (__str[__i] != __zero && __str[__i] != __one)
724 #ifndef _LIBCPP_NO_EXCEPTIONS
725 throw invalid_argument("bitset string ctor has invalid argument");
727 assert(!"bitset string ctor has invalid argument");
729 size_t _Mp = _VSTD::min(__rlen, _Size);
731 for (; __i < _Mp; ++__i)
733 _CharT __c = __str[_Mp - 1 - __i];
735 (*this)[__i] = false;
739 _VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false);
742 template <size_t _Size>
743 template<class _CharT, class _Traits, class _Allocator>
744 bitset<_Size>::bitset(const basic_string<_CharT,_Traits,_Allocator>& __str,
745 typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos,
746 typename basic_string<_CharT,_Traits,_Allocator>::size_type __n,
747 _CharT __zero, _CharT __one)
749 if (__pos > __str.size())
750 #ifndef _LIBCPP_NO_EXCEPTIONS
751 throw out_of_range("bitset string pos out of range");
753 assert(!"bitset string pos out of range");
755 size_t __rlen = _VSTD::min(__n, __str.size() - __pos);
756 for (size_t __i = __pos; __i < __pos + __rlen; ++__i)
757 if (!_Traits::eq(__str[__i], __zero) && !_Traits::eq(__str[__i], __one))
758 #ifndef _LIBCPP_NO_EXCEPTIONS
759 throw invalid_argument("bitset string ctor has invalid argument");
761 assert(!"bitset string ctor has invalid argument");
763 size_t _Mp = _VSTD::min(__rlen, _Size);
765 for (; __i < _Mp; ++__i)
767 _CharT __c = __str[__pos + _Mp - 1 - __i];
768 if (_Traits::eq(__c, __zero))
769 (*this)[__i] = false;
773 _VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false);
776 template <size_t _Size>
777 inline _LIBCPP_INLINE_VISIBILITY
779 bitset<_Size>::operator&=(const bitset& __rhs) _NOEXCEPT
781 base::operator&=(__rhs);
785 template <size_t _Size>
786 inline _LIBCPP_INLINE_VISIBILITY
788 bitset<_Size>::operator|=(const bitset& __rhs) _NOEXCEPT
790 base::operator|=(__rhs);
794 template <size_t _Size>
795 inline _LIBCPP_INLINE_VISIBILITY
797 bitset<_Size>::operator^=(const bitset& __rhs) _NOEXCEPT
799 base::operator^=(__rhs);
803 template <size_t _Size>
805 bitset<_Size>::operator<<=(size_t __pos) _NOEXCEPT
807 __pos = _VSTD::min(__pos, _Size);
808 _VSTD::copy_backward(base::__make_iter(0), base::__make_iter(_Size - __pos), base::__make_iter(_Size));
809 _VSTD::fill_n(base::__make_iter(0), __pos, false);
813 template <size_t _Size>
815 bitset<_Size>::operator>>=(size_t __pos) _NOEXCEPT
817 __pos = _VSTD::min(__pos, _Size);
818 _VSTD::copy(base::__make_iter(__pos), base::__make_iter(_Size), base::__make_iter(0));
819 _VSTD::fill_n(base::__make_iter(_Size - __pos), __pos, false);
823 template <size_t _Size>
824 inline _LIBCPP_INLINE_VISIBILITY
826 bitset<_Size>::set() _NOEXCEPT
828 _VSTD::fill_n(base::__make_iter(0), _Size, true);
832 template <size_t _Size>
834 bitset<_Size>::set(size_t __pos, bool __val)
837 #ifndef _LIBCPP_NO_EXCEPTIONS
838 throw out_of_range("bitset set argument out of range");
840 assert(!"bitset set argument out of range");
842 (*this)[__pos] = __val;
846 template <size_t _Size>
847 inline _LIBCPP_INLINE_VISIBILITY
849 bitset<_Size>::reset() _NOEXCEPT
851 _VSTD::fill_n(base::__make_iter(0), _Size, false);
855 template <size_t _Size>
857 bitset<_Size>::reset(size_t __pos)
860 #ifndef _LIBCPP_NO_EXCEPTIONS
861 throw out_of_range("bitset reset argument out of range");
863 assert(!"bitset reset argument out of range");
865 (*this)[__pos] = false;
869 template <size_t _Size>
870 inline _LIBCPP_INLINE_VISIBILITY
872 bitset<_Size>::operator~() const _NOEXCEPT
879 template <size_t _Size>
880 inline _LIBCPP_INLINE_VISIBILITY
882 bitset<_Size>::flip() _NOEXCEPT
888 template <size_t _Size>
890 bitset<_Size>::flip(size_t __pos)
893 #ifndef _LIBCPP_NO_EXCEPTIONS
894 throw out_of_range("bitset flip argument out of range");
896 assert(!"bitset flip argument out of range");
898 reference r = base::__make_ref(__pos);
903 template <size_t _Size>
904 inline _LIBCPP_INLINE_VISIBILITY
906 bitset<_Size>::to_ulong() const
908 return base::to_ulong();
911 template <size_t _Size>
912 inline _LIBCPP_INLINE_VISIBILITY
914 bitset<_Size>::to_ullong() const
916 return base::to_ullong();
919 template <size_t _Size>
920 template <class _CharT, class _Traits, class _Allocator>
921 basic_string<_CharT, _Traits, _Allocator>
922 bitset<_Size>::to_string(_CharT __zero, _CharT __one) const
924 basic_string<_CharT, _Traits, _Allocator> __r(_Size, __zero);
925 for (size_t __i = 0; __i < _Size; ++__i)
928 __r[_Size - 1 - __i] = __one;
933 template <size_t _Size>
934 template <class _CharT, class _Traits>
935 inline _LIBCPP_INLINE_VISIBILITY
936 basic_string<_CharT, _Traits, allocator<_CharT> >
937 bitset<_Size>::to_string(_CharT __zero, _CharT __one) const
939 return to_string<_CharT, _Traits, allocator<_CharT> >(__zero, __one);
942 template <size_t _Size>
943 template <class _CharT>
944 inline _LIBCPP_INLINE_VISIBILITY
945 basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> >
946 bitset<_Size>::to_string(_CharT __zero, _CharT __one) const
948 return to_string<_CharT, char_traits<_CharT>, allocator<_CharT> >(__zero, __one);
951 template <size_t _Size>
952 inline _LIBCPP_INLINE_VISIBILITY
953 basic_string<char, char_traits<char>, allocator<char> >
954 bitset<_Size>::to_string(char __zero, char __one) const
956 return to_string<char, char_traits<char>, allocator<char> >(__zero, __one);
959 template <size_t _Size>
960 inline _LIBCPP_INLINE_VISIBILITY
962 bitset<_Size>::count() const _NOEXCEPT
964 return static_cast<size_t>(_VSTD::count(base::__make_iter(0), base::__make_iter(_Size), true));
967 template <size_t _Size>
968 inline _LIBCPP_INLINE_VISIBILITY
970 bitset<_Size>::operator==(const bitset& __rhs) const _NOEXCEPT
972 return _VSTD::equal(base::__make_iter(0), base::__make_iter(_Size), __rhs.__make_iter(0));
975 template <size_t _Size>
976 inline _LIBCPP_INLINE_VISIBILITY
978 bitset<_Size>::operator!=(const bitset& __rhs) const _NOEXCEPT
980 return !(*this == __rhs);
983 template <size_t _Size>
985 bitset<_Size>::test(size_t __pos) const
988 #ifndef _LIBCPP_NO_EXCEPTIONS
989 throw out_of_range("bitset test argument out of range");
991 assert(!"bitset test argument out of range");
993 return (*this)[__pos];
996 template <size_t _Size>
997 inline _LIBCPP_INLINE_VISIBILITY
999 bitset<_Size>::all() const _NOEXCEPT
1004 template <size_t _Size>
1005 inline _LIBCPP_INLINE_VISIBILITY
1007 bitset<_Size>::any() const _NOEXCEPT
1012 template <size_t _Size>
1013 inline _LIBCPP_INLINE_VISIBILITY
1015 bitset<_Size>::operator<<(size_t __pos) const _NOEXCEPT
1022 template <size_t _Size>
1023 inline _LIBCPP_INLINE_VISIBILITY
1025 bitset<_Size>::operator>>(size_t __pos) const _NOEXCEPT
1032 template <size_t _Size>
1033 inline _LIBCPP_INLINE_VISIBILITY
1035 operator&(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT
1037 bitset<_Size> __r = __x;
1042 template <size_t _Size>
1043 inline _LIBCPP_INLINE_VISIBILITY
1045 operator|(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT
1047 bitset<_Size> __r = __x;
1052 template <size_t _Size>
1053 inline _LIBCPP_INLINE_VISIBILITY
1055 operator^(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT
1057 bitset<_Size> __r = __x;
1062 template <size_t _Size>
1063 struct _LIBCPP_TYPE_VIS_ONLY hash<bitset<_Size> >
1064 : public unary_function<bitset<_Size>, size_t>
1066 _LIBCPP_INLINE_VISIBILITY
1067 size_t operator()(const bitset<_Size>& __bs) const _NOEXCEPT
1068 {return __bs.__hash_code();}
1071 template <class _CharT, class _Traits, size_t _Size>
1072 basic_istream<_CharT, _Traits>&
1073 operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x);
1075 template <class _CharT, class _Traits, size_t _Size>
1076 basic_ostream<_CharT, _Traits>&
1077 operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x);
1079 _LIBCPP_END_NAMESPACE_STD
1081 #endif // _LIBCPP_BITSET