1227825Stheraven// -*- C++ -*- 2227825Stheraven//===---------------------------- bitset ----------------------------------===// 3227825Stheraven// 4227825Stheraven// The LLVM Compiler Infrastructure 5227825Stheraven// 6227825Stheraven// This file is dual licensed under the MIT and the University of Illinois Open 7227825Stheraven// Source Licenses. See LICENSE.TXT for details. 8227825Stheraven// 9227825Stheraven//===----------------------------------------------------------------------===// 10227825Stheraven 11227825Stheraven#ifndef _LIBCPP_BITSET 12227825Stheraven#define _LIBCPP_BITSET 13227825Stheraven 14227825Stheraven/* 15227825Stheraven bitset synopsis 16227825Stheraven 17227825Stheravennamespace std 18227825Stheraven{ 19227825Stheraven 20227825Stheravennamespace std { 21227825Stheraven 22227825Stheraventemplate <size_t N> 23227825Stheravenclass bitset 24227825Stheraven{ 25227825Stheravenpublic: 26227825Stheraven // bit reference: 27227825Stheraven class reference 28227825Stheraven { 29227825Stheraven friend class bitset; 30227825Stheraven reference() noexcept; 31227825Stheraven public: 32227825Stheraven ~reference() noexcept; 33227825Stheraven reference& operator=(bool x) noexcept; // for b[i] = x; 34227825Stheraven reference& operator=(const reference&) noexcept; // for b[i] = b[j]; 35227825Stheraven bool operator~() const noexcept; // flips the bit 36227825Stheraven operator bool() const noexcept; // for x = b[i]; 37227825Stheraven reference& flip() noexcept; // for b[i].flip(); 38227825Stheraven }; 39227825Stheraven 40227825Stheraven // 23.3.5.1 constructors: 41227825Stheraven constexpr bitset() noexcept; 42227825Stheraven constexpr bitset(unsigned long long val) noexcept; 43227825Stheraven template <class charT> 44227825Stheraven explicit bitset(const charT* str, 45227825Stheraven typename basic_string<charT>::size_type n = basic_string<charT>::npos, 46227825Stheraven charT zero = charT('0'), charT one = charT('1')); 47227825Stheraven template<class charT, class traits, class Allocator> 48227825Stheraven explicit bitset(const basic_string<charT,traits,Allocator>& str, 49227825Stheraven typename basic_string<charT,traits,Allocator>::size_type pos = 0, 50227825Stheraven typename basic_string<charT,traits,Allocator>::size_type n = 51227825Stheraven basic_string<charT,traits,Allocator>::npos, 52227825Stheraven charT zero = charT('0'), charT one = charT('1')); 53227825Stheraven 54227825Stheraven // 23.3.5.2 bitset operations: 55227825Stheraven bitset& operator&=(const bitset& rhs) noexcept; 56227825Stheraven bitset& operator|=(const bitset& rhs) noexcept; 57227825Stheraven bitset& operator^=(const bitset& rhs) noexcept; 58227825Stheraven bitset& operator<<=(size_t pos) noexcept; 59227825Stheraven bitset& operator>>=(size_t pos) noexcept; 60227825Stheraven bitset& set() noexcept; 61227825Stheraven bitset& set(size_t pos, bool val = true); 62227825Stheraven bitset& reset() noexcept; 63227825Stheraven bitset& reset(size_t pos); 64227825Stheraven bitset operator~() const noexcept; 65227825Stheraven bitset& flip() noexcept; 66227825Stheraven bitset& flip(size_t pos); 67227825Stheraven 68227825Stheraven // element access: 69227825Stheraven constexpr bool operator[](size_t pos) const; // for b[i]; 70227825Stheraven reference operator[](size_t pos); // for b[i]; 71227825Stheraven unsigned long to_ulong() const; 72227825Stheraven unsigned long long to_ullong() const; 73227825Stheraven template <class charT, class traits, class Allocator> 74227825Stheraven basic_string<charT, traits, Allocator> to_string(charT zero = charT('0'), charT one = charT('1')) const; 75227825Stheraven template <class charT, class traits> 76227825Stheraven basic_string<charT, traits, allocator<charT> > to_string(charT zero = charT('0'), charT one = charT('1')) const; 77227825Stheraven template <class charT> 78227825Stheraven basic_string<charT, char_traits<charT>, allocator<charT> > to_string(charT zero = charT('0'), charT one = charT('1')) const; 79227825Stheraven basic_string<char, char_traits<char>, allocator<char> > to_string(char zero = '0', char one = '1') const; 80227825Stheraven size_t count() const noexcept; 81227825Stheraven constexpr size_t size() const noexcept; 82227825Stheraven bool operator==(const bitset& rhs) const noexcept; 83227825Stheraven bool operator!=(const bitset& rhs) const noexcept; 84227825Stheraven bool test(size_t pos) const; 85227825Stheraven bool all() const noexcept; 86227825Stheraven bool any() const noexcept; 87227825Stheraven bool none() const noexcept; 88227825Stheraven bitset operator<<(size_t pos) const noexcept; 89227825Stheraven bitset operator>>(size_t pos) const noexcept; 90227825Stheraven}; 91227825Stheraven 92227825Stheraven// 23.3.5.3 bitset operators: 93227825Stheraventemplate <size_t N> 94227825Stheravenbitset<N> operator&(const bitset<N>&, const bitset<N>&) noexcept; 95227825Stheraven 96227825Stheraventemplate <size_t N> 97227825Stheravenbitset<N> operator|(const bitset<N>&, const bitset<N>&) noexcept; 98227825Stheraven 99227825Stheraventemplate <size_t N> 100227825Stheravenbitset<N> operator^(const bitset<N>&, const bitset<N>&) noexcept; 101227825Stheraven 102227825Stheraventemplate <class charT, class traits, size_t N> 103227825Stheravenbasic_istream<charT, traits>& 104227825Stheravenoperator>>(basic_istream<charT, traits>& is, bitset<N>& x); 105227825Stheraven 106227825Stheraventemplate <class charT, class traits, size_t N> 107227825Stheravenbasic_ostream<charT, traits>& 108227825Stheravenoperator<<(basic_ostream<charT, traits>& os, const bitset<N>& x); 109227825Stheraven 110227825Stheraventemplate <size_t N> struct hash<std::bitset<N>>; 111227825Stheraven 112227825Stheraven} // std 113227825Stheraven 114227825Stheraven*/ 115227825Stheraven 116227825Stheraven#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 117227825Stheraven#pragma GCC system_header 118227825Stheraven#endif 119227825Stheraven 120227825Stheraven#include <__config> 121227825Stheraven#include <__bit_reference> 122227825Stheraven#include <cstddef> 123227825Stheraven#include <climits> 124227825Stheraven#include <string> 125227825Stheraven#include <stdexcept> 126227825Stheraven#include <iosfwd> 127227825Stheraven#include <__functional_base> 128227825Stheraven#if defined(_LIBCPP_NO_EXCEPTIONS) 129227825Stheraven #include <cassert> 130227825Stheraven#endif 131227825Stheraven 132232950Stheraven#include <__undef_min_max> 133232950Stheraven 134227825Stheraven_LIBCPP_BEGIN_NAMESPACE_STD 135227825Stheraven 136227825Stheraventemplate <size_t _N_words, size_t _Size> 137227825Stheravenclass __bitset; 138227825Stheraven 139227825Stheraventemplate <size_t _N_words, size_t _Size> 140227825Stheravenstruct __has_storage_type<__bitset<_N_words, _Size> > 141227825Stheraven{ 142227825Stheraven static const bool value = true; 143227825Stheraven}; 144227825Stheraven 145227825Stheraventemplate <size_t _N_words, size_t _Size> 146227825Stheravenclass __bitset 147227825Stheraven{ 148227825Stheravenpublic: 149227825Stheraven typedef ptrdiff_t difference_type; 150227825Stheraven typedef size_t size_type; 151241903Sdim typedef size_type __storage_type; 152227825Stheravenprotected: 153227825Stheraven typedef __bitset __self; 154227825Stheraven typedef __storage_type* __storage_pointer; 155227825Stheraven typedef const __storage_type* __const_storage_pointer; 156227825Stheraven static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT); 157227825Stheraven 158227825Stheraven friend class __bit_reference<__bitset>; 159227825Stheraven friend class __bit_const_reference<__bitset>; 160227825Stheraven friend class __bit_iterator<__bitset, false>; 161227825Stheraven friend class __bit_iterator<__bitset, true>; 162241903Sdim friend struct __bit_array<__bitset>; 163227825Stheraven 164227825Stheraven __storage_type __first_[_N_words]; 165227825Stheraven 166227825Stheraven typedef __bit_reference<__bitset> reference; 167227825Stheraven typedef __bit_const_reference<__bitset> const_reference; 168227825Stheraven typedef __bit_iterator<__bitset, false> iterator; 169227825Stheraven typedef __bit_iterator<__bitset, true> const_iterator; 170227825Stheraven 171241903Sdim _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT; 172241903Sdim explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT; 173227825Stheraven 174227825Stheraven _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t __pos) _NOEXCEPT 175227825Stheraven {return reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);} 176241903Sdim _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT 177227825Stheraven {return const_reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);} 178227825Stheraven _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t __pos) _NOEXCEPT 179227825Stheraven {return iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);} 180227825Stheraven _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t __pos) const _NOEXCEPT 181227825Stheraven {return const_iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);} 182227825Stheraven 183227825Stheraven void operator&=(const __bitset& __v) _NOEXCEPT; 184227825Stheraven void operator|=(const __bitset& __v) _NOEXCEPT; 185227825Stheraven void operator^=(const __bitset& __v) _NOEXCEPT; 186227825Stheraven 187227825Stheraven void flip() _NOEXCEPT; 188227825Stheraven _LIBCPP_INLINE_VISIBILITY unsigned long to_ulong() const 189227825Stheraven {return to_ulong(integral_constant<bool, _Size < sizeof(unsigned long) * CHAR_BIT>());} 190227825Stheraven _LIBCPP_INLINE_VISIBILITY unsigned long long to_ullong() const 191227825Stheraven {return to_ullong(integral_constant<bool, _Size < sizeof(unsigned long long) * CHAR_BIT>());} 192227825Stheraven 193227825Stheraven bool all() const _NOEXCEPT; 194227825Stheraven bool any() const _NOEXCEPT; 195227825Stheraven size_t __hash_code() const _NOEXCEPT; 196227825Stheravenprivate: 197241903Sdim#ifdef _LIBCPP_HAS_NO_CONSTEXPR 198227825Stheraven void __init(unsigned long long __v, false_type) _NOEXCEPT; 199227825Stheraven void __init(unsigned long long __v, true_type) _NOEXCEPT; 200241903Sdim#endif // _LIBCPP_HAS_NO_CONSTEXPR 201227825Stheraven unsigned long to_ulong(false_type) const; 202227825Stheraven unsigned long to_ulong(true_type) const; 203227825Stheraven unsigned long long to_ullong(false_type) const; 204227825Stheraven unsigned long long to_ullong(true_type) const; 205227825Stheraven unsigned long long to_ullong(true_type, false_type) const; 206227825Stheraven unsigned long long to_ullong(true_type, true_type) const; 207227825Stheraven}; 208227825Stheraven 209227825Stheraventemplate <size_t _N_words, size_t _Size> 210227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 211241903Sdim_LIBCPP_CONSTEXPR 212227825Stheraven__bitset<_N_words, _Size>::__bitset() _NOEXCEPT 213241903Sdim#ifndef _LIBCPP_HAS_NO_CONSTEXPR 214241903Sdim : __first_{0} 215241903Sdim#endif 216227825Stheraven{ 217241903Sdim#ifdef _LIBCPP_HAS_NO_CONSTEXPR 218227825Stheraven _VSTD::fill_n(__first_, _N_words, __storage_type(0)); 219241903Sdim#endif 220227825Stheraven} 221227825Stheraven 222241903Sdim#ifdef _LIBCPP_HAS_NO_CONSTEXPR 223241903Sdim 224227825Stheraventemplate <size_t _N_words, size_t _Size> 225227825Stheravenvoid 226232950Stheraven__bitset<_N_words, _Size>::__init(unsigned long long __v, false_type) _NOEXCEPT 227227825Stheraven{ 228227825Stheraven __storage_type __t[sizeof(unsigned long long) / sizeof(__storage_type)]; 229227825Stheraven for (size_t __i = 0; __i < sizeof(__t)/sizeof(__t[0]); ++__i, __v >>= __bits_per_word) 230227825Stheraven __t[__i] = static_cast<__storage_type>(__v); 231227825Stheraven _VSTD::copy(__t, __t + sizeof(__t)/sizeof(__t[0]), __first_); 232227825Stheraven _VSTD::fill(__first_ + sizeof(__t)/sizeof(__t[0]), __first_ + sizeof(__first_)/sizeof(__first_[0]), 233227825Stheraven __storage_type(0)); 234227825Stheraven} 235227825Stheraven 236227825Stheraventemplate <size_t _N_words, size_t _Size> 237227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 238227825Stheravenvoid 239232950Stheraven__bitset<_N_words, _Size>::__init(unsigned long long __v, true_type) _NOEXCEPT 240227825Stheraven{ 241227825Stheraven __first_[0] = __v; 242227825Stheraven _VSTD::fill(__first_ + 1, __first_ + sizeof(__first_)/sizeof(__first_[0]), __storage_type(0)); 243227825Stheraven} 244227825Stheraven 245241903Sdim#endif // _LIBCPP_HAS_NO_CONSTEXPR 246241903Sdim 247227825Stheraventemplate <size_t _N_words, size_t _Size> 248227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 249241903Sdim_LIBCPP_CONSTEXPR 250227825Stheraven__bitset<_N_words, _Size>::__bitset(unsigned long long __v) _NOEXCEPT 251241903Sdim#ifndef _LIBCPP_HAS_NO_CONSTEXPR 252278724Sdim#if __SIZEOF_SIZE_T__ == 8 253241903Sdim : __first_{__v} 254278724Sdim#elif __SIZEOF_SIZE_T__ == 4 255249998Sdim : __first_{__v, __v >> __bits_per_word} 256249998Sdim#else 257249998Sdim#error This constructor has not been ported to this platform 258241903Sdim#endif 259249998Sdim#endif 260227825Stheraven{ 261241903Sdim#ifdef _LIBCPP_HAS_NO_CONSTEXPR 262227825Stheraven __init(__v, integral_constant<bool, sizeof(unsigned long long) == sizeof(__storage_type)>()); 263241903Sdim#endif 264227825Stheraven} 265227825Stheraven 266227825Stheraventemplate <size_t _N_words, size_t _Size> 267227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 268227825Stheravenvoid 269227825Stheraven__bitset<_N_words, _Size>::operator&=(const __bitset& __v) _NOEXCEPT 270227825Stheraven{ 271227825Stheraven for (size_type __i = 0; __i < _N_words; ++__i) 272227825Stheraven __first_[__i] &= __v.__first_[__i]; 273227825Stheraven} 274227825Stheraven 275227825Stheraventemplate <size_t _N_words, size_t _Size> 276227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 277227825Stheravenvoid 278227825Stheraven__bitset<_N_words, _Size>::operator|=(const __bitset& __v) _NOEXCEPT 279227825Stheraven{ 280227825Stheraven for (size_type __i = 0; __i < _N_words; ++__i) 281227825Stheraven __first_[__i] |= __v.__first_[__i]; 282227825Stheraven} 283227825Stheraven 284227825Stheraventemplate <size_t _N_words, size_t _Size> 285227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 286227825Stheravenvoid 287227825Stheraven__bitset<_N_words, _Size>::operator^=(const __bitset& __v) _NOEXCEPT 288227825Stheraven{ 289227825Stheraven for (size_type __i = 0; __i < _N_words; ++__i) 290227825Stheraven __first_[__i] ^= __v.__first_[__i]; 291227825Stheraven} 292227825Stheraven 293227825Stheraventemplate <size_t _N_words, size_t _Size> 294227825Stheravenvoid 295227825Stheraven__bitset<_N_words, _Size>::flip() _NOEXCEPT 296227825Stheraven{ 297227825Stheraven // do middle whole words 298227825Stheraven size_type __n = _Size; 299227825Stheraven __storage_pointer __p = __first_; 300227825Stheraven for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) 301227825Stheraven *__p = ~*__p; 302227825Stheraven // do last partial word 303227825Stheraven if (__n > 0) 304227825Stheraven { 305227825Stheraven __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); 306227825Stheraven __storage_type __b = *__p & __m; 307227825Stheraven *__p &= ~__m; 308227825Stheraven *__p |= ~__b & __m; 309227825Stheraven } 310227825Stheraven} 311227825Stheraven 312227825Stheraventemplate <size_t _N_words, size_t _Size> 313227825Stheravenunsigned long 314227825Stheraven__bitset<_N_words, _Size>::to_ulong(false_type) const 315227825Stheraven{ 316227825Stheraven const_iterator __e = __make_iter(_Size); 317227825Stheraven const_iterator __i = _VSTD::find(__make_iter(sizeof(unsigned long) * CHAR_BIT), __e, true); 318227825Stheraven if (__i != __e) 319227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 320227825Stheraven throw overflow_error("bitset to_ulong overflow error"); 321227825Stheraven#else 322227825Stheraven assert(!"bitset to_ulong overflow error"); 323227825Stheraven#endif 324227825Stheraven return __first_[0]; 325227825Stheraven} 326227825Stheraven 327227825Stheraventemplate <size_t _N_words, size_t _Size> 328227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 329227825Stheravenunsigned long 330227825Stheraven__bitset<_N_words, _Size>::to_ulong(true_type) const 331227825Stheraven{ 332227825Stheraven return __first_[0]; 333227825Stheraven} 334227825Stheraven 335227825Stheraventemplate <size_t _N_words, size_t _Size> 336227825Stheravenunsigned long long 337227825Stheraven__bitset<_N_words, _Size>::to_ullong(false_type) const 338227825Stheraven{ 339227825Stheraven const_iterator __e = __make_iter(_Size); 340227825Stheraven const_iterator __i = _VSTD::find(__make_iter(sizeof(unsigned long long) * CHAR_BIT), __e, true); 341227825Stheraven if (__i != __e) 342227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 343227825Stheraven throw overflow_error("bitset to_ullong overflow error"); 344227825Stheraven#else 345227825Stheraven assert(!"bitset to_ullong overflow error"); 346227825Stheraven#endif 347227825Stheraven return to_ullong(true_type()); 348227825Stheraven} 349227825Stheraven 350227825Stheraventemplate <size_t _N_words, size_t _Size> 351227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 352227825Stheravenunsigned long long 353227825Stheraven__bitset<_N_words, _Size>::to_ullong(true_type) const 354227825Stheraven{ 355227825Stheraven return to_ullong(true_type(), integral_constant<bool, sizeof(__storage_type) < sizeof(unsigned long long)>()); 356227825Stheraven} 357227825Stheraven 358227825Stheraventemplate <size_t _N_words, size_t _Size> 359227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 360227825Stheravenunsigned long long 361227825Stheraven__bitset<_N_words, _Size>::to_ullong(true_type, false_type) const 362227825Stheraven{ 363227825Stheraven return __first_[0]; 364227825Stheraven} 365227825Stheraven 366227825Stheraventemplate <size_t _N_words, size_t _Size> 367227825Stheravenunsigned long long 368227825Stheraven__bitset<_N_words, _Size>::to_ullong(true_type, true_type) const 369227825Stheraven{ 370227825Stheraven unsigned long long __r = __first_[0]; 371227825Stheraven for (std::size_t __i = 1; __i < sizeof(unsigned long long) / sizeof(__storage_type); ++__i) 372227825Stheraven __r |= static_cast<unsigned long long>(__first_[__i]) << (sizeof(__storage_type) * CHAR_BIT); 373227825Stheraven return __r; 374227825Stheraven} 375227825Stheraven 376227825Stheraventemplate <size_t _N_words, size_t _Size> 377227825Stheravenbool 378227825Stheraven__bitset<_N_words, _Size>::all() const _NOEXCEPT 379227825Stheraven{ 380227825Stheraven // do middle whole words 381227825Stheraven size_type __n = _Size; 382227825Stheraven __const_storage_pointer __p = __first_; 383227825Stheraven for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) 384227825Stheraven if (~*__p) 385227825Stheraven return false; 386227825Stheraven // do last partial word 387227825Stheraven if (__n > 0) 388227825Stheraven { 389227825Stheraven __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); 390227825Stheraven if (~*__p & __m) 391227825Stheraven return false; 392227825Stheraven } 393227825Stheraven return true; 394227825Stheraven} 395227825Stheraven 396227825Stheraventemplate <size_t _N_words, size_t _Size> 397227825Stheravenbool 398227825Stheraven__bitset<_N_words, _Size>::any() const _NOEXCEPT 399227825Stheraven{ 400227825Stheraven // do middle whole words 401227825Stheraven size_type __n = _Size; 402227825Stheraven __const_storage_pointer __p = __first_; 403227825Stheraven for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) 404227825Stheraven if (*__p) 405227825Stheraven return true; 406227825Stheraven // do last partial word 407227825Stheraven if (__n > 0) 408227825Stheraven { 409227825Stheraven __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); 410227825Stheraven if (*__p & __m) 411227825Stheraven return true; 412227825Stheraven } 413227825Stheraven return false; 414227825Stheraven} 415227825Stheraven 416227825Stheraventemplate <size_t _N_words, size_t _Size> 417227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 418227825Stheravensize_t 419227825Stheraven__bitset<_N_words, _Size>::__hash_code() const _NOEXCEPT 420227825Stheraven{ 421227825Stheraven size_t __h = 0; 422227825Stheraven for (size_type __i = 0; __i < _N_words; ++__i) 423227825Stheraven __h ^= __first_[__i]; 424227825Stheraven return __h; 425227825Stheraven} 426227825Stheraven 427227825Stheraventemplate <size_t _Size> 428227825Stheravenclass __bitset<1, _Size> 429227825Stheraven{ 430227825Stheravenpublic: 431227825Stheraven typedef ptrdiff_t difference_type; 432227825Stheraven typedef size_t size_type; 433241903Sdim typedef size_type __storage_type; 434227825Stheravenprotected: 435227825Stheraven typedef __bitset __self; 436227825Stheraven typedef __storage_type* __storage_pointer; 437227825Stheraven typedef const __storage_type* __const_storage_pointer; 438227825Stheraven static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT); 439227825Stheraven 440227825Stheraven friend class __bit_reference<__bitset>; 441227825Stheraven friend class __bit_const_reference<__bitset>; 442227825Stheraven friend class __bit_iterator<__bitset, false>; 443227825Stheraven friend class __bit_iterator<__bitset, true>; 444241903Sdim friend struct __bit_array<__bitset>; 445227825Stheraven 446227825Stheraven __storage_type __first_; 447227825Stheraven 448227825Stheraven typedef __bit_reference<__bitset> reference; 449227825Stheraven typedef __bit_const_reference<__bitset> const_reference; 450227825Stheraven typedef __bit_iterator<__bitset, false> iterator; 451227825Stheraven typedef __bit_iterator<__bitset, true> const_iterator; 452227825Stheraven 453241903Sdim _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT; 454241903Sdim explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT; 455227825Stheraven 456227825Stheraven _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t __pos) _NOEXCEPT 457227825Stheraven {return reference(&__first_, __storage_type(1) << __pos);} 458241903Sdim _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT 459227825Stheraven {return const_reference(&__first_, __storage_type(1) << __pos);} 460227825Stheraven _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t __pos) _NOEXCEPT 461227825Stheraven {return iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);} 462227825Stheraven _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t __pos) const _NOEXCEPT 463227825Stheraven {return const_iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);} 464227825Stheraven 465227825Stheraven void operator&=(const __bitset& __v) _NOEXCEPT; 466227825Stheraven void operator|=(const __bitset& __v) _NOEXCEPT; 467227825Stheraven void operator^=(const __bitset& __v) _NOEXCEPT; 468227825Stheraven 469227825Stheraven void flip() _NOEXCEPT; 470227825Stheraven 471227825Stheraven unsigned long to_ulong() const; 472227825Stheraven unsigned long long to_ullong() const; 473227825Stheraven 474227825Stheraven bool all() const _NOEXCEPT; 475227825Stheraven bool any() const _NOEXCEPT; 476227825Stheraven 477227825Stheraven size_t __hash_code() const _NOEXCEPT; 478227825Stheraven}; 479227825Stheraven 480227825Stheraventemplate <size_t _Size> 481227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 482241903Sdim_LIBCPP_CONSTEXPR 483227825Stheraven__bitset<1, _Size>::__bitset() _NOEXCEPT 484227825Stheraven : __first_(0) 485227825Stheraven{ 486227825Stheraven} 487227825Stheraven 488227825Stheraventemplate <size_t _Size> 489227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 490241903Sdim_LIBCPP_CONSTEXPR 491227825Stheraven__bitset<1, _Size>::__bitset(unsigned long long __v) _NOEXCEPT 492227825Stheraven : __first_(static_cast<__storage_type>(__v)) 493227825Stheraven{ 494227825Stheraven} 495227825Stheraven 496227825Stheraventemplate <size_t _Size> 497227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 498227825Stheravenvoid 499227825Stheraven__bitset<1, _Size>::operator&=(const __bitset& __v) _NOEXCEPT 500227825Stheraven{ 501227825Stheraven __first_ &= __v.__first_; 502227825Stheraven} 503227825Stheraven 504227825Stheraventemplate <size_t _Size> 505227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 506227825Stheravenvoid 507227825Stheraven__bitset<1, _Size>::operator|=(const __bitset& __v) _NOEXCEPT 508227825Stheraven{ 509227825Stheraven __first_ |= __v.__first_; 510227825Stheraven} 511227825Stheraven 512227825Stheraventemplate <size_t _Size> 513227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 514227825Stheravenvoid 515227825Stheraven__bitset<1, _Size>::operator^=(const __bitset& __v) _NOEXCEPT 516227825Stheraven{ 517227825Stheraven __first_ ^= __v.__first_; 518227825Stheraven} 519227825Stheraven 520227825Stheraventemplate <size_t _Size> 521227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 522227825Stheravenvoid 523227825Stheraven__bitset<1, _Size>::flip() _NOEXCEPT 524227825Stheraven{ 525227825Stheraven __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size); 526227825Stheraven __first_ = ~__first_; 527227825Stheraven __first_ &= __m; 528227825Stheraven} 529227825Stheraven 530227825Stheraventemplate <size_t _Size> 531227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 532227825Stheravenunsigned long 533227825Stheraven__bitset<1, _Size>::to_ulong() const 534227825Stheraven{ 535227825Stheraven return __first_; 536227825Stheraven} 537227825Stheraven 538227825Stheraventemplate <size_t _Size> 539227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 540227825Stheravenunsigned long long 541227825Stheraven__bitset<1, _Size>::to_ullong() const 542227825Stheraven{ 543227825Stheraven return __first_; 544227825Stheraven} 545227825Stheraven 546227825Stheraventemplate <size_t _Size> 547227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 548227825Stheravenbool 549227825Stheraven__bitset<1, _Size>::all() const _NOEXCEPT 550227825Stheraven{ 551227825Stheraven __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size); 552227825Stheraven return !(~__first_ & __m); 553227825Stheraven} 554227825Stheraven 555227825Stheraventemplate <size_t _Size> 556227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 557227825Stheravenbool 558227825Stheraven__bitset<1, _Size>::any() const _NOEXCEPT 559227825Stheraven{ 560227825Stheraven __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size); 561227825Stheraven return __first_ & __m; 562227825Stheraven} 563227825Stheraven 564227825Stheraventemplate <size_t _Size> 565227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 566227825Stheravensize_t 567227825Stheraven__bitset<1, _Size>::__hash_code() const _NOEXCEPT 568227825Stheraven{ 569227825Stheraven return __first_; 570227825Stheraven} 571227825Stheraven 572227825Stheraventemplate <> 573227825Stheravenclass __bitset<0, 0> 574227825Stheraven{ 575227825Stheravenpublic: 576227825Stheraven typedef ptrdiff_t difference_type; 577227825Stheraven typedef size_t size_type; 578241903Sdim typedef size_type __storage_type; 579227825Stheravenprotected: 580227825Stheraven typedef __bitset __self; 581227825Stheraven typedef __storage_type* __storage_pointer; 582227825Stheraven typedef const __storage_type* __const_storage_pointer; 583227825Stheraven static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT); 584227825Stheraven 585227825Stheraven friend class __bit_reference<__bitset>; 586227825Stheraven friend class __bit_const_reference<__bitset>; 587227825Stheraven friend class __bit_iterator<__bitset, false>; 588227825Stheraven friend class __bit_iterator<__bitset, true>; 589232950Stheraven friend struct __bit_array<__bitset>; 590227825Stheraven 591227825Stheraven typedef __bit_reference<__bitset> reference; 592227825Stheraven typedef __bit_const_reference<__bitset> const_reference; 593227825Stheraven typedef __bit_iterator<__bitset, false> iterator; 594227825Stheraven typedef __bit_iterator<__bitset, true> const_iterator; 595227825Stheraven 596241903Sdim _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT; 597241903Sdim explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long) _NOEXCEPT; 598227825Stheraven 599227825Stheraven _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t) _NOEXCEPT 600227825Stheraven {return reference(0, 1);} 601241903Sdim _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t) const _NOEXCEPT 602227825Stheraven {return const_reference(0, 1);} 603232950Stheraven _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t) _NOEXCEPT 604227825Stheraven {return iterator(0, 0);} 605232950Stheraven _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t) const _NOEXCEPT 606227825Stheraven {return const_iterator(0, 0);} 607227825Stheraven 608227825Stheraven _LIBCPP_INLINE_VISIBILITY void operator&=(const __bitset&) _NOEXCEPT {} 609227825Stheraven _LIBCPP_INLINE_VISIBILITY void operator|=(const __bitset&) _NOEXCEPT {} 610227825Stheraven _LIBCPP_INLINE_VISIBILITY void operator^=(const __bitset&) _NOEXCEPT {} 611227825Stheraven 612227825Stheraven _LIBCPP_INLINE_VISIBILITY void flip() _NOEXCEPT {} 613227825Stheraven 614227825Stheraven _LIBCPP_INLINE_VISIBILITY unsigned long to_ulong() const {return 0;} 615227825Stheraven _LIBCPP_INLINE_VISIBILITY unsigned long long to_ullong() const {return 0;} 616227825Stheraven 617227825Stheraven _LIBCPP_INLINE_VISIBILITY bool all() const _NOEXCEPT {return true;} 618227825Stheraven _LIBCPP_INLINE_VISIBILITY bool any() const _NOEXCEPT {return false;} 619227825Stheraven 620227825Stheraven _LIBCPP_INLINE_VISIBILITY size_t __hash_code() const _NOEXCEPT {return 0;} 621227825Stheraven}; 622227825Stheraven 623227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 624241903Sdim_LIBCPP_CONSTEXPR 625227825Stheraven__bitset<0, 0>::__bitset() _NOEXCEPT 626227825Stheraven{ 627227825Stheraven} 628227825Stheraven 629227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 630241903Sdim_LIBCPP_CONSTEXPR 631227825Stheraven__bitset<0, 0>::__bitset(unsigned long long) _NOEXCEPT 632227825Stheraven{ 633227825Stheraven} 634227825Stheraven 635262801Sdimtemplate <size_t _Size> class _LIBCPP_TYPE_VIS_ONLY bitset; 636262801Sdimtemplate <size_t _Size> struct _LIBCPP_TYPE_VIS_ONLY hash<bitset<_Size> >; 637227825Stheraven 638227825Stheraventemplate <size_t _Size> 639262801Sdimclass _LIBCPP_TYPE_VIS_ONLY bitset 640227825Stheraven : private __bitset<_Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1, _Size> 641227825Stheraven{ 642249998Sdimpublic: 643227825Stheraven static const unsigned __n_words = _Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1; 644227825Stheraven typedef __bitset<__n_words, _Size> base; 645227825Stheraven 646227825Stheravenpublic: 647227825Stheraven typedef typename base::reference reference; 648227825Stheraven typedef typename base::const_reference const_reference; 649227825Stheraven 650227825Stheraven // 23.3.5.1 constructors: 651241903Sdim _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bitset() _NOEXCEPT {} 652241903Sdim _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 653241903Sdim bitset(unsigned long long __v) _NOEXCEPT : base(__v) {} 654227825Stheraven template<class _CharT> 655227825Stheraven explicit bitset(const _CharT* __str, 656227825Stheraven typename basic_string<_CharT>::size_type __n = basic_string<_CharT>::npos, 657227825Stheraven _CharT __zero = _CharT('0'), _CharT __one = _CharT('1')); 658227825Stheraven template<class _CharT, class _Traits, class _Allocator> 659227825Stheraven explicit bitset(const basic_string<_CharT,_Traits,_Allocator>& __str, 660227825Stheraven typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos = 0, 661227825Stheraven typename basic_string<_CharT,_Traits,_Allocator>::size_type __n = 662227825Stheraven (basic_string<_CharT,_Traits,_Allocator>::npos), 663227825Stheraven _CharT __zero = _CharT('0'), _CharT __one = _CharT('1')); 664227825Stheraven 665227825Stheraven // 23.3.5.2 bitset operations: 666227825Stheraven bitset& operator&=(const bitset& __rhs) _NOEXCEPT; 667227825Stheraven bitset& operator|=(const bitset& __rhs) _NOEXCEPT; 668227825Stheraven bitset& operator^=(const bitset& __rhs) _NOEXCEPT; 669227825Stheraven bitset& operator<<=(size_t __pos) _NOEXCEPT; 670227825Stheraven bitset& operator>>=(size_t __pos) _NOEXCEPT; 671227825Stheraven bitset& set() _NOEXCEPT; 672227825Stheraven bitset& set(size_t __pos, bool __val = true); 673227825Stheraven bitset& reset() _NOEXCEPT; 674227825Stheraven bitset& reset(size_t __pos); 675227825Stheraven bitset operator~() const _NOEXCEPT; 676227825Stheraven bitset& flip() _NOEXCEPT; 677227825Stheraven bitset& flip(size_t __pos); 678227825Stheraven 679227825Stheraven // element access: 680241903Sdim _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 681241903Sdim const_reference operator[](size_t __p) const {return base::__make_ref(__p);} 682227825Stheraven _LIBCPP_INLINE_VISIBILITY reference operator[](size_t __p) {return base::__make_ref(__p);} 683227825Stheraven unsigned long to_ulong() const; 684227825Stheraven unsigned long long to_ullong() const; 685227825Stheraven template <class _CharT, class _Traits, class _Allocator> 686227825Stheraven basic_string<_CharT, _Traits, _Allocator> to_string(_CharT __zero = _CharT('0'), 687227825Stheraven _CharT __one = _CharT('1')) const; 688227825Stheraven template <class _CharT, class _Traits> 689227825Stheraven basic_string<_CharT, _Traits, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'), 690227825Stheraven _CharT __one = _CharT('1')) const; 691227825Stheraven template <class _CharT> 692227825Stheraven basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'), 693227825Stheraven _CharT __one = _CharT('1')) const; 694227825Stheraven basic_string<char, char_traits<char>, allocator<char> > to_string(char __zero = '0', 695227825Stheraven char __one = '1') const; 696227825Stheraven size_t count() const _NOEXCEPT; 697241903Sdim _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR size_t size() const _NOEXCEPT {return _Size;} 698227825Stheraven bool operator==(const bitset& __rhs) const _NOEXCEPT; 699227825Stheraven bool operator!=(const bitset& __rhs) const _NOEXCEPT; 700227825Stheraven bool test(size_t __pos) const; 701227825Stheraven bool all() const _NOEXCEPT; 702227825Stheraven bool any() const _NOEXCEPT; 703227825Stheraven _LIBCPP_INLINE_VISIBILITY bool none() const _NOEXCEPT {return !any();} 704227825Stheraven bitset operator<<(size_t __pos) const _NOEXCEPT; 705227825Stheraven bitset operator>>(size_t __pos) const _NOEXCEPT; 706227825Stheraven 707227825Stheravenprivate: 708227825Stheraven 709227825Stheraven _LIBCPP_INLINE_VISIBILITY 710227825Stheraven size_t __hash_code() const _NOEXCEPT {return base::__hash_code();} 711227825Stheraven 712227825Stheraven friend struct hash<bitset>; 713227825Stheraven}; 714227825Stheraven 715227825Stheraventemplate <size_t _Size> 716227825Stheraventemplate<class _CharT> 717227825Stheravenbitset<_Size>::bitset(const _CharT* __str, 718227825Stheraven typename basic_string<_CharT>::size_type __n, 719227825Stheraven _CharT __zero, _CharT __one) 720227825Stheraven{ 721227825Stheraven size_t __rlen = _VSTD::min(__n, char_traits<_CharT>::length(__str)); 722227825Stheraven for (size_t __i = 0; __i < __rlen; ++__i) 723227825Stheraven if (__str[__i] != __zero && __str[__i] != __one) 724227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 725227825Stheraven throw invalid_argument("bitset string ctor has invalid argument"); 726227825Stheraven#else 727227825Stheraven assert(!"bitset string ctor has invalid argument"); 728227825Stheraven#endif 729232950Stheraven size_t _Mp = _VSTD::min(__rlen, _Size); 730227825Stheraven size_t __i = 0; 731232950Stheraven for (; __i < _Mp; ++__i) 732227825Stheraven { 733232950Stheraven _CharT __c = __str[_Mp - 1 - __i]; 734227825Stheraven if (__c == __zero) 735227825Stheraven (*this)[__i] = false; 736227825Stheraven else 737227825Stheraven (*this)[__i] = true; 738227825Stheraven } 739227825Stheraven _VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false); 740227825Stheraven} 741227825Stheraven 742227825Stheraventemplate <size_t _Size> 743227825Stheraventemplate<class _CharT, class _Traits, class _Allocator> 744227825Stheravenbitset<_Size>::bitset(const basic_string<_CharT,_Traits,_Allocator>& __str, 745227825Stheraven typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos, 746227825Stheraven typename basic_string<_CharT,_Traits,_Allocator>::size_type __n, 747227825Stheraven _CharT __zero, _CharT __one) 748227825Stheraven{ 749227825Stheraven if (__pos > __str.size()) 750227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 751227825Stheraven throw out_of_range("bitset string pos out of range"); 752227825Stheraven#else 753227825Stheraven assert(!"bitset string pos out of range"); 754227825Stheraven#endif 755227825Stheraven size_t __rlen = _VSTD::min(__n, __str.size() - __pos); 756227825Stheraven for (size_t __i = __pos; __i < __pos + __rlen; ++__i) 757227825Stheraven if (!_Traits::eq(__str[__i], __zero) && !_Traits::eq(__str[__i], __one)) 758227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 759227825Stheraven throw invalid_argument("bitset string ctor has invalid argument"); 760227825Stheraven#else 761227825Stheraven assert(!"bitset string ctor has invalid argument"); 762227825Stheraven#endif 763232950Stheraven size_t _Mp = _VSTD::min(__rlen, _Size); 764227825Stheraven size_t __i = 0; 765232950Stheraven for (; __i < _Mp; ++__i) 766227825Stheraven { 767232950Stheraven _CharT __c = __str[__pos + _Mp - 1 - __i]; 768227825Stheraven if (_Traits::eq(__c, __zero)) 769227825Stheraven (*this)[__i] = false; 770227825Stheraven else 771227825Stheraven (*this)[__i] = true; 772227825Stheraven } 773227825Stheraven _VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false); 774227825Stheraven} 775227825Stheraven 776227825Stheraventemplate <size_t _Size> 777227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 778227825Stheravenbitset<_Size>& 779227825Stheravenbitset<_Size>::operator&=(const bitset& __rhs) _NOEXCEPT 780227825Stheraven{ 781227825Stheraven base::operator&=(__rhs); 782227825Stheraven return *this; 783227825Stheraven} 784227825Stheraven 785227825Stheraventemplate <size_t _Size> 786227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 787227825Stheravenbitset<_Size>& 788227825Stheravenbitset<_Size>::operator|=(const bitset& __rhs) _NOEXCEPT 789227825Stheraven{ 790227825Stheraven base::operator|=(__rhs); 791227825Stheraven return *this; 792227825Stheraven} 793227825Stheraven 794227825Stheraventemplate <size_t _Size> 795227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 796227825Stheravenbitset<_Size>& 797227825Stheravenbitset<_Size>::operator^=(const bitset& __rhs) _NOEXCEPT 798227825Stheraven{ 799227825Stheraven base::operator^=(__rhs); 800227825Stheraven return *this; 801227825Stheraven} 802227825Stheraven 803227825Stheraventemplate <size_t _Size> 804227825Stheravenbitset<_Size>& 805227825Stheravenbitset<_Size>::operator<<=(size_t __pos) _NOEXCEPT 806227825Stheraven{ 807227825Stheraven __pos = _VSTD::min(__pos, _Size); 808227825Stheraven _VSTD::copy_backward(base::__make_iter(0), base::__make_iter(_Size - __pos), base::__make_iter(_Size)); 809227825Stheraven _VSTD::fill_n(base::__make_iter(0), __pos, false); 810227825Stheraven return *this; 811227825Stheraven} 812227825Stheraven 813227825Stheraventemplate <size_t _Size> 814227825Stheravenbitset<_Size>& 815227825Stheravenbitset<_Size>::operator>>=(size_t __pos) _NOEXCEPT 816227825Stheraven{ 817227825Stheraven __pos = _VSTD::min(__pos, _Size); 818227825Stheraven _VSTD::copy(base::__make_iter(__pos), base::__make_iter(_Size), base::__make_iter(0)); 819227825Stheraven _VSTD::fill_n(base::__make_iter(_Size - __pos), __pos, false); 820227825Stheraven return *this; 821227825Stheraven} 822227825Stheraven 823227825Stheraventemplate <size_t _Size> 824227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 825227825Stheravenbitset<_Size>& 826227825Stheravenbitset<_Size>::set() _NOEXCEPT 827227825Stheraven{ 828227825Stheraven _VSTD::fill_n(base::__make_iter(0), _Size, true); 829227825Stheraven return *this; 830227825Stheraven} 831227825Stheraven 832227825Stheraventemplate <size_t _Size> 833227825Stheravenbitset<_Size>& 834227825Stheravenbitset<_Size>::set(size_t __pos, bool __val) 835227825Stheraven{ 836227825Stheraven if (__pos >= _Size) 837227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 838227825Stheraven throw out_of_range("bitset set argument out of range"); 839227825Stheraven#else 840227825Stheraven assert(!"bitset set argument out of range"); 841227825Stheraven#endif 842227825Stheraven (*this)[__pos] = __val; 843227825Stheraven return *this; 844227825Stheraven} 845227825Stheraven 846227825Stheraventemplate <size_t _Size> 847227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 848227825Stheravenbitset<_Size>& 849227825Stheravenbitset<_Size>::reset() _NOEXCEPT 850227825Stheraven{ 851227825Stheraven _VSTD::fill_n(base::__make_iter(0), _Size, false); 852227825Stheraven return *this; 853227825Stheraven} 854227825Stheraven 855227825Stheraventemplate <size_t _Size> 856227825Stheravenbitset<_Size>& 857227825Stheravenbitset<_Size>::reset(size_t __pos) 858227825Stheraven{ 859227825Stheraven if (__pos >= _Size) 860227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 861227825Stheraven throw out_of_range("bitset reset argument out of range"); 862227825Stheraven#else 863227825Stheraven assert(!"bitset reset argument out of range"); 864227825Stheraven#endif 865227825Stheraven (*this)[__pos] = false; 866227825Stheraven return *this; 867227825Stheraven} 868227825Stheraven 869227825Stheraventemplate <size_t _Size> 870227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 871227825Stheravenbitset<_Size> 872227825Stheravenbitset<_Size>::operator~() const _NOEXCEPT 873227825Stheraven{ 874227825Stheraven bitset __x(*this); 875227825Stheraven __x.flip(); 876227825Stheraven return __x; 877227825Stheraven} 878227825Stheraven 879227825Stheraventemplate <size_t _Size> 880227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 881227825Stheravenbitset<_Size>& 882227825Stheravenbitset<_Size>::flip() _NOEXCEPT 883227825Stheraven{ 884227825Stheraven base::flip(); 885227825Stheraven return *this; 886227825Stheraven} 887227825Stheraven 888227825Stheraventemplate <size_t _Size> 889227825Stheravenbitset<_Size>& 890227825Stheravenbitset<_Size>::flip(size_t __pos) 891227825Stheraven{ 892227825Stheraven if (__pos >= _Size) 893227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 894227825Stheraven throw out_of_range("bitset flip argument out of range"); 895227825Stheraven#else 896227825Stheraven assert(!"bitset flip argument out of range"); 897227825Stheraven#endif 898227825Stheraven reference r = base::__make_ref(__pos); 899227825Stheraven r = ~r; 900227825Stheraven return *this; 901227825Stheraven} 902227825Stheraven 903227825Stheraventemplate <size_t _Size> 904227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 905227825Stheravenunsigned long 906227825Stheravenbitset<_Size>::to_ulong() const 907227825Stheraven{ 908227825Stheraven return base::to_ulong(); 909227825Stheraven} 910227825Stheraven 911227825Stheraventemplate <size_t _Size> 912227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 913227825Stheravenunsigned long long 914227825Stheravenbitset<_Size>::to_ullong() const 915227825Stheraven{ 916227825Stheraven return base::to_ullong(); 917227825Stheraven} 918227825Stheraven 919227825Stheraventemplate <size_t _Size> 920227825Stheraventemplate <class _CharT, class _Traits, class _Allocator> 921227825Stheravenbasic_string<_CharT, _Traits, _Allocator> 922227825Stheravenbitset<_Size>::to_string(_CharT __zero, _CharT __one) const 923227825Stheraven{ 924227825Stheraven basic_string<_CharT, _Traits, _Allocator> __r(_Size, __zero); 925227825Stheraven for (size_t __i = 0; __i < _Size; ++__i) 926227825Stheraven { 927227825Stheraven if ((*this)[__i]) 928227825Stheraven __r[_Size - 1 - __i] = __one; 929227825Stheraven } 930227825Stheraven return __r; 931227825Stheraven} 932227825Stheraven 933227825Stheraventemplate <size_t _Size> 934227825Stheraventemplate <class _CharT, class _Traits> 935227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 936227825Stheravenbasic_string<_CharT, _Traits, allocator<_CharT> > 937227825Stheravenbitset<_Size>::to_string(_CharT __zero, _CharT __one) const 938227825Stheraven{ 939227825Stheraven return to_string<_CharT, _Traits, allocator<_CharT> >(__zero, __one); 940227825Stheraven} 941227825Stheraven 942227825Stheraventemplate <size_t _Size> 943227825Stheraventemplate <class _CharT> 944227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 945227825Stheravenbasic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > 946227825Stheravenbitset<_Size>::to_string(_CharT __zero, _CharT __one) const 947227825Stheraven{ 948227825Stheraven return to_string<_CharT, char_traits<_CharT>, allocator<_CharT> >(__zero, __one); 949227825Stheraven} 950227825Stheraven 951227825Stheraventemplate <size_t _Size> 952227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 953227825Stheravenbasic_string<char, char_traits<char>, allocator<char> > 954227825Stheravenbitset<_Size>::to_string(char __zero, char __one) const 955227825Stheraven{ 956227825Stheraven return to_string<char, char_traits<char>, allocator<char> >(__zero, __one); 957227825Stheraven} 958227825Stheraven 959227825Stheraventemplate <size_t _Size> 960227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 961227825Stheravensize_t 962227825Stheravenbitset<_Size>::count() const _NOEXCEPT 963227825Stheraven{ 964227825Stheraven return static_cast<size_t>(_VSTD::count(base::__make_iter(0), base::__make_iter(_Size), true)); 965227825Stheraven} 966227825Stheraven 967227825Stheraventemplate <size_t _Size> 968227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 969227825Stheravenbool 970227825Stheravenbitset<_Size>::operator==(const bitset& __rhs) const _NOEXCEPT 971227825Stheraven{ 972227825Stheraven return _VSTD::equal(base::__make_iter(0), base::__make_iter(_Size), __rhs.__make_iter(0)); 973227825Stheraven} 974227825Stheraven 975227825Stheraventemplate <size_t _Size> 976227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 977227825Stheravenbool 978227825Stheravenbitset<_Size>::operator!=(const bitset& __rhs) const _NOEXCEPT 979227825Stheraven{ 980227825Stheraven return !(*this == __rhs); 981227825Stheraven} 982227825Stheraven 983227825Stheraventemplate <size_t _Size> 984227825Stheravenbool 985227825Stheravenbitset<_Size>::test(size_t __pos) const 986227825Stheraven{ 987227825Stheraven if (__pos >= _Size) 988227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 989227825Stheraven throw out_of_range("bitset test argument out of range"); 990227825Stheraven#else 991227825Stheraven assert(!"bitset test argument out of range"); 992227825Stheraven#endif 993227825Stheraven return (*this)[__pos]; 994227825Stheraven} 995227825Stheraven 996227825Stheraventemplate <size_t _Size> 997227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 998227825Stheravenbool 999227825Stheravenbitset<_Size>::all() const _NOEXCEPT 1000227825Stheraven{ 1001227825Stheraven return base::all(); 1002227825Stheraven} 1003227825Stheraven 1004227825Stheraventemplate <size_t _Size> 1005227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 1006227825Stheravenbool 1007227825Stheravenbitset<_Size>::any() const _NOEXCEPT 1008227825Stheraven{ 1009227825Stheraven return base::any(); 1010227825Stheraven} 1011227825Stheraven 1012227825Stheraventemplate <size_t _Size> 1013227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 1014227825Stheravenbitset<_Size> 1015227825Stheravenbitset<_Size>::operator<<(size_t __pos) const _NOEXCEPT 1016227825Stheraven{ 1017227825Stheraven bitset __r = *this; 1018227825Stheraven __r <<= __pos; 1019227825Stheraven return __r; 1020227825Stheraven} 1021227825Stheraven 1022227825Stheraventemplate <size_t _Size> 1023227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 1024227825Stheravenbitset<_Size> 1025227825Stheravenbitset<_Size>::operator>>(size_t __pos) const _NOEXCEPT 1026227825Stheraven{ 1027227825Stheraven bitset __r = *this; 1028227825Stheraven __r >>= __pos; 1029227825Stheraven return __r; 1030227825Stheraven} 1031227825Stheraven 1032227825Stheraventemplate <size_t _Size> 1033227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 1034227825Stheravenbitset<_Size> 1035227825Stheravenoperator&(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT 1036227825Stheraven{ 1037227825Stheraven bitset<_Size> __r = __x; 1038227825Stheraven __r &= __y; 1039227825Stheraven return __r; 1040227825Stheraven} 1041227825Stheraven 1042227825Stheraventemplate <size_t _Size> 1043227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 1044227825Stheravenbitset<_Size> 1045227825Stheravenoperator|(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT 1046227825Stheraven{ 1047227825Stheraven bitset<_Size> __r = __x; 1048227825Stheraven __r |= __y; 1049227825Stheraven return __r; 1050227825Stheraven} 1051227825Stheraven 1052227825Stheraventemplate <size_t _Size> 1053227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 1054227825Stheravenbitset<_Size> 1055227825Stheravenoperator^(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT 1056227825Stheraven{ 1057227825Stheraven bitset<_Size> __r = __x; 1058227825Stheraven __r ^= __y; 1059227825Stheraven return __r; 1060227825Stheraven} 1061227825Stheraven 1062227825Stheraventemplate <size_t _Size> 1063262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY hash<bitset<_Size> > 1064227825Stheraven : public unary_function<bitset<_Size>, size_t> 1065227825Stheraven{ 1066227825Stheraven _LIBCPP_INLINE_VISIBILITY 1067227825Stheraven size_t operator()(const bitset<_Size>& __bs) const _NOEXCEPT 1068227825Stheraven {return __bs.__hash_code();} 1069227825Stheraven}; 1070227825Stheraven 1071227825Stheraventemplate <class _CharT, class _Traits, size_t _Size> 1072227825Stheravenbasic_istream<_CharT, _Traits>& 1073227825Stheravenoperator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x); 1074227825Stheraven 1075227825Stheraventemplate <class _CharT, class _Traits, size_t _Size> 1076227825Stheravenbasic_ostream<_CharT, _Traits>& 1077227825Stheravenoperator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x); 1078227825Stheraven 1079227825Stheraven_LIBCPP_END_NAMESPACE_STD 1080227825Stheraven 1081227825Stheraven#endif // _LIBCPP_BITSET 1082