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>>;
117 #include <__bit_reference>
123 #include <__functional_base>
125 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
126 #pragma GCC system_header
130 #include <__undef_macros>
133 _LIBCPP_BEGIN_NAMESPACE_STD
135 template <size_t _N_words, size_t _Size>
138 template <size_t _N_words, size_t _Size>
139 struct __has_storage_type<__bitset<_N_words, _Size> >
141 static const bool value = true;
144 template <size_t _N_words, size_t _Size>
148 typedef ptrdiff_t difference_type;
149 typedef size_t size_type;
150 typedef size_type __storage_type;
152 typedef __bitset __self;
153 typedef __storage_type* __storage_pointer;
154 typedef const __storage_type* __const_storage_pointer;
155 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
157 friend class __bit_reference<__bitset>;
158 friend class __bit_const_reference<__bitset>;
159 friend class __bit_iterator<__bitset, false>;
160 friend class __bit_iterator<__bitset, true>;
161 friend struct __bit_array<__bitset>;
163 __storage_type __first_[_N_words];
165 typedef __bit_reference<__bitset> reference;
166 typedef __bit_const_reference<__bitset> const_reference;
167 typedef __bit_iterator<__bitset, false> iterator;
168 typedef __bit_iterator<__bitset, true> const_iterator;
170 _LIBCPP_INLINE_VISIBILITY
171 _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
172 _LIBCPP_INLINE_VISIBILITY
173 explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT;
175 _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t __pos) _NOEXCEPT
176 {return reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
177 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT
178 {return const_reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
179 _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t __pos) _NOEXCEPT
180 {return iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
181 _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t __pos) const _NOEXCEPT
182 {return const_iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
184 _LIBCPP_INLINE_VISIBILITY
185 void operator&=(const __bitset& __v) _NOEXCEPT;
186 _LIBCPP_INLINE_VISIBILITY
187 void operator|=(const __bitset& __v) _NOEXCEPT;
188 _LIBCPP_INLINE_VISIBILITY
189 void operator^=(const __bitset& __v) _NOEXCEPT;
191 void flip() _NOEXCEPT;
192 _LIBCPP_INLINE_VISIBILITY unsigned long to_ulong() const
193 {return to_ulong(integral_constant<bool, _Size < sizeof(unsigned long) * CHAR_BIT>());}
194 _LIBCPP_INLINE_VISIBILITY unsigned long long to_ullong() const
195 {return to_ullong(integral_constant<bool, _Size < sizeof(unsigned long long) * CHAR_BIT>());}
197 bool all() const _NOEXCEPT;
198 bool any() const _NOEXCEPT;
199 _LIBCPP_INLINE_VISIBILITY
200 size_t __hash_code() const _NOEXCEPT;
202 #ifdef _LIBCPP_CXX03_LANG
203 void __init(unsigned long long __v, false_type) _NOEXCEPT;
204 _LIBCPP_INLINE_VISIBILITY
205 void __init(unsigned long long __v, true_type) _NOEXCEPT;
206 #endif // _LIBCPP_CXX03_LANG
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_CXX03_LANG
226 #ifdef _LIBCPP_CXX03_LANG
227 _VSTD::fill_n(__first_, _N_words, __storage_type(0));
231 #ifdef _LIBCPP_CXX03_LANG
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_CXX03_LANG
256 template <size_t _N_words, size_t _Size>
259 __bitset<_N_words, _Size>::__bitset(unsigned long long __v) _NOEXCEPT
260 #ifndef _LIBCPP_CXX03_LANG
261 #if __SIZEOF_SIZE_T__ == 8
263 #elif __SIZEOF_SIZE_T__ == 4
264 : __first_{static_cast<__storage_type>(__v), static_cast<__storage_type>(__v >> __bits_per_word)}
266 #error This constructor has not been ported to this platform
270 #ifdef _LIBCPP_CXX03_LANG
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 __throw_overflow_error("bitset to_ulong overflow error");
333 template <size_t _N_words, size_t _Size>
336 __bitset<_N_words, _Size>::to_ulong(true_type) const
341 template <size_t _N_words, size_t _Size>
343 __bitset<_N_words, _Size>::to_ullong(false_type) const
345 const_iterator __e = __make_iter(_Size);
346 const_iterator __i = _VSTD::find(__make_iter(sizeof(unsigned long long) * CHAR_BIT), __e, true);
348 __throw_overflow_error("bitset to_ullong overflow error");
350 return to_ullong(true_type());
353 template <size_t _N_words, size_t _Size>
356 __bitset<_N_words, _Size>::to_ullong(true_type) const
358 return to_ullong(true_type(), integral_constant<bool, sizeof(__storage_type) < sizeof(unsigned long long)>());
361 template <size_t _N_words, size_t _Size>
364 __bitset<_N_words, _Size>::to_ullong(true_type, false_type) const
369 template <size_t _N_words, size_t _Size>
371 __bitset<_N_words, _Size>::to_ullong(true_type, true_type) const
373 unsigned long long __r = __first_[0];
374 for (std::size_t __i = 1; __i < sizeof(unsigned long long) / sizeof(__storage_type); ++__i)
375 __r |= static_cast<unsigned long long>(__first_[__i]) << (sizeof(__storage_type) * CHAR_BIT);
379 template <size_t _N_words, size_t _Size>
381 __bitset<_N_words, _Size>::all() const _NOEXCEPT
383 // do middle whole words
384 size_type __n = _Size;
385 __const_storage_pointer __p = __first_;
386 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
389 // do last partial word
392 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
399 template <size_t _N_words, size_t _Size>
401 __bitset<_N_words, _Size>::any() const _NOEXCEPT
403 // do middle whole words
404 size_type __n = _Size;
405 __const_storage_pointer __p = __first_;
406 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
409 // do last partial word
412 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
419 template <size_t _N_words, size_t _Size>
422 __bitset<_N_words, _Size>::__hash_code() const _NOEXCEPT
425 for (size_type __i = 0; __i < _N_words; ++__i)
426 __h ^= __first_[__i];
430 template <size_t _Size>
431 class __bitset<1, _Size>
434 typedef ptrdiff_t difference_type;
435 typedef size_t size_type;
436 typedef size_type __storage_type;
438 typedef __bitset __self;
439 typedef __storage_type* __storage_pointer;
440 typedef const __storage_type* __const_storage_pointer;
441 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
443 friend class __bit_reference<__bitset>;
444 friend class __bit_const_reference<__bitset>;
445 friend class __bit_iterator<__bitset, false>;
446 friend class __bit_iterator<__bitset, true>;
447 friend struct __bit_array<__bitset>;
449 __storage_type __first_;
451 typedef __bit_reference<__bitset> reference;
452 typedef __bit_const_reference<__bitset> const_reference;
453 typedef __bit_iterator<__bitset, false> iterator;
454 typedef __bit_iterator<__bitset, true> const_iterator;
456 _LIBCPP_INLINE_VISIBILITY
457 _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
458 _LIBCPP_INLINE_VISIBILITY
459 explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT;
461 _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t __pos) _NOEXCEPT
462 {return reference(&__first_, __storage_type(1) << __pos);}
463 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT
464 {return const_reference(&__first_, __storage_type(1) << __pos);}
465 _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t __pos) _NOEXCEPT
466 {return iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
467 _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t __pos) const _NOEXCEPT
468 {return const_iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
470 _LIBCPP_INLINE_VISIBILITY
471 void operator&=(const __bitset& __v) _NOEXCEPT;
472 _LIBCPP_INLINE_VISIBILITY
473 void operator|=(const __bitset& __v) _NOEXCEPT;
474 _LIBCPP_INLINE_VISIBILITY
475 void operator^=(const __bitset& __v) _NOEXCEPT;
477 _LIBCPP_INLINE_VISIBILITY
478 void flip() _NOEXCEPT;
480 _LIBCPP_INLINE_VISIBILITY
481 unsigned long to_ulong() const;
482 _LIBCPP_INLINE_VISIBILITY
483 unsigned long long to_ullong() const;
485 _LIBCPP_INLINE_VISIBILITY
486 bool all() const _NOEXCEPT;
487 _LIBCPP_INLINE_VISIBILITY
488 bool any() const _NOEXCEPT;
490 _LIBCPP_INLINE_VISIBILITY
491 size_t __hash_code() const _NOEXCEPT;
494 template <size_t _Size>
497 __bitset<1, _Size>::__bitset() _NOEXCEPT
502 template <size_t _Size>
505 __bitset<1, _Size>::__bitset(unsigned long long __v) _NOEXCEPT
506 : __first_(static_cast<__storage_type>(__v))
510 template <size_t _Size>
513 __bitset<1, _Size>::operator&=(const __bitset& __v) _NOEXCEPT
515 __first_ &= __v.__first_;
518 template <size_t _Size>
521 __bitset<1, _Size>::operator|=(const __bitset& __v) _NOEXCEPT
523 __first_ |= __v.__first_;
526 template <size_t _Size>
529 __bitset<1, _Size>::operator^=(const __bitset& __v) _NOEXCEPT
531 __first_ ^= __v.__first_;
534 template <size_t _Size>
537 __bitset<1, _Size>::flip() _NOEXCEPT
539 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
540 __first_ = ~__first_;
544 template <size_t _Size>
547 __bitset<1, _Size>::to_ulong() const
552 template <size_t _Size>
555 __bitset<1, _Size>::to_ullong() const
560 template <size_t _Size>
563 __bitset<1, _Size>::all() const _NOEXCEPT
565 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
566 return !(~__first_ & __m);
569 template <size_t _Size>
572 __bitset<1, _Size>::any() const _NOEXCEPT
574 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
575 return __first_ & __m;
578 template <size_t _Size>
581 __bitset<1, _Size>::__hash_code() const _NOEXCEPT
590 typedef ptrdiff_t difference_type;
591 typedef size_t size_type;
592 typedef size_type __storage_type;
594 typedef __bitset __self;
595 typedef __storage_type* __storage_pointer;
596 typedef const __storage_type* __const_storage_pointer;
597 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
599 friend class __bit_reference<__bitset>;
600 friend class __bit_const_reference<__bitset>;
601 friend class __bit_iterator<__bitset, false>;
602 friend class __bit_iterator<__bitset, true>;
603 friend struct __bit_array<__bitset>;
605 typedef __bit_reference<__bitset> reference;
606 typedef __bit_const_reference<__bitset> const_reference;
607 typedef __bit_iterator<__bitset, false> iterator;
608 typedef __bit_iterator<__bitset, true> const_iterator;
610 _LIBCPP_INLINE_VISIBILITY
611 _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
612 _LIBCPP_INLINE_VISIBILITY
613 explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long) _NOEXCEPT;
615 _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t) _NOEXCEPT
616 {return reference(0, 1);}
617 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t) const _NOEXCEPT
618 {return const_reference(0, 1);}
619 _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t) _NOEXCEPT
620 {return iterator(0, 0);}
621 _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t) const _NOEXCEPT
622 {return const_iterator(0, 0);}
624 _LIBCPP_INLINE_VISIBILITY void operator&=(const __bitset&) _NOEXCEPT {}
625 _LIBCPP_INLINE_VISIBILITY void operator|=(const __bitset&) _NOEXCEPT {}
626 _LIBCPP_INLINE_VISIBILITY void operator^=(const __bitset&) _NOEXCEPT {}
628 _LIBCPP_INLINE_VISIBILITY void flip() _NOEXCEPT {}
630 _LIBCPP_INLINE_VISIBILITY unsigned long to_ulong() const {return 0;}
631 _LIBCPP_INLINE_VISIBILITY unsigned long long to_ullong() const {return 0;}
633 _LIBCPP_INLINE_VISIBILITY bool all() const _NOEXCEPT {return true;}
634 _LIBCPP_INLINE_VISIBILITY bool any() const _NOEXCEPT {return false;}
636 _LIBCPP_INLINE_VISIBILITY size_t __hash_code() const _NOEXCEPT {return 0;}
641 __bitset<0, 0>::__bitset() _NOEXCEPT
647 __bitset<0, 0>::__bitset(unsigned long long) _NOEXCEPT
651 template <size_t _Size> class _LIBCPP_TEMPLATE_VIS bitset;
652 template <size_t _Size> struct hash<bitset<_Size> >;
654 template <size_t _Size>
655 class _LIBCPP_TEMPLATE_VIS bitset
656 : private __bitset<_Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1, _Size>
659 static const unsigned __n_words = _Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1;
660 typedef __bitset<__n_words, _Size> base;
663 typedef typename base::reference reference;
664 typedef typename base::const_reference const_reference;
666 // 23.3.5.1 constructors:
667 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bitset() _NOEXCEPT {}
668 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
669 bitset(unsigned long long __v) _NOEXCEPT : base(__v) {}
670 template<class _CharT>
671 explicit bitset(const _CharT* __str,
672 typename basic_string<_CharT>::size_type __n = basic_string<_CharT>::npos,
673 _CharT __zero = _CharT('0'), _CharT __one = _CharT('1'));
674 template<class _CharT, class _Traits, class _Allocator>
675 explicit bitset(const basic_string<_CharT,_Traits,_Allocator>& __str,
676 typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos = 0,
677 typename basic_string<_CharT,_Traits,_Allocator>::size_type __n =
678 (basic_string<_CharT,_Traits,_Allocator>::npos),
679 _CharT __zero = _CharT('0'), _CharT __one = _CharT('1'));
681 // 23.3.5.2 bitset operations:
682 _LIBCPP_INLINE_VISIBILITY
683 bitset& operator&=(const bitset& __rhs) _NOEXCEPT;
684 _LIBCPP_INLINE_VISIBILITY
685 bitset& operator|=(const bitset& __rhs) _NOEXCEPT;
686 _LIBCPP_INLINE_VISIBILITY
687 bitset& operator^=(const bitset& __rhs) _NOEXCEPT;
688 bitset& operator<<=(size_t __pos) _NOEXCEPT;
689 bitset& operator>>=(size_t __pos) _NOEXCEPT;
690 _LIBCPP_INLINE_VISIBILITY
691 bitset& set() _NOEXCEPT;
692 bitset& set(size_t __pos, bool __val = true);
693 _LIBCPP_INLINE_VISIBILITY
694 bitset& reset() _NOEXCEPT;
695 bitset& reset(size_t __pos);
696 _LIBCPP_INLINE_VISIBILITY
697 bitset operator~() const _NOEXCEPT;
698 _LIBCPP_INLINE_VISIBILITY
699 bitset& flip() _NOEXCEPT;
700 bitset& flip(size_t __pos);
703 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
704 const_reference operator[](size_t __p) const {return base::__make_ref(__p);}
705 _LIBCPP_INLINE_VISIBILITY reference operator[](size_t __p) {return base::__make_ref(__p);}
706 _LIBCPP_INLINE_VISIBILITY
707 unsigned long to_ulong() const;
708 _LIBCPP_INLINE_VISIBILITY
709 unsigned long long to_ullong() const;
710 template <class _CharT, class _Traits, class _Allocator>
711 basic_string<_CharT, _Traits, _Allocator> to_string(_CharT __zero = _CharT('0'),
712 _CharT __one = _CharT('1')) const;
713 template <class _CharT, class _Traits>
714 _LIBCPP_INLINE_VISIBILITY
715 basic_string<_CharT, _Traits, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'),
716 _CharT __one = _CharT('1')) const;
717 template <class _CharT>
718 _LIBCPP_INLINE_VISIBILITY
719 basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'),
720 _CharT __one = _CharT('1')) const;
721 _LIBCPP_INLINE_VISIBILITY
722 basic_string<char, char_traits<char>, allocator<char> > to_string(char __zero = '0',
723 char __one = '1') const;
724 _LIBCPP_INLINE_VISIBILITY
725 size_t count() const _NOEXCEPT;
726 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR size_t size() const _NOEXCEPT {return _Size;}
727 _LIBCPP_INLINE_VISIBILITY
728 bool operator==(const bitset& __rhs) const _NOEXCEPT;
729 _LIBCPP_INLINE_VISIBILITY
730 bool operator!=(const bitset& __rhs) const _NOEXCEPT;
731 bool test(size_t __pos) const;
732 _LIBCPP_INLINE_VISIBILITY
733 bool all() const _NOEXCEPT;
734 _LIBCPP_INLINE_VISIBILITY
735 bool any() const _NOEXCEPT;
736 _LIBCPP_INLINE_VISIBILITY bool none() const _NOEXCEPT {return !any();}
737 _LIBCPP_INLINE_VISIBILITY
738 bitset operator<<(size_t __pos) const _NOEXCEPT;
739 _LIBCPP_INLINE_VISIBILITY
740 bitset operator>>(size_t __pos) const _NOEXCEPT;
744 _LIBCPP_INLINE_VISIBILITY
745 size_t __hash_code() const _NOEXCEPT {return base::__hash_code();}
747 friend struct hash<bitset>;
750 template <size_t _Size>
751 template<class _CharT>
752 bitset<_Size>::bitset(const _CharT* __str,
753 typename basic_string<_CharT>::size_type __n,
754 _CharT __zero, _CharT __one)
756 size_t __rlen = _VSTD::min(__n, char_traits<_CharT>::length(__str));
757 for (size_t __i = 0; __i < __rlen; ++__i)
758 if (__str[__i] != __zero && __str[__i] != __one)
759 __throw_invalid_argument("bitset string ctor has invalid argument");
761 size_t _Mp = _VSTD::min(__rlen, _Size);
763 for (; __i < _Mp; ++__i)
765 _CharT __c = __str[_Mp - 1 - __i];
767 (*this)[__i] = false;
771 _VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false);
774 template <size_t _Size>
775 template<class _CharT, class _Traits, class _Allocator>
776 bitset<_Size>::bitset(const basic_string<_CharT,_Traits,_Allocator>& __str,
777 typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos,
778 typename basic_string<_CharT,_Traits,_Allocator>::size_type __n,
779 _CharT __zero, _CharT __one)
781 if (__pos > __str.size())
782 __throw_out_of_range("bitset string pos out of range");
784 size_t __rlen = _VSTD::min(__n, __str.size() - __pos);
785 for (size_t __i = __pos; __i < __pos + __rlen; ++__i)
786 if (!_Traits::eq(__str[__i], __zero) && !_Traits::eq(__str[__i], __one))
787 __throw_invalid_argument("bitset string ctor has invalid argument");
789 size_t _Mp = _VSTD::min(__rlen, _Size);
791 for (; __i < _Mp; ++__i)
793 _CharT __c = __str[__pos + _Mp - 1 - __i];
794 if (_Traits::eq(__c, __zero))
795 (*this)[__i] = false;
799 _VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false);
802 template <size_t _Size>
805 bitset<_Size>::operator&=(const bitset& __rhs) _NOEXCEPT
807 base::operator&=(__rhs);
811 template <size_t _Size>
814 bitset<_Size>::operator|=(const bitset& __rhs) _NOEXCEPT
816 base::operator|=(__rhs);
820 template <size_t _Size>
823 bitset<_Size>::operator^=(const bitset& __rhs) _NOEXCEPT
825 base::operator^=(__rhs);
829 template <size_t _Size>
831 bitset<_Size>::operator<<=(size_t __pos) _NOEXCEPT
833 __pos = _VSTD::min(__pos, _Size);
834 _VSTD::copy_backward(base::__make_iter(0), base::__make_iter(_Size - __pos), base::__make_iter(_Size));
835 _VSTD::fill_n(base::__make_iter(0), __pos, false);
839 template <size_t _Size>
841 bitset<_Size>::operator>>=(size_t __pos) _NOEXCEPT
843 __pos = _VSTD::min(__pos, _Size);
844 _VSTD::copy(base::__make_iter(__pos), base::__make_iter(_Size), base::__make_iter(0));
845 _VSTD::fill_n(base::__make_iter(_Size - __pos), __pos, false);
849 template <size_t _Size>
852 bitset<_Size>::set() _NOEXCEPT
854 _VSTD::fill_n(base::__make_iter(0), _Size, true);
858 template <size_t _Size>
860 bitset<_Size>::set(size_t __pos, bool __val)
863 __throw_out_of_range("bitset set argument out of range");
865 (*this)[__pos] = __val;
869 template <size_t _Size>
872 bitset<_Size>::reset() _NOEXCEPT
874 _VSTD::fill_n(base::__make_iter(0), _Size, false);
878 template <size_t _Size>
880 bitset<_Size>::reset(size_t __pos)
883 __throw_out_of_range("bitset reset argument out of range");
885 (*this)[__pos] = false;
889 template <size_t _Size>
892 bitset<_Size>::operator~() const _NOEXCEPT
899 template <size_t _Size>
902 bitset<_Size>::flip() _NOEXCEPT
908 template <size_t _Size>
910 bitset<_Size>::flip(size_t __pos)
913 __throw_out_of_range("bitset flip argument out of range");
915 reference r = base::__make_ref(__pos);
920 template <size_t _Size>
923 bitset<_Size>::to_ulong() const
925 return base::to_ulong();
928 template <size_t _Size>
931 bitset<_Size>::to_ullong() const
933 return base::to_ullong();
936 template <size_t _Size>
937 template <class _CharT, class _Traits, class _Allocator>
938 basic_string<_CharT, _Traits, _Allocator>
939 bitset<_Size>::to_string(_CharT __zero, _CharT __one) const
941 basic_string<_CharT, _Traits, _Allocator> __r(_Size, __zero);
942 for (size_t __i = 0; __i < _Size; ++__i)
945 __r[_Size - 1 - __i] = __one;
950 template <size_t _Size>
951 template <class _CharT, class _Traits>
953 basic_string<_CharT, _Traits, allocator<_CharT> >
954 bitset<_Size>::to_string(_CharT __zero, _CharT __one) const
956 return to_string<_CharT, _Traits, allocator<_CharT> >(__zero, __one);
959 template <size_t _Size>
960 template <class _CharT>
962 basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> >
963 bitset<_Size>::to_string(_CharT __zero, _CharT __one) const
965 return to_string<_CharT, char_traits<_CharT>, allocator<_CharT> >(__zero, __one);
968 template <size_t _Size>
970 basic_string<char, char_traits<char>, allocator<char> >
971 bitset<_Size>::to_string(char __zero, char __one) const
973 return to_string<char, char_traits<char>, allocator<char> >(__zero, __one);
976 template <size_t _Size>
979 bitset<_Size>::count() const _NOEXCEPT
981 return static_cast<size_t>(_VSTD::count(base::__make_iter(0), base::__make_iter(_Size), true));
984 template <size_t _Size>
987 bitset<_Size>::operator==(const bitset& __rhs) const _NOEXCEPT
989 return _VSTD::equal(base::__make_iter(0), base::__make_iter(_Size), __rhs.__make_iter(0));
992 template <size_t _Size>
995 bitset<_Size>::operator!=(const bitset& __rhs) const _NOEXCEPT
997 return !(*this == __rhs);
1000 template <size_t _Size>
1002 bitset<_Size>::test(size_t __pos) const
1005 __throw_out_of_range("bitset test argument out of range");
1007 return (*this)[__pos];
1010 template <size_t _Size>
1013 bitset<_Size>::all() const _NOEXCEPT
1018 template <size_t _Size>
1021 bitset<_Size>::any() const _NOEXCEPT
1026 template <size_t _Size>
1029 bitset<_Size>::operator<<(size_t __pos) const _NOEXCEPT
1036 template <size_t _Size>
1039 bitset<_Size>::operator>>(size_t __pos) const _NOEXCEPT
1046 template <size_t _Size>
1047 inline _LIBCPP_INLINE_VISIBILITY
1049 operator&(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT
1051 bitset<_Size> __r = __x;
1056 template <size_t _Size>
1057 inline _LIBCPP_INLINE_VISIBILITY
1059 operator|(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT
1061 bitset<_Size> __r = __x;
1066 template <size_t _Size>
1067 inline _LIBCPP_INLINE_VISIBILITY
1069 operator^(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT
1071 bitset<_Size> __r = __x;
1076 template <size_t _Size>
1077 struct _LIBCPP_TEMPLATE_VIS hash<bitset<_Size> >
1078 : public unary_function<bitset<_Size>, size_t>
1080 _LIBCPP_INLINE_VISIBILITY
1081 size_t operator()(const bitset<_Size>& __bs) const _NOEXCEPT
1082 {return __bs.__hash_code();}
1085 template <class _CharT, class _Traits, size_t _Size>
1086 basic_istream<_CharT, _Traits>&
1087 operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x);
1089 template <class _CharT, class _Traits, size_t _Size>
1090 basic_ostream<_CharT, _Traits>&
1091 operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x);
1093 _LIBCPP_END_NAMESPACE_STD
1097 #endif // _LIBCPP_BITSET