codekingpro/portable-devtools
114k
1// -*- C++ -*-2//===---------------------------- bitset ----------------------------------===//3//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-exception7//8//===----------------------------------------------------------------------===//9 10#ifndef _LIBCUDACXX_BITSET11#define _LIBCUDACXX_BITSET12 13/*14 bitset synopsis15 16namespace std17{18 19namespace std {20 21template <size_t N>22class bitset23{24public:25 // bit reference:26 class reference27 {28 friend class bitset;29 reference() noexcept;30 public: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 bit35 operator bool() const noexcept; // for x = b[i];36 reference& flip() noexcept; // for b[i].flip();37 };38 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'));52 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);66 67 // element access: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;89};90 91// 23.3.5.3 bitset operators:92template <size_t N>93bitset<N> operator&(const bitset<N>&, const bitset<N>&) noexcept;94 95template <size_t N>96bitset<N> operator|(const bitset<N>&, const bitset<N>&) noexcept;97 98template <size_t N>99bitset<N> operator^(const bitset<N>&, const bitset<N>&) noexcept;100 101template <class charT, class traits, size_t N>102basic_istream<charT, traits>&103operator>>(basic_istream<charT, traits>& is, bitset<N>& x);104 105template <class charT, class traits, size_t N>106basic_ostream<charT, traits>&107operator<<(basic_ostream<charT, traits>& os, const bitset<N>& x);108 109template <size_t N> struct hash<std::bitset<N>>;110 111} // std112 113*/114 115#include <__config>116#include <__bit_reference>117#include <cstddef>118#include <climits>119#include <string>120#include <stdexcept>121#include <iosfwd>122#include <__functional_base>123 124#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)125# pragma GCC system_header126#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)127# pragma clang system_header128#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)129# pragma system_header130#endif // no system header131 132_LIBCUDACXX_PUSH_MACROS133#include <__undef_macros>134 135 136_LIBCUDACXX_BEGIN_NAMESPACE_STD137 138template <size_t _N_words, size_t _Size>139class __bitset;140 141template <size_t _N_words, size_t _Size>142struct __has_storage_type<__bitset<_N_words, _Size> >143{144 static const bool value = true;145};146 147template <size_t _N_words, size_t _Size>148class __bitset149{150public:151 typedef ptrdiff_t difference_type;152 typedef size_t size_type;153 typedef size_type __storage_type;154protected:155 typedef __bitset __self;156 typedef __storage_type* __storage_pointer;157 typedef const __storage_type* __const_storage_pointer;158 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);159 160 friend class __bit_reference<__bitset>;161 friend class __bit_const_reference<__bitset>;162 friend class __bit_iterator<__bitset, false>;163 friend class __bit_iterator<__bitset, true>;164 friend struct __bit_array<__bitset>;165 166 __storage_type __first_[_N_words];167 168 typedef __bit_reference<__bitset> reference;169 typedef __bit_const_reference<__bitset> const_reference;170 typedef __bit_iterator<__bitset, false> iterator;171 typedef __bit_iterator<__bitset, true> const_iterator;172 173 _LIBCUDACXX_INLINE_VISIBILITY174 constexpr __bitset() noexcept;175 _LIBCUDACXX_INLINE_VISIBILITY176 explicit constexpr __bitset(unsigned long long __v) noexcept;177 178 _LIBCUDACXX_INLINE_VISIBILITY reference __make_ref(size_t __pos) noexcept179 {return reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}180 _LIBCUDACXX_INLINE_VISIBILITY constexpr const_reference __make_ref(size_t __pos) const noexcept181 {return const_reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}182 _LIBCUDACXX_INLINE_VISIBILITY iterator __make_iter(size_t __pos) noexcept183 {return iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}184 _LIBCUDACXX_INLINE_VISIBILITY const_iterator __make_iter(size_t __pos) const noexcept185 {return const_iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}186 187 _LIBCUDACXX_INLINE_VISIBILITY188 void operator&=(const __bitset& __v) noexcept;189 _LIBCUDACXX_INLINE_VISIBILITY190 void operator|=(const __bitset& __v) noexcept;191 _LIBCUDACXX_INLINE_VISIBILITY192 void operator^=(const __bitset& __v) noexcept;193 194 void flip() noexcept;195 _LIBCUDACXX_INLINE_VISIBILITY unsigned long to_ulong() const196 {return to_ulong(integral_constant<bool, _Size < sizeof(unsigned long) * CHAR_BIT>());}197 _LIBCUDACXX_INLINE_VISIBILITY unsigned long long to_ullong() const198 {return to_ullong(integral_constant<bool, _Size < sizeof(unsigned long long) * CHAR_BIT>());}199 200 bool all() const noexcept;201 bool any() const noexcept;202 _LIBCUDACXX_INLINE_VISIBILITY203 size_t __hash_code() const noexcept;204private:205 unsigned long to_ulong(false_type) const;206 _LIBCUDACXX_INLINE_VISIBILITY207 unsigned long to_ulong(true_type) const;208 unsigned long long to_ullong(false_type) const;209 _LIBCUDACXX_INLINE_VISIBILITY210 unsigned long long to_ullong(true_type) const;211 _LIBCUDACXX_INLINE_VISIBILITY212 unsigned long long to_ullong(true_type, false_type) const;213 unsigned long long to_ullong(true_type, true_type) const;214};215 216template <size_t _N_words, size_t _Size>217inline constexpr218__bitset<_N_words, _Size>::__bitset() noexcept219 : __first_{0}220{}221 222template <size_t _N_words, size_t _Size>223inline224constexpr225__bitset<_N_words, _Size>::__bitset(unsigned long long __v) noexcept226#if __SIZEOF_SIZE_T__ == 8227 : __first_{__v}228#elif __SIZEOF_SIZE_T__ == 4229 : __first_{static_cast<__storage_type>(__v),230 _Size >= 2 * __bits_per_word ? static_cast<__storage_type>(__v >> __bits_per_word)231 : static_cast<__storage_type>((__v >> __bits_per_word) & (__storage_type(1) << (_Size - __bits_per_word)) - 1)}232#else233#error This constructor has not been ported to this platform234#endif235{}236 237template <size_t _N_words, size_t _Size>238inline239void240__bitset<_N_words, _Size>::operator&=(const __bitset& __v) noexcept241{242 for (size_type __i = 0; __i < _N_words; ++__i)243 __first_[__i] &= __v.__first_[__i];244}245 246template <size_t _N_words, size_t _Size>247inline248void249__bitset<_N_words, _Size>::operator|=(const __bitset& __v) noexcept250{251 for (size_type __i = 0; __i < _N_words; ++__i)252 __first_[__i] |= __v.__first_[__i];253}254 255template <size_t _N_words, size_t _Size>256inline257void258__bitset<_N_words, _Size>::operator^=(const __bitset& __v) noexcept259{260 for (size_type __i = 0; __i < _N_words; ++__i)261 __first_[__i] ^= __v.__first_[__i];262}263 264template <size_t _N_words, size_t _Size>265void266__bitset<_N_words, _Size>::flip() noexcept267{268 // do middle whole words269 size_type __n = _Size;270 __storage_pointer __p = __first_;271 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)272 *__p = ~*__p;273 // do last partial word274 if (__n > 0)275 {276 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);277 __storage_type __b = *__p & __m;278 *__p &= ~__m;279 *__p |= ~__b & __m;280 }281}282 283template <size_t _N_words, size_t _Size>284unsigned long285__bitset<_N_words, _Size>::to_ulong(false_type) const286{287 const_iterator __e = __make_iter(_Size);288 const_iterator __i = _CUDA_VSTD::find(__make_iter(sizeof(unsigned long) * CHAR_BIT), __e, true);289 if (__i != __e)290 __throw_overflow_error("bitset to_ulong overflow error");291 292 return __first_[0];293}294 295template <size_t _N_words, size_t _Size>296inline297unsigned long298__bitset<_N_words, _Size>::to_ulong(true_type) const299{300 return __first_[0];301}302 303template <size_t _N_words, size_t _Size>304unsigned long long305__bitset<_N_words, _Size>::to_ullong(false_type) const306{307 const_iterator __e = __make_iter(_Size);308 const_iterator __i = _CUDA_VSTD::find(__make_iter(sizeof(unsigned long long) * CHAR_BIT), __e, true);309 if (__i != __e)310 __throw_overflow_error("bitset to_ullong overflow error");311 312 return to_ullong(true_type());313}314 315template <size_t _N_words, size_t _Size>316inline317unsigned long long318__bitset<_N_words, _Size>::to_ullong(true_type) const319{320 return to_ullong(true_type(), integral_constant<bool, sizeof(__storage_type) < sizeof(unsigned long long)>());321}322 323template <size_t _N_words, size_t _Size>324inline325unsigned long long326__bitset<_N_words, _Size>::to_ullong(true_type, false_type) const327{328 return __first_[0];329}330 331template <size_t _N_words, size_t _Size>332unsigned long long333__bitset<_N_words, _Size>::to_ullong(true_type, true_type) const334{335 unsigned long long __r = __first_[0];336 for (std::size_t __i = 1; __i < sizeof(unsigned long long) / sizeof(__storage_type); ++__i)337 __r |= static_cast<unsigned long long>(__first_[__i]) << (sizeof(__storage_type) * CHAR_BIT);338 return __r;339}340 341template <size_t _N_words, size_t _Size>342bool343__bitset<_N_words, _Size>::all() const noexcept344{345 // do middle whole words346 size_type __n = _Size;347 __const_storage_pointer __p = __first_;348 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)349 if (~*__p)350 return false;351 // do last partial word352 if (__n > 0)353 {354 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);355 if (~*__p & __m)356 return false;357 }358 return true;359}360 361template <size_t _N_words, size_t _Size>362bool363__bitset<_N_words, _Size>::any() const noexcept364{365 // do middle whole words366 size_type __n = _Size;367 __const_storage_pointer __p = __first_;368 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)369 if (*__p)370 return true;371 // do last partial word372 if (__n > 0)373 {374 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);375 if (*__p & __m)376 return true;377 }378 return false;379}380 381template <size_t _N_words, size_t _Size>382inline383size_t384__bitset<_N_words, _Size>::__hash_code() const noexcept385{386 size_t __h = 0;387 for (size_type __i = 0; __i < _N_words; ++__i)388 __h ^= __first_[__i];389 return __h;390}391 392template <size_t _Size>393class __bitset<1, _Size>394{395public:396 typedef ptrdiff_t difference_type;397 typedef size_t size_type;398 typedef size_type __storage_type;399protected:400 typedef __bitset __self;401 typedef __storage_type* __storage_pointer;402 typedef const __storage_type* __const_storage_pointer;403 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);404 405 friend class __bit_reference<__bitset>;406 friend class __bit_const_reference<__bitset>;407 friend class __bit_iterator<__bitset, false>;408 friend class __bit_iterator<__bitset, true>;409 friend struct __bit_array<__bitset>;410 411 __storage_type __first_;412 413 typedef __bit_reference<__bitset> reference;414 typedef __bit_const_reference<__bitset> const_reference;415 typedef __bit_iterator<__bitset, false> iterator;416 typedef __bit_iterator<__bitset, true> const_iterator;417 418 _LIBCUDACXX_INLINE_VISIBILITY419 constexpr __bitset() noexcept;420 _LIBCUDACXX_INLINE_VISIBILITY421 explicit constexpr __bitset(unsigned long long __v) noexcept;422 423 _LIBCUDACXX_INLINE_VISIBILITY reference __make_ref(size_t __pos) noexcept424 {return reference(&__first_, __storage_type(1) << __pos);}425 _LIBCUDACXX_INLINE_VISIBILITY constexpr const_reference __make_ref(size_t __pos) const noexcept426 {return const_reference(&__first_, __storage_type(1) << __pos);}427 _LIBCUDACXX_INLINE_VISIBILITY iterator __make_iter(size_t __pos) noexcept428 {return iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}429 _LIBCUDACXX_INLINE_VISIBILITY const_iterator __make_iter(size_t __pos) const noexcept430 {return const_iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}431 432 _LIBCUDACXX_INLINE_VISIBILITY433 void operator&=(const __bitset& __v) noexcept;434 _LIBCUDACXX_INLINE_VISIBILITY435 void operator|=(const __bitset& __v) noexcept;436 _LIBCUDACXX_INLINE_VISIBILITY437 void operator^=(const __bitset& __v) noexcept;438 439 _LIBCUDACXX_INLINE_VISIBILITY440 void flip() noexcept;441 442 _LIBCUDACXX_INLINE_VISIBILITY443 unsigned long to_ulong() const;444 _LIBCUDACXX_INLINE_VISIBILITY445 unsigned long long to_ullong() const;446 447 _LIBCUDACXX_INLINE_VISIBILITY448 bool all() const noexcept;449 _LIBCUDACXX_INLINE_VISIBILITY450 bool any() const noexcept;451 452 _LIBCUDACXX_INLINE_VISIBILITY453 size_t __hash_code() const noexcept;454};455 456template <size_t _Size>457inline constexpr458__bitset<1, _Size>::__bitset() noexcept459 : __first_(0)460{461}462 463template <size_t _Size>464inline constexpr465__bitset<1, _Size>::__bitset(unsigned long long __v) noexcept466 : __first_(467 _Size == __bits_per_word ? static_cast<__storage_type>(__v)468 : static_cast<__storage_type>(__v) & ((__storage_type(1) << _Size) - 1)469 )470{471}472 473template <size_t _Size>474inline475void476__bitset<1, _Size>::operator&=(const __bitset& __v) noexcept477{478 __first_ &= __v.__first_;479}480 481template <size_t _Size>482inline483void484__bitset<1, _Size>::operator|=(const __bitset& __v) noexcept485{486 __first_ |= __v.__first_;487}488 489template <size_t _Size>490inline491void492__bitset<1, _Size>::operator^=(const __bitset& __v) noexcept493{494 __first_ ^= __v.__first_;495}496 497template <size_t _Size>498inline499void500__bitset<1, _Size>::flip() noexcept501{502 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);503 __first_ = ~__first_;504 __first_ &= __m;505}506 507template <size_t _Size>508inline509unsigned long510__bitset<1, _Size>::to_ulong() const511{512 return __first_;513}514 515template <size_t _Size>516inline517unsigned long long518__bitset<1, _Size>::to_ullong() const519{520 return __first_;521}522 523template <size_t _Size>524inline525bool526__bitset<1, _Size>::all() const noexcept527{528 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);529 return !(~__first_ & __m);530}531 532template <size_t _Size>533inline534bool535__bitset<1, _Size>::any() const noexcept536{537 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);538 return __first_ & __m;539}540 541template <size_t _Size>542inline543size_t544__bitset<1, _Size>::__hash_code() const noexcept545{546 return __first_;547}548 549template <>550class __bitset<0, 0>551{552public:553 typedef ptrdiff_t difference_type;554 typedef size_t size_type;555 typedef size_type __storage_type;556protected:557 typedef __bitset __self;558 typedef __storage_type* __storage_pointer;559 typedef const __storage_type* __const_storage_pointer;560 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);561 562 friend class __bit_reference<__bitset>;563 friend class __bit_const_reference<__bitset>;564 friend class __bit_iterator<__bitset, false>;565 friend class __bit_iterator<__bitset, true>;566 friend struct __bit_array<__bitset>;567 568 typedef __bit_reference<__bitset> reference;569 typedef __bit_const_reference<__bitset> const_reference;570 typedef __bit_iterator<__bitset, false> iterator;571 typedef __bit_iterator<__bitset, true> const_iterator;572 573 _LIBCUDACXX_INLINE_VISIBILITY574 constexpr __bitset() noexcept;575 _LIBCUDACXX_INLINE_VISIBILITY576 explicit constexpr __bitset(unsigned long long) noexcept;577 578 _LIBCUDACXX_INLINE_VISIBILITY reference __make_ref(size_t) noexcept579 {return reference(0, 1);}580 _LIBCUDACXX_INLINE_VISIBILITY constexpr const_reference __make_ref(size_t) const noexcept581 {return const_reference(0, 1);}582 _LIBCUDACXX_INLINE_VISIBILITY iterator __make_iter(size_t) noexcept583 {return iterator(0, 0);}584 _LIBCUDACXX_INLINE_VISIBILITY const_iterator __make_iter(size_t) const noexcept585 {return const_iterator(0, 0);}586 587 _LIBCUDACXX_INLINE_VISIBILITY void operator&=(const __bitset&) noexcept {}588 _LIBCUDACXX_INLINE_VISIBILITY void operator|=(const __bitset&) noexcept {}589 _LIBCUDACXX_INLINE_VISIBILITY void operator^=(const __bitset&) noexcept {}590 591 _LIBCUDACXX_INLINE_VISIBILITY void flip() noexcept {}592 593 _LIBCUDACXX_INLINE_VISIBILITY unsigned long to_ulong() const {return 0;}594 _LIBCUDACXX_INLINE_VISIBILITY unsigned long long to_ullong() const {return 0;}595 596 _LIBCUDACXX_INLINE_VISIBILITY bool all() const noexcept {return true;}597 _LIBCUDACXX_INLINE_VISIBILITY bool any() const noexcept {return false;}598 599 _LIBCUDACXX_INLINE_VISIBILITY size_t __hash_code() const noexcept {return 0;}600};601 602inline603constexpr604__bitset<0, 0>::__bitset() noexcept605{606}607 608inline609constexpr610__bitset<0, 0>::__bitset(unsigned long long) noexcept611{612}613 614template <size_t _Size> class _LIBCUDACXX_TEMPLATE_VIS bitset;615template <size_t _Size> struct hash<bitset<_Size> >;616 617template <size_t _Size>618class _LIBCUDACXX_TEMPLATE_VIS bitset619 : private __bitset<_Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1, _Size>620{621public:622 static const unsigned __n_words = _Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1;623 typedef __bitset<__n_words, _Size> base;624 625public:626 typedef typename base::reference reference;627 typedef typename base::const_reference const_reference;628 629 // 23.3.5.1 constructors:630 _LIBCUDACXX_INLINE_VISIBILITY constexpr bitset() noexcept {}631 _LIBCUDACXX_INLINE_VISIBILITY constexpr632 bitset(unsigned long long __v) noexcept : base(__v) {}633 template<class _CharT, class = _EnableIf<_IsCharLikeType<_CharT>::value> >634 explicit bitset(const _CharT* __str,635 typename basic_string<_CharT>::size_type __n = basic_string<_CharT>::npos,636 _CharT __zero = _CharT('0'), _CharT __one = _CharT('1'));637 template<class _CharT, class _Traits, class _Allocator>638 explicit bitset(const basic_string<_CharT,_Traits,_Allocator>& __str,639 typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos = 0,640 typename basic_string<_CharT,_Traits,_Allocator>::size_type __n =641 (basic_string<_CharT,_Traits,_Allocator>::npos),642 _CharT __zero = _CharT('0'), _CharT __one = _CharT('1'));643 644 // 23.3.5.2 bitset operations:645 _LIBCUDACXX_INLINE_VISIBILITY646 bitset& operator&=(const bitset& __rhs) noexcept;647 _LIBCUDACXX_INLINE_VISIBILITY648 bitset& operator|=(const bitset& __rhs) noexcept;649 _LIBCUDACXX_INLINE_VISIBILITY650 bitset& operator^=(const bitset& __rhs) noexcept;651 bitset& operator<<=(size_t __pos) noexcept;652 bitset& operator>>=(size_t __pos) noexcept;653 _LIBCUDACXX_INLINE_VISIBILITY654 bitset& set() noexcept;655 bitset& set(size_t __pos, bool __val = true);656 _LIBCUDACXX_INLINE_VISIBILITY657 bitset& reset() noexcept;658 bitset& reset(size_t __pos);659 _LIBCUDACXX_INLINE_VISIBILITY660 bitset operator~() const noexcept;661 _LIBCUDACXX_INLINE_VISIBILITY662 bitset& flip() noexcept;663 bitset& flip(size_t __pos);664 665 // element access:666 _LIBCUDACXX_INLINE_VISIBILITY constexpr667 const_reference operator[](size_t __p) const {return base::__make_ref(__p);}668 _LIBCUDACXX_INLINE_VISIBILITY reference operator[](size_t __p) {return base::__make_ref(__p);}669 _LIBCUDACXX_INLINE_VISIBILITY670 unsigned long to_ulong() const;671 _LIBCUDACXX_INLINE_VISIBILITY672 unsigned long long to_ullong() const;673 template <class _CharT, class _Traits, class _Allocator>674 basic_string<_CharT, _Traits, _Allocator> to_string(_CharT __zero = _CharT('0'),675 _CharT __one = _CharT('1')) const;676 template <class _CharT, class _Traits>677 _LIBCUDACXX_INLINE_VISIBILITY678 basic_string<_CharT, _Traits, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'),679 _CharT __one = _CharT('1')) const;680 template <class _CharT>681 _LIBCUDACXX_INLINE_VISIBILITY682 basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'),683 _CharT __one = _CharT('1')) const;684 _LIBCUDACXX_INLINE_VISIBILITY685 basic_string<char, char_traits<char>, allocator<char> > to_string(char __zero = '0',686 char __one = '1') const;687 _LIBCUDACXX_INLINE_VISIBILITY688 size_t count() const noexcept;689 _LIBCUDACXX_INLINE_VISIBILITY constexpr size_t size() const noexcept {return _Size;}690 _LIBCUDACXX_INLINE_VISIBILITY691 bool operator==(const bitset& __rhs) const noexcept;692 _LIBCUDACXX_INLINE_VISIBILITY693 bool operator!=(const bitset& __rhs) const noexcept;694 bool test(size_t __pos) const;695 _LIBCUDACXX_INLINE_VISIBILITY696 bool all() const noexcept;697 _LIBCUDACXX_INLINE_VISIBILITY698 bool any() const noexcept;699 _LIBCUDACXX_INLINE_VISIBILITY bool none() const noexcept {return !any();}700 _LIBCUDACXX_INLINE_VISIBILITY701 bitset operator<<(size_t __pos) const noexcept;702 _LIBCUDACXX_INLINE_VISIBILITY703 bitset operator>>(size_t __pos) const noexcept;704 705private:706 707 _LIBCUDACXX_INLINE_VISIBILITY708 size_t __hash_code() const noexcept {return base::__hash_code();}709 710 friend struct hash<bitset>;711};712 713template <size_t _Size>714template<class _CharT, class>715bitset<_Size>::bitset(const _CharT* __str,716 typename basic_string<_CharT>::size_type __n,717 _CharT __zero, _CharT __one)718{719 size_t __rlen = _CUDA_VSTD::min(__n, char_traits<_CharT>::length(__str));720 for (size_t __i = 0; __i < __rlen; ++__i)721 if (__str[__i] != __zero && __str[__i] != __one)722 __throw_invalid_argument("bitset string ctor has invalid argument");723 724 size_t _Mp = _CUDA_VSTD::min(__rlen, _Size);725 size_t __i = 0;726 for (; __i < _Mp; ++__i)727 {728 _CharT __c = __str[_Mp - 1 - __i];729 if (__c == __zero)730 (*this)[__i] = false;731 else732 (*this)[__i] = true;733 }734 _CUDA_VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false);735}736 737template <size_t _Size>738template<class _CharT, class _Traits, class _Allocator>739bitset<_Size>::bitset(const basic_string<_CharT,_Traits,_Allocator>& __str,740 typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos,741 typename basic_string<_CharT,_Traits,_Allocator>::size_type __n,742 _CharT __zero, _CharT __one)743{744 if (__pos > __str.size())745 __throw_out_of_range("bitset string pos out of range");746 747 size_t __rlen = _CUDA_VSTD::min(__n, __str.size() - __pos);748 for (size_t __i = __pos; __i < __pos + __rlen; ++__i)749 if (!_Traits::eq(__str[__i], __zero) && !_Traits::eq(__str[__i], __one))750 __throw_invalid_argument("bitset string ctor has invalid argument");751 752 size_t _Mp = _CUDA_VSTD::min(__rlen, _Size);753 size_t __i = 0;754 for (; __i < _Mp; ++__i)755 {756 _CharT __c = __str[__pos + _Mp - 1 - __i];757 if (_Traits::eq(__c, __zero))758 (*this)[__i] = false;759 else760 (*this)[__i] = true;761 }762 _CUDA_VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false);763}764 765template <size_t _Size>766inline767bitset<_Size>&768bitset<_Size>::operator&=(const bitset& __rhs) noexcept769{770 base::operator&=(__rhs);771 return *this;772}773 774template <size_t _Size>775inline776bitset<_Size>&777bitset<_Size>::operator|=(const bitset& __rhs) noexcept778{779 base::operator|=(__rhs);780 return *this;781}782 783template <size_t _Size>784inline785bitset<_Size>&786bitset<_Size>::operator^=(const bitset& __rhs) noexcept787{788 base::operator^=(__rhs);789 return *this;790}791 792template <size_t _Size>793bitset<_Size>&794bitset<_Size>::operator<<=(size_t __pos) noexcept795{796 __pos = _CUDA_VSTD::min(__pos, _Size);797 _CUDA_VSTD::copy_backward(base::__make_iter(0), base::__make_iter(_Size - __pos), base::__make_iter(_Size));798 _CUDA_VSTD::fill_n(base::__make_iter(0), __pos, false);799 return *this;800}801 802template <size_t _Size>803bitset<_Size>&804bitset<_Size>::operator>>=(size_t __pos) noexcept805{806 __pos = _CUDA_VSTD::min(__pos, _Size);807 _CUDA_VSTD::copy(base::__make_iter(__pos), base::__make_iter(_Size), base::__make_iter(0));808 _CUDA_VSTD::fill_n(base::__make_iter(_Size - __pos), __pos, false);809 return *this;810}811 812template <size_t _Size>813inline814bitset<_Size>&815bitset<_Size>::set() noexcept816{817 _CUDA_VSTD::fill_n(base::__make_iter(0), _Size, true);818 return *this;819}820 821template <size_t _Size>822bitset<_Size>&823bitset<_Size>::set(size_t __pos, bool __val)824{825 if (__pos >= _Size)826 __throw_out_of_range("bitset set argument out of range");827 828 (*this)[__pos] = __val;829 return *this;830}831 832template <size_t _Size>833inline834bitset<_Size>&835bitset<_Size>::reset() noexcept836{837 _CUDA_VSTD::fill_n(base::__make_iter(0), _Size, false);838 return *this;839}840 841template <size_t _Size>842bitset<_Size>&843bitset<_Size>::reset(size_t __pos)844{845 if (__pos >= _Size)846 __throw_out_of_range("bitset reset argument out of range");847 848 (*this)[__pos] = false;849 return *this;850}851 852template <size_t _Size>853inline854bitset<_Size>855bitset<_Size>::operator~() const noexcept856{857 bitset __x(*this);858 __x.flip();859 return __x;860}861 862template <size_t _Size>863inline864bitset<_Size>&865bitset<_Size>::flip() noexcept866{867 base::flip();868 return *this;869}870 871template <size_t _Size>872bitset<_Size>&873bitset<_Size>::flip(size_t __pos)874{875 if (__pos >= _Size)876 __throw_out_of_range("bitset flip argument out of range");877 878 reference r = base::__make_ref(__pos);879 r = ~r;880 return *this;881}882 883template <size_t _Size>884inline885unsigned long886bitset<_Size>::to_ulong() const887{888 return base::to_ulong();889}890 891template <size_t _Size>892inline893unsigned long long894bitset<_Size>::to_ullong() const895{896 return base::to_ullong();897}898 899template <size_t _Size>900template <class _CharT, class _Traits, class _Allocator>901basic_string<_CharT, _Traits, _Allocator>902bitset<_Size>::to_string(_CharT __zero, _CharT __one) const903{904 basic_string<_CharT, _Traits, _Allocator> __r(_Size, __zero);905 for (size_t __i = 0; __i < _Size; ++__i)906 {907 if ((*this)[__i])908 __r[_Size - 1 - __i] = __one;909 }910 return __r;911}912 913template <size_t _Size>914template <class _CharT, class _Traits>915inline916basic_string<_CharT, _Traits, allocator<_CharT> >917bitset<_Size>::to_string(_CharT __zero, _CharT __one) const918{919 return to_string<_CharT, _Traits, allocator<_CharT> >(__zero, __one);920}921 922template <size_t _Size>923template <class _CharT>924inline925basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> >926bitset<_Size>::to_string(_CharT __zero, _CharT __one) const927{928 return to_string<_CharT, char_traits<_CharT>, allocator<_CharT> >(__zero, __one);929}930 931template <size_t _Size>932inline933basic_string<char, char_traits<char>, allocator<char> >934bitset<_Size>::to_string(char __zero, char __one) const935{936 return to_string<char, char_traits<char>, allocator<char> >(__zero, __one);937}938 939template <size_t _Size>940inline941size_t942bitset<_Size>::count() const noexcept943{944 return static_cast<size_t>(__count_bool_true(base::__make_iter(0), _Size));945}946 947template <size_t _Size>948inline949bool950bitset<_Size>::operator==(const bitset& __rhs) const noexcept951{952 return _CUDA_VSTD::equal(base::__make_iter(0), base::__make_iter(_Size), __rhs.__make_iter(0));953}954 955template <size_t _Size>956inline957bool958bitset<_Size>::operator!=(const bitset& __rhs) const noexcept959{960 return !(*this == __rhs);961}962 963template <size_t _Size>964bool965bitset<_Size>::test(size_t __pos) const966{967 if (__pos >= _Size)968 __throw_out_of_range("bitset test argument out of range");969 970 return (*this)[__pos];971}972 973template <size_t _Size>974inline975bool976bitset<_Size>::all() const noexcept977{978 return base::all();979}980 981template <size_t _Size>982inline983bool984bitset<_Size>::any() const noexcept985{986 return base::any();987}988 989template <size_t _Size>990inline991bitset<_Size>992bitset<_Size>::operator<<(size_t __pos) const noexcept993{994 bitset __r = *this;995 __r <<= __pos;996 return __r;997}998 999template <size_t _Size>1000inline1001bitset<_Size>1002bitset<_Size>::operator>>(size_t __pos) const noexcept1003{1004 bitset __r = *this;1005 __r >>= __pos;1006 return __r;1007}1008 1009template <size_t _Size>1010inline _LIBCUDACXX_INLINE_VISIBILITY1011bitset<_Size>1012operator&(const bitset<_Size>& __x, const bitset<_Size>& __y) noexcept1013{1014 bitset<_Size> __r = __x;1015 __r &= __y;1016 return __r;1017}1018 1019template <size_t _Size>1020inline _LIBCUDACXX_INLINE_VISIBILITY1021bitset<_Size>1022operator|(const bitset<_Size>& __x, const bitset<_Size>& __y) noexcept1023{1024 bitset<_Size> __r = __x;1025 __r |= __y;1026 return __r;1027}1028 1029template <size_t _Size>1030inline _LIBCUDACXX_INLINE_VISIBILITY1031bitset<_Size>1032operator^(const bitset<_Size>& __x, const bitset<_Size>& __y) noexcept1033{1034 bitset<_Size> __r = __x;1035 __r ^= __y;1036 return __r;1037}1038 1039template <size_t _Size>1040struct _LIBCUDACXX_TEMPLATE_VIS hash<bitset<_Size> >1041 : public __unary_function<bitset<_Size>, size_t>1042{1043 _LIBCUDACXX_INLINE_VISIBILITY1044 size_t operator()(const bitset<_Size>& __bs) const noexcept1045 {return __bs.__hash_code();}1046};1047 1048template <class _CharT, class _Traits, size_t _Size>1049basic_istream<_CharT, _Traits>&1050operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x);1051 1052template <class _CharT, class _Traits, size_t _Size>1053basic_ostream<_CharT, _Traits>&1054operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x);1055 1056_LIBCUDACXX_END_NAMESPACE_STD1057 1058_LIBCUDACXX_POP_MACROS1059 1060#endif // _LIBCUDACXX_BITSET1061 