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_INLINE_VISIBILITY
172 _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
173 _LIBCPP_INLINE_VISIBILITY
174 explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT;
176 _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t __pos) _NOEXCEPT
177 {return reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
178 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT
179 {return const_reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
180 _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t __pos) _NOEXCEPT
181 {return iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
182 _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t __pos) const _NOEXCEPT
183 {return const_iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
185 _LIBCPP_INLINE_VISIBILITY
186 void operator&=(const __bitset& __v) _NOEXCEPT;
187 _LIBCPP_INLINE_VISIBILITY
188 void operator|=(const __bitset& __v) _NOEXCEPT;
189 _LIBCPP_INLINE_VISIBILITY
190 void operator^=(const __bitset& __v) _NOEXCEPT;
192 void flip() _NOEXCEPT;
193 _LIBCPP_INLINE_VISIBILITY unsigned long to_ulong() const
194 {return to_ulong(integral_constant<bool, _Size < sizeof(unsigned long) * CHAR_BIT>());}
195 _LIBCPP_INLINE_VISIBILITY unsigned long long to_ullong() const
196 {return to_ullong(integral_constant<bool, _Size < sizeof(unsigned long long) * CHAR_BIT>());}
198 bool all() const _NOEXCEPT;
199 bool any() const _NOEXCEPT;
200 _LIBCPP_INLINE_VISIBILITY
201 size_t __hash_code() const _NOEXCEPT;
203 #ifdef _LIBCPP_HAS_NO_CONSTEXPR
204 void __init(unsigned long long __v, false_type) _NOEXCEPT;
205 void __init(unsigned long long __v, true_type) _NOEXCEPT;
206 #endif // _LIBCPP_HAS_NO_CONSTEXPR
207 unsigned long to_ulong(false_type) const;
208 _LIBCPP_INLINE_VISIBILITY
209 unsigned long to_ulong(true_type) const;
210 unsigned long long to_ullong(false_type) const;
211 _LIBCPP_INLINE_VISIBILITY
212 unsigned long long to_ullong(true_type) const;
213 _LIBCPP_INLINE_VISIBILITY
214 unsigned long long to_ullong(true_type, false_type) const;
215 unsigned long long to_ullong(true_type, true_type) const;
218 template <size_t _N_words, size_t _Size>
221 __bitset<_N_words, _Size>::__bitset() _NOEXCEPT
222 #ifndef _LIBCPP_HAS_NO_CONSTEXPR
226 #ifdef _LIBCPP_HAS_NO_CONSTEXPR
227 _VSTD::fill_n(__first_, _N_words, __storage_type(0));
231 #ifdef _LIBCPP_HAS_NO_CONSTEXPR
233 template <size_t _N_words, size_t _Size>
235 __bitset<_N_words, _Size>::__init(unsigned long long __v, false_type) _NOEXCEPT
237 __storage_type __t[sizeof(unsigned long long) / sizeof(__storage_type)];
238 for (size_t __i = 0; __i < sizeof(__t)/sizeof(__t[0]); ++__i, __v >>= __bits_per_word)
239 __t[__i] = static_cast<__storage_type>(__v);
240 _VSTD::copy(__t, __t + sizeof(__t)/sizeof(__t[0]), __first_);
241 _VSTD::fill(__first_ + sizeof(__t)/sizeof(__t[0]), __first_ + sizeof(__first_)/sizeof(__first_[0]),
245 template <size_t _N_words, size_t _Size>
246 inline _LIBCPP_INLINE_VISIBILITY
248 __bitset<_N_words, _Size>::__init(unsigned long long __v, true_type) _NOEXCEPT
251 _VSTD::fill(__first_ + 1, __first_ + sizeof(__first_)/sizeof(__first_[0]), __storage_type(0));
254 #endif // _LIBCPP_HAS_NO_CONSTEXPR
256 template <size_t _N_words, size_t _Size>
259 __bitset<_N_words, _Size>::__bitset(unsigned long long __v) _NOEXCEPT
260 #ifndef _LIBCPP_HAS_NO_CONSTEXPR
261 #if __SIZEOF_SIZE_T__ == 8
263 #elif __SIZEOF_SIZE_T__ == 4
264 : __first_{__v, __v >> __bits_per_word}
266 #error This constructor has not been ported to this platform
270 #ifdef _LIBCPP_HAS_NO_CONSTEXPR
271 __init(__v, integral_constant<bool, sizeof(unsigned long long) == sizeof(__storage_type)>());
275 template <size_t _N_words, size_t _Size>
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>
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>
296 __bitset<_N_words, _Size>::operator^=(const __bitset& __v) _NOEXCEPT
298 for (size_type __i = 0; __i < _N_words; ++__i)
299 __first_[__i] ^= __v.__first_[__i];
302 template <size_t _N_words, size_t _Size>
304 __bitset<_N_words, _Size>::flip() _NOEXCEPT
306 // do middle whole words
307 size_type __n = _Size;
308 __storage_pointer __p = __first_;
309 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
311 // do last partial word
314 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
315 __storage_type __b = *__p & __m;
321 template <size_t _N_words, size_t _Size>
323 __bitset<_N_words, _Size>::to_ulong(false_type) const
325 const_iterator __e = __make_iter(_Size);
326 const_iterator __i = _VSTD::find(__make_iter(sizeof(unsigned long) * CHAR_BIT), __e, true);
328 #ifndef _LIBCPP_NO_EXCEPTIONS
329 throw overflow_error("bitset to_ulong overflow error");
331 assert(!"bitset to_ulong overflow error");
336 template <size_t _N_words, size_t _Size>
339 __bitset<_N_words, _Size>::to_ulong(true_type) const
344 template <size_t _N_words, size_t _Size>
346 __bitset<_N_words, _Size>::to_ullong(false_type) const
348 const_iterator __e = __make_iter(_Size);
349 const_iterator __i = _VSTD::find(__make_iter(sizeof(unsigned long long) * CHAR_BIT), __e, true);
351 #ifndef _LIBCPP_NO_EXCEPTIONS
352 throw overflow_error("bitset to_ullong overflow error");
354 assert(!"bitset to_ullong overflow error");
356 return to_ullong(true_type());
359 template <size_t _N_words, size_t _Size>
362 __bitset<_N_words, _Size>::to_ullong(true_type) const
364 return to_ullong(true_type(), integral_constant<bool, sizeof(__storage_type) < sizeof(unsigned long long)>());
367 template <size_t _N_words, size_t _Size>
370 __bitset<_N_words, _Size>::to_ullong(true_type, false_type) const
375 template <size_t _N_words, size_t _Size>
377 __bitset<_N_words, _Size>::to_ullong(true_type, true_type) const
379 unsigned long long __r = __first_[0];
380 for (std::size_t __i = 1; __i < sizeof(unsigned long long) / sizeof(__storage_type); ++__i)
381 __r |= static_cast<unsigned long long>(__first_[__i]) << (sizeof(__storage_type) * CHAR_BIT);
385 template <size_t _N_words, size_t _Size>
387 __bitset<_N_words, _Size>::all() const _NOEXCEPT
389 // do middle whole words
390 size_type __n = _Size;
391 __const_storage_pointer __p = __first_;
392 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
395 // do last partial word
398 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
405 template <size_t _N_words, size_t _Size>
407 __bitset<_N_words, _Size>::any() const _NOEXCEPT
409 // do middle whole words
410 size_type __n = _Size;
411 __const_storage_pointer __p = __first_;
412 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
415 // do last partial word
418 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
425 template <size_t _N_words, size_t _Size>
428 __bitset<_N_words, _Size>::__hash_code() const _NOEXCEPT
431 for (size_type __i = 0; __i < _N_words; ++__i)
432 __h ^= __first_[__i];
436 template <size_t _Size>
437 class __bitset<1, _Size>
440 typedef ptrdiff_t difference_type;
441 typedef size_t size_type;
442 typedef size_type __storage_type;
444 typedef __bitset __self;
445 typedef __storage_type* __storage_pointer;
446 typedef const __storage_type* __const_storage_pointer;
447 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
449 friend class __bit_reference<__bitset>;
450 friend class __bit_const_reference<__bitset>;
451 friend class __bit_iterator<__bitset, false>;
452 friend class __bit_iterator<__bitset, true>;
453 friend struct __bit_array<__bitset>;
455 __storage_type __first_;
457 typedef __bit_reference<__bitset> reference;
458 typedef __bit_const_reference<__bitset> const_reference;
459 typedef __bit_iterator<__bitset, false> iterator;
460 typedef __bit_iterator<__bitset, true> const_iterator;
462 _LIBCPP_INLINE_VISIBILITY
463 _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
464 _LIBCPP_INLINE_VISIBILITY
465 explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT;
467 _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t __pos) _NOEXCEPT
468 {return reference(&__first_, __storage_type(1) << __pos);}
469 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT
470 {return const_reference(&__first_, __storage_type(1) << __pos);}
471 _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t __pos) _NOEXCEPT
472 {return iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
473 _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t __pos) const _NOEXCEPT
474 {return const_iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
476 _LIBCPP_INLINE_VISIBILITY
477 void operator&=(const __bitset& __v) _NOEXCEPT;
478 _LIBCPP_INLINE_VISIBILITY
479 void operator|=(const __bitset& __v) _NOEXCEPT;
480 _LIBCPP_INLINE_VISIBILITY
481 void operator^=(const __bitset& __v) _NOEXCEPT;
483 _LIBCPP_INLINE_VISIBILITY
484 void flip() _NOEXCEPT;
486 _LIBCPP_INLINE_VISIBILITY
487 unsigned long to_ulong() const;
488 _LIBCPP_INLINE_VISIBILITY
489 unsigned long long to_ullong() const;
491 _LIBCPP_INLINE_VISIBILITY
492 bool all() const _NOEXCEPT;
493 _LIBCPP_INLINE_VISIBILITY
494 bool any() const _NOEXCEPT;
496 _LIBCPP_INLINE_VISIBILITY
497 size_t __hash_code() const _NOEXCEPT;
500 template <size_t _Size>
503 __bitset<1, _Size>::__bitset() _NOEXCEPT
508 template <size_t _Size>
511 __bitset<1, _Size>::__bitset(unsigned long long __v) _NOEXCEPT
512 : __first_(static_cast<__storage_type>(__v))
516 template <size_t _Size>
519 __bitset<1, _Size>::operator&=(const __bitset& __v) _NOEXCEPT
521 __first_ &= __v.__first_;
524 template <size_t _Size>
527 __bitset<1, _Size>::operator|=(const __bitset& __v) _NOEXCEPT
529 __first_ |= __v.__first_;
532 template <size_t _Size>
535 __bitset<1, _Size>::operator^=(const __bitset& __v) _NOEXCEPT
537 __first_ ^= __v.__first_;
540 template <size_t _Size>
543 __bitset<1, _Size>::flip() _NOEXCEPT
545 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
546 __first_ = ~__first_;
550 template <size_t _Size>
553 __bitset<1, _Size>::to_ulong() const
558 template <size_t _Size>
561 __bitset<1, _Size>::to_ullong() const
566 template <size_t _Size>
569 __bitset<1, _Size>::all() const _NOEXCEPT
571 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
572 return !(~__first_ & __m);
575 template <size_t _Size>
578 __bitset<1, _Size>::any() const _NOEXCEPT
580 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
581 return __first_ & __m;
584 template <size_t _Size>
587 __bitset<1, _Size>::__hash_code() const _NOEXCEPT
596 typedef ptrdiff_t difference_type;
597 typedef size_t size_type;
598 typedef size_type __storage_type;
600 typedef __bitset __self;
601 typedef __storage_type* __storage_pointer;
602 typedef const __storage_type* __const_storage_pointer;
603 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
605 friend class __bit_reference<__bitset>;
606 friend class __bit_const_reference<__bitset>;
607 friend class __bit_iterator<__bitset, false>;
608 friend class __bit_iterator<__bitset, true>;
609 friend struct __bit_array<__bitset>;
611 typedef __bit_reference<__bitset> reference;
612 typedef __bit_const_reference<__bitset> const_reference;
613 typedef __bit_iterator<__bitset, false> iterator;
614 typedef __bit_iterator<__bitset, true> const_iterator;
616 _LIBCPP_INLINE_VISIBILITY
617 _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
618 _LIBCPP_INLINE_VISIBILITY
619 explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long) _NOEXCEPT;
621 _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t) _NOEXCEPT
622 {return reference(0, 1);}
623 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t) const _NOEXCEPT
624 {return const_reference(0, 1);}
625 _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t) _NOEXCEPT
626 {return iterator(0, 0);}
627 _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t) const _NOEXCEPT
628 {return const_iterator(0, 0);}
630 _LIBCPP_INLINE_VISIBILITY void operator&=(const __bitset&) _NOEXCEPT {}
631 _LIBCPP_INLINE_VISIBILITY void operator|=(const __bitset&) _NOEXCEPT {}
632 _LIBCPP_INLINE_VISIBILITY void operator^=(const __bitset&) _NOEXCEPT {}
634 _LIBCPP_INLINE_VISIBILITY void flip() _NOEXCEPT {}
636 _LIBCPP_INLINE_VISIBILITY unsigned long to_ulong() const {return 0;}
637 _LIBCPP_INLINE_VISIBILITY unsigned long long to_ullong() const {return 0;}
639 _LIBCPP_INLINE_VISIBILITY bool all() const _NOEXCEPT {return true;}
640 _LIBCPP_INLINE_VISIBILITY bool any() const _NOEXCEPT {return false;}
642 _LIBCPP_INLINE_VISIBILITY size_t __hash_code() const _NOEXCEPT {return 0;}
647 __bitset<0, 0>::__bitset() _NOEXCEPT
653 __bitset<0, 0>::__bitset(unsigned long long) _NOEXCEPT
657 template <size_t _Size> class _LIBCPP_TYPE_VIS_ONLY bitset;
658 template <size_t _Size> struct _LIBCPP_TYPE_VIS_ONLY hash<bitset<_Size> >;
660 template <size_t _Size>
661 class _LIBCPP_TYPE_VIS_ONLY bitset
662 : private __bitset<_Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1, _Size>
665 static const unsigned __n_words = _Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1;
666 typedef __bitset<__n_words, _Size> base;
669 typedef typename base::reference reference;
670 typedef typename base::const_reference const_reference;
672 // 23.3.5.1 constructors:
673 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bitset() _NOEXCEPT {}
674 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
675 bitset(unsigned long long __v) _NOEXCEPT : base(__v) {}
676 template<class _CharT>
677 explicit bitset(const _CharT* __str,
678 typename basic_string<_CharT>::size_type __n = basic_string<_CharT>::npos,
679 _CharT __zero = _CharT('0'), _CharT __one = _CharT('1'));
680 template<class _CharT, class _Traits, class _Allocator>
681 explicit bitset(const basic_string<_CharT,_Traits,_Allocator>& __str,
682 typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos = 0,
683 typename basic_string<_CharT,_Traits,_Allocator>::size_type __n =
684 (basic_string<_CharT,_Traits,_Allocator>::npos),
685 _CharT __zero = _CharT('0'), _CharT __one = _CharT('1'));
687 // 23.3.5.2 bitset operations:
688 _LIBCPP_INLINE_VISIBILITY
689 bitset& operator&=(const bitset& __rhs) _NOEXCEPT;
690 _LIBCPP_INLINE_VISIBILITY
691 bitset& operator|=(const bitset& __rhs) _NOEXCEPT;
692 _LIBCPP_INLINE_VISIBILITY
693 bitset& operator^=(const bitset& __rhs) _NOEXCEPT;
694 bitset& operator<<=(size_t __pos) _NOEXCEPT;
695 bitset& operator>>=(size_t __pos) _NOEXCEPT;
696 _LIBCPP_INLINE_VISIBILITY
697 bitset& set() _NOEXCEPT;
698 bitset& set(size_t __pos, bool __val = true);
699 _LIBCPP_INLINE_VISIBILITY
700 bitset& reset() _NOEXCEPT;
701 bitset& reset(size_t __pos);
702 _LIBCPP_INLINE_VISIBILITY
703 bitset operator~() const _NOEXCEPT;
704 _LIBCPP_INLINE_VISIBILITY
705 bitset& flip() _NOEXCEPT;
706 bitset& flip(size_t __pos);
709 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
710 const_reference operator[](size_t __p) const {return base::__make_ref(__p);}
711 _LIBCPP_INLINE_VISIBILITY reference operator[](size_t __p) {return base::__make_ref(__p);}
712 _LIBCPP_INLINE_VISIBILITY
713 unsigned long to_ulong() const;
714 _LIBCPP_INLINE_VISIBILITY
715 unsigned long long to_ullong() const;
716 template <class _CharT, class _Traits, class _Allocator>
717 basic_string<_CharT, _Traits, _Allocator> to_string(_CharT __zero = _CharT('0'),
718 _CharT __one = _CharT('1')) const;
719 template <class _CharT, class _Traits>
720 _LIBCPP_INLINE_VISIBILITY
721 basic_string<_CharT, _Traits, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'),
722 _CharT __one = _CharT('1')) const;
723 template <class _CharT>
724 _LIBCPP_INLINE_VISIBILITY
725 basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'),
726 _CharT __one = _CharT('1')) const;
727 _LIBCPP_INLINE_VISIBILITY
728 basic_string<char, char_traits<char>, allocator<char> > to_string(char __zero = '0',
729 char __one = '1') const;
730 _LIBCPP_INLINE_VISIBILITY
731 size_t count() const _NOEXCEPT;
732 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR size_t size() const _NOEXCEPT {return _Size;}
733 _LIBCPP_INLINE_VISIBILITY
734 bool operator==(const bitset& __rhs) const _NOEXCEPT;
735 _LIBCPP_INLINE_VISIBILITY
736 bool operator!=(const bitset& __rhs) const _NOEXCEPT;
737 bool test(size_t __pos) const;
738 _LIBCPP_INLINE_VISIBILITY
739 bool all() const _NOEXCEPT;
740 _LIBCPP_INLINE_VISIBILITY
741 bool any() const _NOEXCEPT;
742 _LIBCPP_INLINE_VISIBILITY bool none() const _NOEXCEPT {return !any();}
743 _LIBCPP_INLINE_VISIBILITY
744 bitset operator<<(size_t __pos) const _NOEXCEPT;
745 _LIBCPP_INLINE_VISIBILITY
746 bitset operator>>(size_t __pos) const _NOEXCEPT;
750 _LIBCPP_INLINE_VISIBILITY
751 size_t __hash_code() const _NOEXCEPT {return base::__hash_code();}
753 friend struct hash<bitset>;
756 template <size_t _Size>
757 template<class _CharT>
758 bitset<_Size>::bitset(const _CharT* __str,
759 typename basic_string<_CharT>::size_type __n,
760 _CharT __zero, _CharT __one)
762 size_t __rlen = _VSTD::min(__n, char_traits<_CharT>::length(__str));
763 for (size_t __i = 0; __i < __rlen; ++__i)
764 if (__str[__i] != __zero && __str[__i] != __one)
765 #ifndef _LIBCPP_NO_EXCEPTIONS
766 throw invalid_argument("bitset string ctor has invalid argument");
768 assert(!"bitset string ctor has invalid argument");
770 size_t _Mp = _VSTD::min(__rlen, _Size);
772 for (; __i < _Mp; ++__i)
774 _CharT __c = __str[_Mp - 1 - __i];
776 (*this)[__i] = false;
780 _VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false);
783 template <size_t _Size>
784 template<class _CharT, class _Traits, class _Allocator>
785 bitset<_Size>::bitset(const basic_string<_CharT,_Traits,_Allocator>& __str,
786 typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos,
787 typename basic_string<_CharT,_Traits,_Allocator>::size_type __n,
788 _CharT __zero, _CharT __one)
790 if (__pos > __str.size())
791 #ifndef _LIBCPP_NO_EXCEPTIONS
792 throw out_of_range("bitset string pos out of range");
794 assert(!"bitset string pos out of range");
796 size_t __rlen = _VSTD::min(__n, __str.size() - __pos);
797 for (size_t __i = __pos; __i < __pos + __rlen; ++__i)
798 if (!_Traits::eq(__str[__i], __zero) && !_Traits::eq(__str[__i], __one))
799 #ifndef _LIBCPP_NO_EXCEPTIONS
800 throw invalid_argument("bitset string ctor has invalid argument");
802 assert(!"bitset string ctor has invalid argument");
804 size_t _Mp = _VSTD::min(__rlen, _Size);
806 for (; __i < _Mp; ++__i)
808 _CharT __c = __str[__pos + _Mp - 1 - __i];
809 if (_Traits::eq(__c, __zero))
810 (*this)[__i] = false;
814 _VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false);
817 template <size_t _Size>
820 bitset<_Size>::operator&=(const bitset& __rhs) _NOEXCEPT
822 base::operator&=(__rhs);
826 template <size_t _Size>
829 bitset<_Size>::operator|=(const bitset& __rhs) _NOEXCEPT
831 base::operator|=(__rhs);
835 template <size_t _Size>
838 bitset<_Size>::operator^=(const bitset& __rhs) _NOEXCEPT
840 base::operator^=(__rhs);
844 template <size_t _Size>
846 bitset<_Size>::operator<<=(size_t __pos) _NOEXCEPT
848 __pos = _VSTD::min(__pos, _Size);
849 _VSTD::copy_backward(base::__make_iter(0), base::__make_iter(_Size - __pos), base::__make_iter(_Size));
850 _VSTD::fill_n(base::__make_iter(0), __pos, false);
854 template <size_t _Size>
856 bitset<_Size>::operator>>=(size_t __pos) _NOEXCEPT
858 __pos = _VSTD::min(__pos, _Size);
859 _VSTD::copy(base::__make_iter(__pos), base::__make_iter(_Size), base::__make_iter(0));
860 _VSTD::fill_n(base::__make_iter(_Size - __pos), __pos, false);
864 template <size_t _Size>
867 bitset<_Size>::set() _NOEXCEPT
869 _VSTD::fill_n(base::__make_iter(0), _Size, true);
873 template <size_t _Size>
875 bitset<_Size>::set(size_t __pos, bool __val)
878 #ifndef _LIBCPP_NO_EXCEPTIONS
879 throw out_of_range("bitset set argument out of range");
881 assert(!"bitset set argument out of range");
883 (*this)[__pos] = __val;
887 template <size_t _Size>
890 bitset<_Size>::reset() _NOEXCEPT
892 _VSTD::fill_n(base::__make_iter(0), _Size, false);
896 template <size_t _Size>
898 bitset<_Size>::reset(size_t __pos)
901 #ifndef _LIBCPP_NO_EXCEPTIONS
902 throw out_of_range("bitset reset argument out of range");
904 assert(!"bitset reset argument out of range");
906 (*this)[__pos] = false;
910 template <size_t _Size>
913 bitset<_Size>::operator~() const _NOEXCEPT
920 template <size_t _Size>
923 bitset<_Size>::flip() _NOEXCEPT
929 template <size_t _Size>
931 bitset<_Size>::flip(size_t __pos)
934 #ifndef _LIBCPP_NO_EXCEPTIONS
935 throw out_of_range("bitset flip argument out of range");
937 assert(!"bitset flip argument out of range");
939 reference r = base::__make_ref(__pos);
944 template <size_t _Size>
947 bitset<_Size>::to_ulong() const
949 return base::to_ulong();
952 template <size_t _Size>
955 bitset<_Size>::to_ullong() const
957 return base::to_ullong();
960 template <size_t _Size>
961 template <class _CharT, class _Traits, class _Allocator>
962 basic_string<_CharT, _Traits, _Allocator>
963 bitset<_Size>::to_string(_CharT __zero, _CharT __one) const
965 basic_string<_CharT, _Traits, _Allocator> __r(_Size, __zero);
966 for (size_t __i = 0; __i < _Size; ++__i)
969 __r[_Size - 1 - __i] = __one;
974 template <size_t _Size>
975 template <class _CharT, class _Traits>
977 basic_string<_CharT, _Traits, allocator<_CharT> >
978 bitset<_Size>::to_string(_CharT __zero, _CharT __one) const
980 return to_string<_CharT, _Traits, allocator<_CharT> >(__zero, __one);
983 template <size_t _Size>
984 template <class _CharT>
986 basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> >
987 bitset<_Size>::to_string(_CharT __zero, _CharT __one) const
989 return to_string<_CharT, char_traits<_CharT>, allocator<_CharT> >(__zero, __one);
992 template <size_t _Size>
994 basic_string<char, char_traits<char>, allocator<char> >
995 bitset<_Size>::to_string(char __zero, char __one) const
997 return to_string<char, char_traits<char>, allocator<char> >(__zero, __one);
1000 template <size_t _Size>
1003 bitset<_Size>::count() const _NOEXCEPT
1005 return static_cast<size_t>(_VSTD::count(base::__make_iter(0), base::__make_iter(_Size), true));
1008 template <size_t _Size>
1011 bitset<_Size>::operator==(const bitset& __rhs) const _NOEXCEPT
1013 return _VSTD::equal(base::__make_iter(0), base::__make_iter(_Size), __rhs.__make_iter(0));
1016 template <size_t _Size>
1019 bitset<_Size>::operator!=(const bitset& __rhs) const _NOEXCEPT
1021 return !(*this == __rhs);
1024 template <size_t _Size>
1026 bitset<_Size>::test(size_t __pos) const
1029 #ifndef _LIBCPP_NO_EXCEPTIONS
1030 throw out_of_range("bitset test argument out of range");
1032 assert(!"bitset test argument out of range");
1034 return (*this)[__pos];
1037 template <size_t _Size>
1040 bitset<_Size>::all() const _NOEXCEPT
1045 template <size_t _Size>
1048 bitset<_Size>::any() const _NOEXCEPT
1053 template <size_t _Size>
1056 bitset<_Size>::operator<<(size_t __pos) const _NOEXCEPT
1063 template <size_t _Size>
1066 bitset<_Size>::operator>>(size_t __pos) const _NOEXCEPT
1073 template <size_t _Size>
1074 inline _LIBCPP_INLINE_VISIBILITY
1076 operator&(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT
1078 bitset<_Size> __r = __x;
1083 template <size_t _Size>
1084 inline _LIBCPP_INLINE_VISIBILITY
1086 operator|(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT
1088 bitset<_Size> __r = __x;
1093 template <size_t _Size>
1094 inline _LIBCPP_INLINE_VISIBILITY
1096 operator^(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT
1098 bitset<_Size> __r = __x;
1103 template <size_t _Size>
1104 struct _LIBCPP_TYPE_VIS_ONLY hash<bitset<_Size> >
1105 : public unary_function<bitset<_Size>, size_t>
1107 _LIBCPP_INLINE_VISIBILITY
1108 size_t operator()(const bitset<_Size>& __bs) const _NOEXCEPT
1109 {return __bs.__hash_code();}
1112 template <class _CharT, class _Traits, size_t _Size>
1113 basic_istream<_CharT, _Traits>&
1114 operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x);
1116 template <class _CharT, class _Traits, size_t _Size>
1117 basic_ostream<_CharT, _Traits>&
1118 operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x);
1120 _LIBCPP_END_NAMESPACE_STD
1122 #endif // _LIBCPP_BITSET