2 //===----------------------------------------------------------------------===//
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP_BITSET
11 #define _LIBCPP_BITSET
31 ~reference() noexcept;
32 reference& operator=(bool x) noexcept; // for b[i] = x;
33 reference& operator=(const reference&) noexcept; // for b[i] = b[j];
34 bool operator~() const noexcept; // flips the bit
35 operator bool() const noexcept; // for x = b[i];
36 reference& flip() noexcept; // for b[i].flip();
39 // 23.3.5.1 constructors:
40 constexpr bitset() noexcept;
41 constexpr bitset(unsigned long long val) noexcept;
42 template <class charT>
43 explicit bitset(const charT* str,
44 typename basic_string<charT>::size_type n = basic_string<charT>::npos,
45 charT zero = charT('0'), charT one = charT('1'));
46 template<class charT, class traits, class Allocator>
47 explicit bitset(const basic_string<charT,traits,Allocator>& str,
48 typename basic_string<charT,traits,Allocator>::size_type pos = 0,
49 typename basic_string<charT,traits,Allocator>::size_type n =
50 basic_string<charT,traits,Allocator>::npos,
51 charT zero = charT('0'), charT one = charT('1'));
53 // 23.3.5.2 bitset operations:
54 bitset& operator&=(const bitset& rhs) noexcept;
55 bitset& operator|=(const bitset& rhs) noexcept;
56 bitset& operator^=(const bitset& rhs) noexcept;
57 bitset& operator<<=(size_t pos) noexcept;
58 bitset& operator>>=(size_t pos) noexcept;
59 bitset& set() noexcept;
60 bitset& set(size_t pos, bool val = true);
61 bitset& reset() noexcept;
62 bitset& reset(size_t pos);
63 bitset operator~() const noexcept;
64 bitset& flip() noexcept;
65 bitset& flip(size_t pos);
68 constexpr bool operator[](size_t pos) const; // for b[i];
69 reference operator[](size_t pos); // for b[i];
70 unsigned long to_ulong() const;
71 unsigned long long to_ullong() const;
72 template <class charT, class traits, class Allocator>
73 basic_string<charT, traits, Allocator> to_string(charT zero = charT('0'), charT one = charT('1')) const;
74 template <class charT, class traits>
75 basic_string<charT, traits, allocator<charT> > to_string(charT zero = charT('0'), charT one = charT('1')) const;
76 template <class charT>
77 basic_string<charT, char_traits<charT>, allocator<charT> > to_string(charT zero = charT('0'), charT one = charT('1')) const;
78 basic_string<char, char_traits<char>, allocator<char> > to_string(char zero = '0', char one = '1') const;
79 size_t count() const noexcept;
80 constexpr size_t size() const noexcept;
81 bool operator==(const bitset& rhs) const noexcept;
82 bool operator!=(const bitset& rhs) const noexcept;
83 bool test(size_t pos) const;
84 bool all() const noexcept;
85 bool any() const noexcept;
86 bool none() const noexcept;
87 bitset operator<<(size_t pos) const noexcept;
88 bitset operator>>(size_t pos) const noexcept;
91 // 23.3.5.3 bitset operators:
93 bitset<N> operator&(const bitset<N>&, const bitset<N>&) noexcept;
96 bitset<N> operator|(const bitset<N>&, const bitset<N>&) noexcept;
99 bitset<N> operator^(const bitset<N>&, const bitset<N>&) noexcept;
101 template <class charT, class traits, size_t N>
102 basic_istream<charT, traits>&
103 operator>>(basic_istream<charT, traits>& is, bitset<N>& x);
105 template <class charT, class traits, size_t N>
106 basic_ostream<charT, traits>&
107 operator<<(basic_ostream<charT, traits>& os, const bitset<N>& x);
109 template <size_t N> struct hash<std::bitset<N>>;
115 #include <__bit_reference>
117 #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)];
239 for (size_t __i = 0; __i < sizeof(__t)/sizeof(__t[0]); ++__i, __v >>= __bits_per_word, __sz -= __bits_per_word )
240 if ( __sz < __bits_per_word)
241 __t[__i] = static_cast<__storage_type>(__v) & ( 1ULL << __sz ) - 1;
243 __t[__i] = static_cast<__storage_type>(__v);
245 _VSTD::copy(__t, __t + sizeof(__t)/sizeof(__t[0]), __first_);
246 _VSTD::fill(__first_ + sizeof(__t)/sizeof(__t[0]), __first_ + sizeof(__first_)/sizeof(__first_[0]),
250 template <size_t _N_words, size_t _Size>
251 inline _LIBCPP_INLINE_VISIBILITY
253 __bitset<_N_words, _Size>::__init(unsigned long long __v, true_type) _NOEXCEPT
256 if (_Size < __bits_per_word)
257 __first_[0] &= ( 1ULL << _Size ) - 1;
259 _VSTD::fill(__first_ + 1, __first_ + sizeof(__first_)/sizeof(__first_[0]), __storage_type(0));
262 #endif // _LIBCPP_CXX03_LANG
264 template <size_t _N_words, size_t _Size>
267 __bitset<_N_words, _Size>::__bitset(unsigned long long __v) _NOEXCEPT
268 #ifndef _LIBCPP_CXX03_LANG
269 #if __SIZEOF_SIZE_T__ == 8
271 #elif __SIZEOF_SIZE_T__ == 4
272 : __first_{static_cast<__storage_type>(__v),
273 _Size >= 2 * __bits_per_word ? static_cast<__storage_type>(__v >> __bits_per_word)
274 : static_cast<__storage_type>((__v >> __bits_per_word) & (__storage_type(1) << (_Size - __bits_per_word)) - 1)}
276 #error This constructor has not been ported to this platform
280 #ifdef _LIBCPP_CXX03_LANG
281 __init(__v, integral_constant<bool, sizeof(unsigned long long) == sizeof(__storage_type)>());
285 template <size_t _N_words, size_t _Size>
288 __bitset<_N_words, _Size>::operator&=(const __bitset& __v) _NOEXCEPT
290 for (size_type __i = 0; __i < _N_words; ++__i)
291 __first_[__i] &= __v.__first_[__i];
294 template <size_t _N_words, size_t _Size>
297 __bitset<_N_words, _Size>::operator|=(const __bitset& __v) _NOEXCEPT
299 for (size_type __i = 0; __i < _N_words; ++__i)
300 __first_[__i] |= __v.__first_[__i];
303 template <size_t _N_words, size_t _Size>
306 __bitset<_N_words, _Size>::operator^=(const __bitset& __v) _NOEXCEPT
308 for (size_type __i = 0; __i < _N_words; ++__i)
309 __first_[__i] ^= __v.__first_[__i];
312 template <size_t _N_words, size_t _Size>
314 __bitset<_N_words, _Size>::flip() _NOEXCEPT
316 // do middle whole words
317 size_type __n = _Size;
318 __storage_pointer __p = __first_;
319 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
321 // do last partial word
324 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
325 __storage_type __b = *__p & __m;
331 template <size_t _N_words, size_t _Size>
333 __bitset<_N_words, _Size>::to_ulong(false_type) const
335 const_iterator __e = __make_iter(_Size);
336 const_iterator __i = _VSTD::find(__make_iter(sizeof(unsigned long) * CHAR_BIT), __e, true);
338 __throw_overflow_error("bitset to_ulong overflow error");
343 template <size_t _N_words, size_t _Size>
346 __bitset<_N_words, _Size>::to_ulong(true_type) const
351 template <size_t _N_words, size_t _Size>
353 __bitset<_N_words, _Size>::to_ullong(false_type) const
355 const_iterator __e = __make_iter(_Size);
356 const_iterator __i = _VSTD::find(__make_iter(sizeof(unsigned long long) * CHAR_BIT), __e, true);
358 __throw_overflow_error("bitset to_ullong overflow error");
360 return to_ullong(true_type());
363 template <size_t _N_words, size_t _Size>
366 __bitset<_N_words, _Size>::to_ullong(true_type) const
368 return to_ullong(true_type(), integral_constant<bool, sizeof(__storage_type) < sizeof(unsigned long long)>());
371 template <size_t _N_words, size_t _Size>
374 __bitset<_N_words, _Size>::to_ullong(true_type, false_type) const
379 template <size_t _N_words, size_t _Size>
381 __bitset<_N_words, _Size>::to_ullong(true_type, true_type) const
383 unsigned long long __r = __first_[0];
384 for (size_t __i = 1; __i < sizeof(unsigned long long) / sizeof(__storage_type); ++__i)
385 __r |= static_cast<unsigned long long>(__first_[__i]) << (sizeof(__storage_type) * CHAR_BIT);
389 template <size_t _N_words, size_t _Size>
391 __bitset<_N_words, _Size>::all() const _NOEXCEPT
393 // do middle whole words
394 size_type __n = _Size;
395 __const_storage_pointer __p = __first_;
396 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
399 // do last partial word
402 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
409 template <size_t _N_words, size_t _Size>
411 __bitset<_N_words, _Size>::any() const _NOEXCEPT
413 // do middle whole words
414 size_type __n = _Size;
415 __const_storage_pointer __p = __first_;
416 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
419 // do last partial word
422 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
429 template <size_t _N_words, size_t _Size>
432 __bitset<_N_words, _Size>::__hash_code() const _NOEXCEPT
435 for (size_type __i = 0; __i < _N_words; ++__i)
436 __h ^= __first_[__i];
440 template <size_t _Size>
441 class __bitset<1, _Size>
444 typedef ptrdiff_t difference_type;
445 typedef size_t size_type;
446 typedef size_type __storage_type;
448 typedef __bitset __self;
449 typedef __storage_type* __storage_pointer;
450 typedef const __storage_type* __const_storage_pointer;
451 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
453 friend class __bit_reference<__bitset>;
454 friend class __bit_const_reference<__bitset>;
455 friend class __bit_iterator<__bitset, false>;
456 friend class __bit_iterator<__bitset, true>;
457 friend struct __bit_array<__bitset>;
459 __storage_type __first_;
461 typedef __bit_reference<__bitset> reference;
462 typedef __bit_const_reference<__bitset> const_reference;
463 typedef __bit_iterator<__bitset, false> iterator;
464 typedef __bit_iterator<__bitset, true> const_iterator;
466 _LIBCPP_INLINE_VISIBILITY
467 _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
468 _LIBCPP_INLINE_VISIBILITY
469 explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT;
471 _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t __pos) _NOEXCEPT
472 {return reference(&__first_, __storage_type(1) << __pos);}
473 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT
474 {return const_reference(&__first_, __storage_type(1) << __pos);}
475 _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t __pos) _NOEXCEPT
476 {return iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
477 _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t __pos) const _NOEXCEPT
478 {return const_iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
480 _LIBCPP_INLINE_VISIBILITY
481 void operator&=(const __bitset& __v) _NOEXCEPT;
482 _LIBCPP_INLINE_VISIBILITY
483 void operator|=(const __bitset& __v) _NOEXCEPT;
484 _LIBCPP_INLINE_VISIBILITY
485 void operator^=(const __bitset& __v) _NOEXCEPT;
487 _LIBCPP_INLINE_VISIBILITY
488 void flip() _NOEXCEPT;
490 _LIBCPP_INLINE_VISIBILITY
491 unsigned long to_ulong() const;
492 _LIBCPP_INLINE_VISIBILITY
493 unsigned long long to_ullong() const;
495 _LIBCPP_INLINE_VISIBILITY
496 bool all() const _NOEXCEPT;
497 _LIBCPP_INLINE_VISIBILITY
498 bool any() const _NOEXCEPT;
500 _LIBCPP_INLINE_VISIBILITY
501 size_t __hash_code() const _NOEXCEPT;
504 template <size_t _Size>
507 __bitset<1, _Size>::__bitset() _NOEXCEPT
512 template <size_t _Size>
515 __bitset<1, _Size>::__bitset(unsigned long long __v) _NOEXCEPT
517 _Size == __bits_per_word ? static_cast<__storage_type>(__v)
518 : static_cast<__storage_type>(__v) & ((__storage_type(1) << _Size) - 1)
523 template <size_t _Size>
526 __bitset<1, _Size>::operator&=(const __bitset& __v) _NOEXCEPT
528 __first_ &= __v.__first_;
531 template <size_t _Size>
534 __bitset<1, _Size>::operator|=(const __bitset& __v) _NOEXCEPT
536 __first_ |= __v.__first_;
539 template <size_t _Size>
542 __bitset<1, _Size>::operator^=(const __bitset& __v) _NOEXCEPT
544 __first_ ^= __v.__first_;
547 template <size_t _Size>
550 __bitset<1, _Size>::flip() _NOEXCEPT
552 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
553 __first_ = ~__first_;
557 template <size_t _Size>
560 __bitset<1, _Size>::to_ulong() const
565 template <size_t _Size>
568 __bitset<1, _Size>::to_ullong() const
573 template <size_t _Size>
576 __bitset<1, _Size>::all() const _NOEXCEPT
578 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
579 return !(~__first_ & __m);
582 template <size_t _Size>
585 __bitset<1, _Size>::any() const _NOEXCEPT
587 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
588 return __first_ & __m;
591 template <size_t _Size>
594 __bitset<1, _Size>::__hash_code() const _NOEXCEPT
603 typedef ptrdiff_t difference_type;
604 typedef size_t size_type;
605 typedef size_type __storage_type;
607 typedef __bitset __self;
608 typedef __storage_type* __storage_pointer;
609 typedef const __storage_type* __const_storage_pointer;
610 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
612 friend class __bit_reference<__bitset>;
613 friend class __bit_const_reference<__bitset>;
614 friend class __bit_iterator<__bitset, false>;
615 friend class __bit_iterator<__bitset, true>;
616 friend struct __bit_array<__bitset>;
618 typedef __bit_reference<__bitset> reference;
619 typedef __bit_const_reference<__bitset> const_reference;
620 typedef __bit_iterator<__bitset, false> iterator;
621 typedef __bit_iterator<__bitset, true> const_iterator;
623 _LIBCPP_INLINE_VISIBILITY
624 _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
625 _LIBCPP_INLINE_VISIBILITY
626 explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long) _NOEXCEPT;
628 _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t) _NOEXCEPT
629 {return reference(nullptr, 1);}
630 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t) const _NOEXCEPT
631 {return const_reference(nullptr, 1);}
632 _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t) _NOEXCEPT
633 {return iterator(nullptr, 0);}
634 _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t) const _NOEXCEPT
635 {return const_iterator(nullptr, 0);}
637 _LIBCPP_INLINE_VISIBILITY void operator&=(const __bitset&) _NOEXCEPT {}
638 _LIBCPP_INLINE_VISIBILITY void operator|=(const __bitset&) _NOEXCEPT {}
639 _LIBCPP_INLINE_VISIBILITY void operator^=(const __bitset&) _NOEXCEPT {}
641 _LIBCPP_INLINE_VISIBILITY void flip() _NOEXCEPT {}
643 _LIBCPP_INLINE_VISIBILITY unsigned long to_ulong() const {return 0;}
644 _LIBCPP_INLINE_VISIBILITY unsigned long long to_ullong() const {return 0;}
646 _LIBCPP_INLINE_VISIBILITY bool all() const _NOEXCEPT {return true;}
647 _LIBCPP_INLINE_VISIBILITY bool any() const _NOEXCEPT {return false;}
649 _LIBCPP_INLINE_VISIBILITY size_t __hash_code() const _NOEXCEPT {return 0;}
654 __bitset<0, 0>::__bitset() _NOEXCEPT
660 __bitset<0, 0>::__bitset(unsigned long long) _NOEXCEPT
664 template <size_t _Size> class _LIBCPP_TEMPLATE_VIS bitset;
665 template <size_t _Size> struct hash<bitset<_Size> >;
667 template <size_t _Size>
668 class _LIBCPP_TEMPLATE_VIS bitset
669 : private __bitset<_Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1, _Size>
672 static const unsigned __n_words = _Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1;
673 typedef __bitset<__n_words, _Size> base;
676 typedef typename base::reference reference;
677 typedef typename base::const_reference const_reference;
679 // 23.3.5.1 constructors:
680 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bitset() _NOEXCEPT {}
681 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
682 bitset(unsigned long long __v) _NOEXCEPT : base(__v) {}
683 template<class _CharT, class = __enable_if_t<_IsCharLikeType<_CharT>::value> >
684 explicit bitset(const _CharT* __str,
685 typename basic_string<_CharT>::size_type __n = basic_string<_CharT>::npos,
686 _CharT __zero = _CharT('0'), _CharT __one = _CharT('1'));
687 template<class _CharT, class _Traits, class _Allocator>
688 explicit bitset(const basic_string<_CharT,_Traits,_Allocator>& __str,
689 typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos = 0,
690 typename basic_string<_CharT,_Traits,_Allocator>::size_type __n =
691 (basic_string<_CharT,_Traits,_Allocator>::npos),
692 _CharT __zero = _CharT('0'), _CharT __one = _CharT('1'));
694 // 23.3.5.2 bitset operations:
695 _LIBCPP_INLINE_VISIBILITY
696 bitset& operator&=(const bitset& __rhs) _NOEXCEPT;
697 _LIBCPP_INLINE_VISIBILITY
698 bitset& operator|=(const bitset& __rhs) _NOEXCEPT;
699 _LIBCPP_INLINE_VISIBILITY
700 bitset& operator^=(const bitset& __rhs) _NOEXCEPT;
701 bitset& operator<<=(size_t __pos) _NOEXCEPT;
702 bitset& operator>>=(size_t __pos) _NOEXCEPT;
703 _LIBCPP_INLINE_VISIBILITY
704 bitset& set() _NOEXCEPT;
705 bitset& set(size_t __pos, bool __val = true);
706 _LIBCPP_INLINE_VISIBILITY
707 bitset& reset() _NOEXCEPT;
708 bitset& reset(size_t __pos);
709 _LIBCPP_INLINE_VISIBILITY
710 bitset operator~() const _NOEXCEPT;
711 _LIBCPP_INLINE_VISIBILITY
712 bitset& flip() _NOEXCEPT;
713 bitset& flip(size_t __pos);
716 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
717 const_reference operator[](size_t __p) const {return base::__make_ref(__p);}
718 _LIBCPP_INLINE_VISIBILITY reference operator[](size_t __p) {return base::__make_ref(__p);}
719 _LIBCPP_INLINE_VISIBILITY
720 unsigned long to_ulong() const;
721 _LIBCPP_INLINE_VISIBILITY
722 unsigned long long to_ullong() const;
723 template <class _CharT, class _Traits, class _Allocator>
724 basic_string<_CharT, _Traits, _Allocator> to_string(_CharT __zero = _CharT('0'),
725 _CharT __one = _CharT('1')) const;
726 template <class _CharT, class _Traits>
727 _LIBCPP_INLINE_VISIBILITY
728 basic_string<_CharT, _Traits, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'),
729 _CharT __one = _CharT('1')) const;
730 template <class _CharT>
731 _LIBCPP_INLINE_VISIBILITY
732 basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'),
733 _CharT __one = _CharT('1')) const;
734 _LIBCPP_INLINE_VISIBILITY
735 basic_string<char, char_traits<char>, allocator<char> > to_string(char __zero = '0',
736 char __one = '1') const;
737 _LIBCPP_INLINE_VISIBILITY
738 size_t count() const _NOEXCEPT;
739 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR size_t size() const _NOEXCEPT {return _Size;}
740 _LIBCPP_INLINE_VISIBILITY
741 bool operator==(const bitset& __rhs) const _NOEXCEPT;
742 _LIBCPP_INLINE_VISIBILITY
743 bool operator!=(const bitset& __rhs) const _NOEXCEPT;
744 bool test(size_t __pos) const;
745 _LIBCPP_INLINE_VISIBILITY
746 bool all() const _NOEXCEPT;
747 _LIBCPP_INLINE_VISIBILITY
748 bool any() const _NOEXCEPT;
749 _LIBCPP_INLINE_VISIBILITY bool none() const _NOEXCEPT {return !any();}
750 _LIBCPP_INLINE_VISIBILITY
751 bitset operator<<(size_t __pos) const _NOEXCEPT;
752 _LIBCPP_INLINE_VISIBILITY
753 bitset operator>>(size_t __pos) const _NOEXCEPT;
757 _LIBCPP_INLINE_VISIBILITY
758 size_t __hash_code() const _NOEXCEPT {return base::__hash_code();}
760 friend struct hash<bitset>;
763 template <size_t _Size>
764 template<class _CharT, class>
765 bitset<_Size>::bitset(const _CharT* __str,
766 typename basic_string<_CharT>::size_type __n,
767 _CharT __zero, _CharT __one)
769 size_t __rlen = _VSTD::min(__n, char_traits<_CharT>::length(__str));
770 for (size_t __i = 0; __i < __rlen; ++__i)
771 if (__str[__i] != __zero && __str[__i] != __one)
772 __throw_invalid_argument("bitset string ctor has invalid argument");
774 size_t _Mp = _VSTD::min(__rlen, _Size);
776 for (; __i < _Mp; ++__i)
778 _CharT __c = __str[_Mp - 1 - __i];
779 (*this)[__i] = (__c == __one);
781 _VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false);
784 template <size_t _Size>
785 template<class _CharT, class _Traits, class _Allocator>
786 bitset<_Size>::bitset(const basic_string<_CharT,_Traits,_Allocator>& __str,
787 typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos,
788 typename basic_string<_CharT,_Traits,_Allocator>::size_type __n,
789 _CharT __zero, _CharT __one)
791 if (__pos > __str.size())
792 __throw_out_of_range("bitset string pos out of range");
794 size_t __rlen = _VSTD::min(__n, __str.size() - __pos);
795 for (size_t __i = __pos; __i < __pos + __rlen; ++__i)
796 if (!_Traits::eq(__str[__i], __zero) && !_Traits::eq(__str[__i], __one))
797 __throw_invalid_argument("bitset string ctor has invalid argument");
799 size_t _Mp = _VSTD::min(__rlen, _Size);
801 for (; __i < _Mp; ++__i)
803 _CharT __c = __str[__pos + _Mp - 1 - __i];
804 (*this)[__i] = _Traits::eq(__c, __one);
806 _VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false);
809 template <size_t _Size>
812 bitset<_Size>::operator&=(const bitset& __rhs) _NOEXCEPT
814 base::operator&=(__rhs);
818 template <size_t _Size>
821 bitset<_Size>::operator|=(const bitset& __rhs) _NOEXCEPT
823 base::operator|=(__rhs);
827 template <size_t _Size>
830 bitset<_Size>::operator^=(const bitset& __rhs) _NOEXCEPT
832 base::operator^=(__rhs);
836 template <size_t _Size>
838 bitset<_Size>::operator<<=(size_t __pos) _NOEXCEPT
840 __pos = _VSTD::min(__pos, _Size);
841 _VSTD::copy_backward(base::__make_iter(0), base::__make_iter(_Size - __pos), base::__make_iter(_Size));
842 _VSTD::fill_n(base::__make_iter(0), __pos, false);
846 template <size_t _Size>
848 bitset<_Size>::operator>>=(size_t __pos) _NOEXCEPT
850 __pos = _VSTD::min(__pos, _Size);
851 _VSTD::copy(base::__make_iter(__pos), base::__make_iter(_Size), base::__make_iter(0));
852 _VSTD::fill_n(base::__make_iter(_Size - __pos), __pos, false);
856 template <size_t _Size>
859 bitset<_Size>::set() _NOEXCEPT
861 _VSTD::fill_n(base::__make_iter(0), _Size, true);
865 template <size_t _Size>
867 bitset<_Size>::set(size_t __pos, bool __val)
870 __throw_out_of_range("bitset set argument out of range");
872 (*this)[__pos] = __val;
876 template <size_t _Size>
879 bitset<_Size>::reset() _NOEXCEPT
881 _VSTD::fill_n(base::__make_iter(0), _Size, false);
885 template <size_t _Size>
887 bitset<_Size>::reset(size_t __pos)
890 __throw_out_of_range("bitset reset argument out of range");
892 (*this)[__pos] = false;
896 template <size_t _Size>
899 bitset<_Size>::operator~() const _NOEXCEPT
906 template <size_t _Size>
909 bitset<_Size>::flip() _NOEXCEPT
915 template <size_t _Size>
917 bitset<_Size>::flip(size_t __pos)
920 __throw_out_of_range("bitset flip argument out of range");
922 reference r = base::__make_ref(__pos);
927 template <size_t _Size>
930 bitset<_Size>::to_ulong() const
932 return base::to_ulong();
935 template <size_t _Size>
938 bitset<_Size>::to_ullong() const
940 return base::to_ullong();
943 template <size_t _Size>
944 template <class _CharT, class _Traits, class _Allocator>
945 basic_string<_CharT, _Traits, _Allocator>
946 bitset<_Size>::to_string(_CharT __zero, _CharT __one) const
948 basic_string<_CharT, _Traits, _Allocator> __r(_Size, __zero);
949 for (size_t __i = 0; __i < _Size; ++__i)
952 __r[_Size - 1 - __i] = __one;
957 template <size_t _Size>
958 template <class _CharT, class _Traits>
960 basic_string<_CharT, _Traits, allocator<_CharT> >
961 bitset<_Size>::to_string(_CharT __zero, _CharT __one) const
963 return to_string<_CharT, _Traits, allocator<_CharT> >(__zero, __one);
966 template <size_t _Size>
967 template <class _CharT>
969 basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> >
970 bitset<_Size>::to_string(_CharT __zero, _CharT __one) const
972 return to_string<_CharT, char_traits<_CharT>, allocator<_CharT> >(__zero, __one);
975 template <size_t _Size>
977 basic_string<char, char_traits<char>, allocator<char> >
978 bitset<_Size>::to_string(char __zero, char __one) const
980 return to_string<char, char_traits<char>, allocator<char> >(__zero, __one);
983 template <size_t _Size>
986 bitset<_Size>::count() const _NOEXCEPT
988 return static_cast<size_t>(_VSTD::__count_bool_true(base::__make_iter(0), _Size));
991 template <size_t _Size>
994 bitset<_Size>::operator==(const bitset& __rhs) const _NOEXCEPT
996 return _VSTD::equal(base::__make_iter(0), base::__make_iter(_Size), __rhs.__make_iter(0));
999 template <size_t _Size>
1002 bitset<_Size>::operator!=(const bitset& __rhs) const _NOEXCEPT
1004 return !(*this == __rhs);
1007 template <size_t _Size>
1009 bitset<_Size>::test(size_t __pos) const
1012 __throw_out_of_range("bitset test argument out of range");
1014 return (*this)[__pos];
1017 template <size_t _Size>
1020 bitset<_Size>::all() const _NOEXCEPT
1025 template <size_t _Size>
1028 bitset<_Size>::any() const _NOEXCEPT
1033 template <size_t _Size>
1036 bitset<_Size>::operator<<(size_t __pos) const _NOEXCEPT
1043 template <size_t _Size>
1046 bitset<_Size>::operator>>(size_t __pos) const _NOEXCEPT
1053 template <size_t _Size>
1054 inline _LIBCPP_INLINE_VISIBILITY
1056 operator&(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT
1058 bitset<_Size> __r = __x;
1063 template <size_t _Size>
1064 inline _LIBCPP_INLINE_VISIBILITY
1066 operator|(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT
1068 bitset<_Size> __r = __x;
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 struct _LIBCPP_TEMPLATE_VIS hash<bitset<_Size> >
1085 : public unary_function<bitset<_Size>, size_t>
1087 _LIBCPP_INLINE_VISIBILITY
1088 size_t operator()(const bitset<_Size>& __bs) const _NOEXCEPT
1089 {return __bs.__hash_code();}
1092 template <class _CharT, class _Traits, size_t _Size>
1093 basic_istream<_CharT, _Traits>&
1094 operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x);
1096 template <class _CharT, class _Traits, size_t _Size>
1097 basic_ostream<_CharT, _Traits>&
1098 operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x);
1100 _LIBCPP_END_NAMESPACE_STD
1104 #endif // _LIBCPP_BITSET