bitset revision 241903
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 252241903Sdim : __first_{__v} 253241903Sdim#endif 254227825Stheraven{ 255241903Sdim#ifdef _LIBCPP_HAS_NO_CONSTEXPR 256227825Stheraven __init(__v, integral_constant<bool, sizeof(unsigned long long) == sizeof(__storage_type)>()); 257241903Sdim#endif 258227825Stheraven} 259227825Stheraven 260227825Stheraventemplate <size_t _N_words, size_t _Size> 261227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 262227825Stheravenvoid 263227825Stheraven__bitset<_N_words, _Size>::operator&=(const __bitset& __v) _NOEXCEPT 264227825Stheraven{ 265227825Stheraven for (size_type __i = 0; __i < _N_words; ++__i) 266227825Stheraven __first_[__i] &= __v.__first_[__i]; 267227825Stheraven} 268227825Stheraven 269227825Stheraventemplate <size_t _N_words, size_t _Size> 270227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 271227825Stheravenvoid 272227825Stheraven__bitset<_N_words, _Size>::operator|=(const __bitset& __v) _NOEXCEPT 273227825Stheraven{ 274227825Stheraven for (size_type __i = 0; __i < _N_words; ++__i) 275227825Stheraven __first_[__i] |= __v.__first_[__i]; 276227825Stheraven} 277227825Stheraven 278227825Stheraventemplate <size_t _N_words, size_t _Size> 279227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 280227825Stheravenvoid 281227825Stheraven__bitset<_N_words, _Size>::operator^=(const __bitset& __v) _NOEXCEPT 282227825Stheraven{ 283227825Stheraven for (size_type __i = 0; __i < _N_words; ++__i) 284227825Stheraven __first_[__i] ^= __v.__first_[__i]; 285227825Stheraven} 286227825Stheraven 287227825Stheraventemplate <size_t _N_words, size_t _Size> 288227825Stheravenvoid 289227825Stheraven__bitset<_N_words, _Size>::flip() _NOEXCEPT 290227825Stheraven{ 291227825Stheraven // do middle whole words 292227825Stheraven size_type __n = _Size; 293227825Stheraven __storage_pointer __p = __first_; 294227825Stheraven for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) 295227825Stheraven *__p = ~*__p; 296227825Stheraven // do last partial word 297227825Stheraven if (__n > 0) 298227825Stheraven { 299227825Stheraven __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); 300227825Stheraven __storage_type __b = *__p & __m; 301227825Stheraven *__p &= ~__m; 302227825Stheraven *__p |= ~__b & __m; 303227825Stheraven } 304227825Stheraven} 305227825Stheraven 306227825Stheraventemplate <size_t _N_words, size_t _Size> 307227825Stheravenunsigned long 308227825Stheraven__bitset<_N_words, _Size>::to_ulong(false_type) const 309227825Stheraven{ 310227825Stheraven const_iterator __e = __make_iter(_Size); 311227825Stheraven const_iterator __i = _VSTD::find(__make_iter(sizeof(unsigned long) * CHAR_BIT), __e, true); 312227825Stheraven if (__i != __e) 313227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 314227825Stheraven throw overflow_error("bitset to_ulong overflow error"); 315227825Stheraven#else 316227825Stheraven assert(!"bitset to_ulong overflow error"); 317227825Stheraven#endif 318227825Stheraven return __first_[0]; 319227825Stheraven} 320227825Stheraven 321227825Stheraventemplate <size_t _N_words, size_t _Size> 322227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 323227825Stheravenunsigned long 324227825Stheraven__bitset<_N_words, _Size>::to_ulong(true_type) const 325227825Stheraven{ 326227825Stheraven return __first_[0]; 327227825Stheraven} 328227825Stheraven 329227825Stheraventemplate <size_t _N_words, size_t _Size> 330227825Stheravenunsigned long long 331227825Stheraven__bitset<_N_words, _Size>::to_ullong(false_type) const 332227825Stheraven{ 333227825Stheraven const_iterator __e = __make_iter(_Size); 334227825Stheraven const_iterator __i = _VSTD::find(__make_iter(sizeof(unsigned long long) * CHAR_BIT), __e, true); 335227825Stheraven if (__i != __e) 336227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 337227825Stheraven throw overflow_error("bitset to_ullong overflow error"); 338227825Stheraven#else 339227825Stheraven assert(!"bitset to_ullong overflow error"); 340227825Stheraven#endif 341227825Stheraven return to_ullong(true_type()); 342227825Stheraven} 343227825Stheraven 344227825Stheraventemplate <size_t _N_words, size_t _Size> 345227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 346227825Stheravenunsigned long long 347227825Stheraven__bitset<_N_words, _Size>::to_ullong(true_type) const 348227825Stheraven{ 349227825Stheraven return to_ullong(true_type(), integral_constant<bool, sizeof(__storage_type) < sizeof(unsigned long long)>()); 350227825Stheraven} 351227825Stheraven 352227825Stheraventemplate <size_t _N_words, size_t _Size> 353227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 354227825Stheravenunsigned long long 355227825Stheraven__bitset<_N_words, _Size>::to_ullong(true_type, false_type) const 356227825Stheraven{ 357227825Stheraven return __first_[0]; 358227825Stheraven} 359227825Stheraven 360227825Stheraventemplate <size_t _N_words, size_t _Size> 361227825Stheravenunsigned long long 362227825Stheraven__bitset<_N_words, _Size>::to_ullong(true_type, true_type) const 363227825Stheraven{ 364227825Stheraven unsigned long long __r = __first_[0]; 365227825Stheraven for (std::size_t __i = 1; __i < sizeof(unsigned long long) / sizeof(__storage_type); ++__i) 366227825Stheraven __r |= static_cast<unsigned long long>(__first_[__i]) << (sizeof(__storage_type) * CHAR_BIT); 367227825Stheraven return __r; 368227825Stheraven} 369227825Stheraven 370227825Stheraventemplate <size_t _N_words, size_t _Size> 371227825Stheravenbool 372227825Stheraven__bitset<_N_words, _Size>::all() const _NOEXCEPT 373227825Stheraven{ 374227825Stheraven // do middle whole words 375227825Stheraven size_type __n = _Size; 376227825Stheraven __const_storage_pointer __p = __first_; 377227825Stheraven for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) 378227825Stheraven if (~*__p) 379227825Stheraven return false; 380227825Stheraven // do last partial word 381227825Stheraven if (__n > 0) 382227825Stheraven { 383227825Stheraven __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); 384227825Stheraven if (~*__p & __m) 385227825Stheraven return false; 386227825Stheraven } 387227825Stheraven return true; 388227825Stheraven} 389227825Stheraven 390227825Stheraventemplate <size_t _N_words, size_t _Size> 391227825Stheravenbool 392227825Stheraven__bitset<_N_words, _Size>::any() const _NOEXCEPT 393227825Stheraven{ 394227825Stheraven // do middle whole words 395227825Stheraven size_type __n = _Size; 396227825Stheraven __const_storage_pointer __p = __first_; 397227825Stheraven for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) 398227825Stheraven if (*__p) 399227825Stheraven return true; 400227825Stheraven // do last partial word 401227825Stheraven if (__n > 0) 402227825Stheraven { 403227825Stheraven __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); 404227825Stheraven if (*__p & __m) 405227825Stheraven return true; 406227825Stheraven } 407227825Stheraven return false; 408227825Stheraven} 409227825Stheraven 410227825Stheraventemplate <size_t _N_words, size_t _Size> 411227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 412227825Stheravensize_t 413227825Stheraven__bitset<_N_words, _Size>::__hash_code() const _NOEXCEPT 414227825Stheraven{ 415227825Stheraven size_t __h = 0; 416227825Stheraven for (size_type __i = 0; __i < _N_words; ++__i) 417227825Stheraven __h ^= __first_[__i]; 418227825Stheraven return __h; 419227825Stheraven} 420227825Stheraven 421227825Stheraventemplate <size_t _Size> 422227825Stheravenclass __bitset<1, _Size> 423227825Stheraven{ 424227825Stheravenpublic: 425227825Stheraven typedef ptrdiff_t difference_type; 426227825Stheraven typedef size_t size_type; 427241903Sdim typedef size_type __storage_type; 428227825Stheravenprotected: 429227825Stheraven typedef __bitset __self; 430227825Stheraven typedef __storage_type* __storage_pointer; 431227825Stheraven typedef const __storage_type* __const_storage_pointer; 432227825Stheraven static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT); 433227825Stheraven 434227825Stheraven friend class __bit_reference<__bitset>; 435227825Stheraven friend class __bit_const_reference<__bitset>; 436227825Stheraven friend class __bit_iterator<__bitset, false>; 437227825Stheraven friend class __bit_iterator<__bitset, true>; 438241903Sdim friend struct __bit_array<__bitset>; 439227825Stheraven 440227825Stheraven __storage_type __first_; 441227825Stheraven 442227825Stheraven typedef __bit_reference<__bitset> reference; 443227825Stheraven typedef __bit_const_reference<__bitset> const_reference; 444227825Stheraven typedef __bit_iterator<__bitset, false> iterator; 445227825Stheraven typedef __bit_iterator<__bitset, true> const_iterator; 446227825Stheraven 447241903Sdim _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT; 448241903Sdim explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT; 449227825Stheraven 450227825Stheraven _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t __pos) _NOEXCEPT 451227825Stheraven {return reference(&__first_, __storage_type(1) << __pos);} 452241903Sdim _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT 453227825Stheraven {return const_reference(&__first_, __storage_type(1) << __pos);} 454227825Stheraven _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t __pos) _NOEXCEPT 455227825Stheraven {return iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);} 456227825Stheraven _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t __pos) const _NOEXCEPT 457227825Stheraven {return const_iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);} 458227825Stheraven 459227825Stheraven void operator&=(const __bitset& __v) _NOEXCEPT; 460227825Stheraven void operator|=(const __bitset& __v) _NOEXCEPT; 461227825Stheraven void operator^=(const __bitset& __v) _NOEXCEPT; 462227825Stheraven 463227825Stheraven void flip() _NOEXCEPT; 464227825Stheraven 465227825Stheraven unsigned long to_ulong() const; 466227825Stheraven unsigned long long to_ullong() const; 467227825Stheraven 468227825Stheraven bool all() const _NOEXCEPT; 469227825Stheraven bool any() const _NOEXCEPT; 470227825Stheraven 471227825Stheraven size_t __hash_code() const _NOEXCEPT; 472227825Stheraven}; 473227825Stheraven 474227825Stheraventemplate <size_t _Size> 475227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 476241903Sdim_LIBCPP_CONSTEXPR 477227825Stheraven__bitset<1, _Size>::__bitset() _NOEXCEPT 478227825Stheraven : __first_(0) 479227825Stheraven{ 480227825Stheraven} 481227825Stheraven 482227825Stheraventemplate <size_t _Size> 483227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 484241903Sdim_LIBCPP_CONSTEXPR 485227825Stheraven__bitset<1, _Size>::__bitset(unsigned long long __v) _NOEXCEPT 486227825Stheraven : __first_(static_cast<__storage_type>(__v)) 487227825Stheraven{ 488227825Stheraven} 489227825Stheraven 490227825Stheraventemplate <size_t _Size> 491227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 492227825Stheravenvoid 493227825Stheraven__bitset<1, _Size>::operator&=(const __bitset& __v) _NOEXCEPT 494227825Stheraven{ 495227825Stheraven __first_ &= __v.__first_; 496227825Stheraven} 497227825Stheraven 498227825Stheraventemplate <size_t _Size> 499227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 500227825Stheravenvoid 501227825Stheraven__bitset<1, _Size>::operator|=(const __bitset& __v) _NOEXCEPT 502227825Stheraven{ 503227825Stheraven __first_ |= __v.__first_; 504227825Stheraven} 505227825Stheraven 506227825Stheraventemplate <size_t _Size> 507227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 508227825Stheravenvoid 509227825Stheraven__bitset<1, _Size>::operator^=(const __bitset& __v) _NOEXCEPT 510227825Stheraven{ 511227825Stheraven __first_ ^= __v.__first_; 512227825Stheraven} 513227825Stheraven 514227825Stheraventemplate <size_t _Size> 515227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 516227825Stheravenvoid 517227825Stheraven__bitset<1, _Size>::flip() _NOEXCEPT 518227825Stheraven{ 519227825Stheraven __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size); 520227825Stheraven __first_ = ~__first_; 521227825Stheraven __first_ &= __m; 522227825Stheraven} 523227825Stheraven 524227825Stheraventemplate <size_t _Size> 525227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 526227825Stheravenunsigned long 527227825Stheraven__bitset<1, _Size>::to_ulong() const 528227825Stheraven{ 529227825Stheraven return __first_; 530227825Stheraven} 531227825Stheraven 532227825Stheraventemplate <size_t _Size> 533227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 534227825Stheravenunsigned long long 535227825Stheraven__bitset<1, _Size>::to_ullong() const 536227825Stheraven{ 537227825Stheraven return __first_; 538227825Stheraven} 539227825Stheraven 540227825Stheraventemplate <size_t _Size> 541227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 542227825Stheravenbool 543227825Stheraven__bitset<1, _Size>::all() const _NOEXCEPT 544227825Stheraven{ 545227825Stheraven __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size); 546227825Stheraven return !(~__first_ & __m); 547227825Stheraven} 548227825Stheraven 549227825Stheraventemplate <size_t _Size> 550227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 551227825Stheravenbool 552227825Stheraven__bitset<1, _Size>::any() const _NOEXCEPT 553227825Stheraven{ 554227825Stheraven __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size); 555227825Stheraven return __first_ & __m; 556227825Stheraven} 557227825Stheraven 558227825Stheraventemplate <size_t _Size> 559227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 560227825Stheravensize_t 561227825Stheraven__bitset<1, _Size>::__hash_code() const _NOEXCEPT 562227825Stheraven{ 563227825Stheraven return __first_; 564227825Stheraven} 565227825Stheraven 566227825Stheraventemplate <> 567227825Stheravenclass __bitset<0, 0> 568227825Stheraven{ 569227825Stheravenpublic: 570227825Stheraven typedef ptrdiff_t difference_type; 571227825Stheraven typedef size_t size_type; 572241903Sdim typedef size_type __storage_type; 573227825Stheravenprotected: 574227825Stheraven typedef __bitset __self; 575227825Stheraven typedef __storage_type* __storage_pointer; 576227825Stheraven typedef const __storage_type* __const_storage_pointer; 577227825Stheraven static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT); 578227825Stheraven 579227825Stheraven friend class __bit_reference<__bitset>; 580227825Stheraven friend class __bit_const_reference<__bitset>; 581227825Stheraven friend class __bit_iterator<__bitset, false>; 582227825Stheraven friend class __bit_iterator<__bitset, true>; 583232950Stheraven friend struct __bit_array<__bitset>; 584227825Stheraven 585227825Stheraven typedef __bit_reference<__bitset> reference; 586227825Stheraven typedef __bit_const_reference<__bitset> const_reference; 587227825Stheraven typedef __bit_iterator<__bitset, false> iterator; 588227825Stheraven typedef __bit_iterator<__bitset, true> const_iterator; 589227825Stheraven 590241903Sdim _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT; 591241903Sdim explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long) _NOEXCEPT; 592227825Stheraven 593227825Stheraven _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t) _NOEXCEPT 594227825Stheraven {return reference(0, 1);} 595241903Sdim _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t) const _NOEXCEPT 596227825Stheraven {return const_reference(0, 1);} 597232950Stheraven _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t) _NOEXCEPT 598227825Stheraven {return iterator(0, 0);} 599232950Stheraven _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t) const _NOEXCEPT 600227825Stheraven {return const_iterator(0, 0);} 601227825Stheraven 602227825Stheraven _LIBCPP_INLINE_VISIBILITY void operator&=(const __bitset&) _NOEXCEPT {} 603227825Stheraven _LIBCPP_INLINE_VISIBILITY void operator|=(const __bitset&) _NOEXCEPT {} 604227825Stheraven _LIBCPP_INLINE_VISIBILITY void operator^=(const __bitset&) _NOEXCEPT {} 605227825Stheraven 606227825Stheraven _LIBCPP_INLINE_VISIBILITY void flip() _NOEXCEPT {} 607227825Stheraven 608227825Stheraven _LIBCPP_INLINE_VISIBILITY unsigned long to_ulong() const {return 0;} 609227825Stheraven _LIBCPP_INLINE_VISIBILITY unsigned long long to_ullong() const {return 0;} 610227825Stheraven 611227825Stheraven _LIBCPP_INLINE_VISIBILITY bool all() const _NOEXCEPT {return true;} 612227825Stheraven _LIBCPP_INLINE_VISIBILITY bool any() const _NOEXCEPT {return false;} 613227825Stheraven 614227825Stheraven _LIBCPP_INLINE_VISIBILITY size_t __hash_code() const _NOEXCEPT {return 0;} 615227825Stheraven}; 616227825Stheraven 617227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 618241903Sdim_LIBCPP_CONSTEXPR 619227825Stheraven__bitset<0, 0>::__bitset() _NOEXCEPT 620227825Stheraven{ 621227825Stheraven} 622227825Stheraven 623227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 624241903Sdim_LIBCPP_CONSTEXPR 625227825Stheraven__bitset<0, 0>::__bitset(unsigned long long) _NOEXCEPT 626227825Stheraven{ 627227825Stheraven} 628227825Stheraven 629241903Sdimtemplate <size_t _Size> class _LIBCPP_VISIBLE bitset; 630227825Stheraventemplate <size_t _Size> struct hash<bitset<_Size> >; 631227825Stheraven 632227825Stheraventemplate <size_t _Size> 633227825Stheravenclass _LIBCPP_VISIBLE bitset 634227825Stheraven : private __bitset<_Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1, _Size> 635227825Stheraven{ 636227825Stheraven static const unsigned __n_words = _Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1; 637227825Stheraven typedef __bitset<__n_words, _Size> base; 638227825Stheraven 639227825Stheravenpublic: 640227825Stheraven typedef typename base::reference reference; 641227825Stheraven typedef typename base::const_reference const_reference; 642227825Stheraven 643227825Stheraven // 23.3.5.1 constructors: 644241903Sdim _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bitset() _NOEXCEPT {} 645241903Sdim _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 646241903Sdim bitset(unsigned long long __v) _NOEXCEPT : base(__v) {} 647227825Stheraven template<class _CharT> 648227825Stheraven explicit bitset(const _CharT* __str, 649227825Stheraven typename basic_string<_CharT>::size_type __n = basic_string<_CharT>::npos, 650227825Stheraven _CharT __zero = _CharT('0'), _CharT __one = _CharT('1')); 651227825Stheraven template<class _CharT, class _Traits, class _Allocator> 652227825Stheraven explicit bitset(const basic_string<_CharT,_Traits,_Allocator>& __str, 653227825Stheraven typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos = 0, 654227825Stheraven typename basic_string<_CharT,_Traits,_Allocator>::size_type __n = 655227825Stheraven (basic_string<_CharT,_Traits,_Allocator>::npos), 656227825Stheraven _CharT __zero = _CharT('0'), _CharT __one = _CharT('1')); 657227825Stheraven 658227825Stheraven // 23.3.5.2 bitset operations: 659227825Stheraven bitset& operator&=(const bitset& __rhs) _NOEXCEPT; 660227825Stheraven bitset& operator|=(const bitset& __rhs) _NOEXCEPT; 661227825Stheraven bitset& operator^=(const bitset& __rhs) _NOEXCEPT; 662227825Stheraven bitset& operator<<=(size_t __pos) _NOEXCEPT; 663227825Stheraven bitset& operator>>=(size_t __pos) _NOEXCEPT; 664227825Stheraven bitset& set() _NOEXCEPT; 665227825Stheraven bitset& set(size_t __pos, bool __val = true); 666227825Stheraven bitset& reset() _NOEXCEPT; 667227825Stheraven bitset& reset(size_t __pos); 668227825Stheraven bitset operator~() const _NOEXCEPT; 669227825Stheraven bitset& flip() _NOEXCEPT; 670227825Stheraven bitset& flip(size_t __pos); 671227825Stheraven 672227825Stheraven // element access: 673241903Sdim _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 674241903Sdim const_reference operator[](size_t __p) const {return base::__make_ref(__p);} 675227825Stheraven _LIBCPP_INLINE_VISIBILITY reference operator[](size_t __p) {return base::__make_ref(__p);} 676227825Stheraven unsigned long to_ulong() const; 677227825Stheraven unsigned long long to_ullong() const; 678227825Stheraven template <class _CharT, class _Traits, class _Allocator> 679227825Stheraven basic_string<_CharT, _Traits, _Allocator> to_string(_CharT __zero = _CharT('0'), 680227825Stheraven _CharT __one = _CharT('1')) const; 681227825Stheraven template <class _CharT, class _Traits> 682227825Stheraven basic_string<_CharT, _Traits, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'), 683227825Stheraven _CharT __one = _CharT('1')) const; 684227825Stheraven template <class _CharT> 685227825Stheraven basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'), 686227825Stheraven _CharT __one = _CharT('1')) const; 687227825Stheraven basic_string<char, char_traits<char>, allocator<char> > to_string(char __zero = '0', 688227825Stheraven char __one = '1') const; 689227825Stheraven size_t count() const _NOEXCEPT; 690241903Sdim _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR size_t size() const _NOEXCEPT {return _Size;} 691227825Stheraven bool operator==(const bitset& __rhs) const _NOEXCEPT; 692227825Stheraven bool operator!=(const bitset& __rhs) const _NOEXCEPT; 693227825Stheraven bool test(size_t __pos) const; 694227825Stheraven bool all() const _NOEXCEPT; 695227825Stheraven bool any() const _NOEXCEPT; 696227825Stheraven _LIBCPP_INLINE_VISIBILITY bool none() const _NOEXCEPT {return !any();} 697227825Stheraven bitset operator<<(size_t __pos) const _NOEXCEPT; 698227825Stheraven bitset operator>>(size_t __pos) const _NOEXCEPT; 699227825Stheraven 700227825Stheravenprivate: 701227825Stheraven 702227825Stheraven _LIBCPP_INLINE_VISIBILITY 703227825Stheraven size_t __hash_code() const _NOEXCEPT {return base::__hash_code();} 704227825Stheraven 705227825Stheraven friend struct hash<bitset>; 706227825Stheraven}; 707227825Stheraven 708227825Stheraventemplate <size_t _Size> 709227825Stheraventemplate<class _CharT> 710227825Stheravenbitset<_Size>::bitset(const _CharT* __str, 711227825Stheraven typename basic_string<_CharT>::size_type __n, 712227825Stheraven _CharT __zero, _CharT __one) 713227825Stheraven{ 714227825Stheraven size_t __rlen = _VSTD::min(__n, char_traits<_CharT>::length(__str)); 715227825Stheraven for (size_t __i = 0; __i < __rlen; ++__i) 716227825Stheraven if (__str[__i] != __zero && __str[__i] != __one) 717227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 718227825Stheraven throw invalid_argument("bitset string ctor has invalid argument"); 719227825Stheraven#else 720227825Stheraven assert(!"bitset string ctor has invalid argument"); 721227825Stheraven#endif 722232950Stheraven size_t _Mp = _VSTD::min(__rlen, _Size); 723227825Stheraven size_t __i = 0; 724232950Stheraven for (; __i < _Mp; ++__i) 725227825Stheraven { 726232950Stheraven _CharT __c = __str[_Mp - 1 - __i]; 727227825Stheraven if (__c == __zero) 728227825Stheraven (*this)[__i] = false; 729227825Stheraven else 730227825Stheraven (*this)[__i] = true; 731227825Stheraven } 732227825Stheraven _VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false); 733227825Stheraven} 734227825Stheraven 735227825Stheraventemplate <size_t _Size> 736227825Stheraventemplate<class _CharT, class _Traits, class _Allocator> 737227825Stheravenbitset<_Size>::bitset(const basic_string<_CharT,_Traits,_Allocator>& __str, 738227825Stheraven typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos, 739227825Stheraven typename basic_string<_CharT,_Traits,_Allocator>::size_type __n, 740227825Stheraven _CharT __zero, _CharT __one) 741227825Stheraven{ 742227825Stheraven if (__pos > __str.size()) 743227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 744227825Stheraven throw out_of_range("bitset string pos out of range"); 745227825Stheraven#else 746227825Stheraven assert(!"bitset string pos out of range"); 747227825Stheraven#endif 748227825Stheraven size_t __rlen = _VSTD::min(__n, __str.size() - __pos); 749227825Stheraven for (size_t __i = __pos; __i < __pos + __rlen; ++__i) 750227825Stheraven if (!_Traits::eq(__str[__i], __zero) && !_Traits::eq(__str[__i], __one)) 751227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 752227825Stheraven throw invalid_argument("bitset string ctor has invalid argument"); 753227825Stheraven#else 754227825Stheraven assert(!"bitset string ctor has invalid argument"); 755227825Stheraven#endif 756232950Stheraven size_t _Mp = _VSTD::min(__rlen, _Size); 757227825Stheraven size_t __i = 0; 758232950Stheraven for (; __i < _Mp; ++__i) 759227825Stheraven { 760232950Stheraven _CharT __c = __str[__pos + _Mp - 1 - __i]; 761227825Stheraven if (_Traits::eq(__c, __zero)) 762227825Stheraven (*this)[__i] = false; 763227825Stheraven else 764227825Stheraven (*this)[__i] = true; 765227825Stheraven } 766227825Stheraven _VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false); 767227825Stheraven} 768227825Stheraven 769227825Stheraventemplate <size_t _Size> 770227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 771227825Stheravenbitset<_Size>& 772227825Stheravenbitset<_Size>::operator&=(const bitset& __rhs) _NOEXCEPT 773227825Stheraven{ 774227825Stheraven base::operator&=(__rhs); 775227825Stheraven return *this; 776227825Stheraven} 777227825Stheraven 778227825Stheraventemplate <size_t _Size> 779227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 780227825Stheravenbitset<_Size>& 781227825Stheravenbitset<_Size>::operator|=(const bitset& __rhs) _NOEXCEPT 782227825Stheraven{ 783227825Stheraven base::operator|=(__rhs); 784227825Stheraven return *this; 785227825Stheraven} 786227825Stheraven 787227825Stheraventemplate <size_t _Size> 788227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 789227825Stheravenbitset<_Size>& 790227825Stheravenbitset<_Size>::operator^=(const bitset& __rhs) _NOEXCEPT 791227825Stheraven{ 792227825Stheraven base::operator^=(__rhs); 793227825Stheraven return *this; 794227825Stheraven} 795227825Stheraven 796227825Stheraventemplate <size_t _Size> 797227825Stheravenbitset<_Size>& 798227825Stheravenbitset<_Size>::operator<<=(size_t __pos) _NOEXCEPT 799227825Stheraven{ 800227825Stheraven __pos = _VSTD::min(__pos, _Size); 801227825Stheraven _VSTD::copy_backward(base::__make_iter(0), base::__make_iter(_Size - __pos), base::__make_iter(_Size)); 802227825Stheraven _VSTD::fill_n(base::__make_iter(0), __pos, false); 803227825Stheraven return *this; 804227825Stheraven} 805227825Stheraven 806227825Stheraventemplate <size_t _Size> 807227825Stheravenbitset<_Size>& 808227825Stheravenbitset<_Size>::operator>>=(size_t __pos) _NOEXCEPT 809227825Stheraven{ 810227825Stheraven __pos = _VSTD::min(__pos, _Size); 811227825Stheraven _VSTD::copy(base::__make_iter(__pos), base::__make_iter(_Size), base::__make_iter(0)); 812227825Stheraven _VSTD::fill_n(base::__make_iter(_Size - __pos), __pos, false); 813227825Stheraven return *this; 814227825Stheraven} 815227825Stheraven 816227825Stheraventemplate <size_t _Size> 817227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 818227825Stheravenbitset<_Size>& 819227825Stheravenbitset<_Size>::set() _NOEXCEPT 820227825Stheraven{ 821227825Stheraven _VSTD::fill_n(base::__make_iter(0), _Size, true); 822227825Stheraven return *this; 823227825Stheraven} 824227825Stheraven 825227825Stheraventemplate <size_t _Size> 826227825Stheravenbitset<_Size>& 827227825Stheravenbitset<_Size>::set(size_t __pos, bool __val) 828227825Stheraven{ 829227825Stheraven if (__pos >= _Size) 830227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 831227825Stheraven throw out_of_range("bitset set argument out of range"); 832227825Stheraven#else 833227825Stheraven assert(!"bitset set argument out of range"); 834227825Stheraven#endif 835227825Stheraven (*this)[__pos] = __val; 836227825Stheraven return *this; 837227825Stheraven} 838227825Stheraven 839227825Stheraventemplate <size_t _Size> 840227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 841227825Stheravenbitset<_Size>& 842227825Stheravenbitset<_Size>::reset() _NOEXCEPT 843227825Stheraven{ 844227825Stheraven _VSTD::fill_n(base::__make_iter(0), _Size, false); 845227825Stheraven return *this; 846227825Stheraven} 847227825Stheraven 848227825Stheraventemplate <size_t _Size> 849227825Stheravenbitset<_Size>& 850227825Stheravenbitset<_Size>::reset(size_t __pos) 851227825Stheraven{ 852227825Stheraven if (__pos >= _Size) 853227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 854227825Stheraven throw out_of_range("bitset reset argument out of range"); 855227825Stheraven#else 856227825Stheraven assert(!"bitset reset argument out of range"); 857227825Stheraven#endif 858227825Stheraven (*this)[__pos] = false; 859227825Stheraven return *this; 860227825Stheraven} 861227825Stheraven 862227825Stheraventemplate <size_t _Size> 863227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 864227825Stheravenbitset<_Size> 865227825Stheravenbitset<_Size>::operator~() const _NOEXCEPT 866227825Stheraven{ 867227825Stheraven bitset __x(*this); 868227825Stheraven __x.flip(); 869227825Stheraven return __x; 870227825Stheraven} 871227825Stheraven 872227825Stheraventemplate <size_t _Size> 873227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 874227825Stheravenbitset<_Size>& 875227825Stheravenbitset<_Size>::flip() _NOEXCEPT 876227825Stheraven{ 877227825Stheraven base::flip(); 878227825Stheraven return *this; 879227825Stheraven} 880227825Stheraven 881227825Stheraventemplate <size_t _Size> 882227825Stheravenbitset<_Size>& 883227825Stheravenbitset<_Size>::flip(size_t __pos) 884227825Stheraven{ 885227825Stheraven if (__pos >= _Size) 886227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 887227825Stheraven throw out_of_range("bitset flip argument out of range"); 888227825Stheraven#else 889227825Stheraven assert(!"bitset flip argument out of range"); 890227825Stheraven#endif 891227825Stheraven reference r = base::__make_ref(__pos); 892227825Stheraven r = ~r; 893227825Stheraven return *this; 894227825Stheraven} 895227825Stheraven 896227825Stheraventemplate <size_t _Size> 897227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 898227825Stheravenunsigned long 899227825Stheravenbitset<_Size>::to_ulong() const 900227825Stheraven{ 901227825Stheraven return base::to_ulong(); 902227825Stheraven} 903227825Stheraven 904227825Stheraventemplate <size_t _Size> 905227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 906227825Stheravenunsigned long long 907227825Stheravenbitset<_Size>::to_ullong() const 908227825Stheraven{ 909227825Stheraven return base::to_ullong(); 910227825Stheraven} 911227825Stheraven 912227825Stheraventemplate <size_t _Size> 913227825Stheraventemplate <class _CharT, class _Traits, class _Allocator> 914227825Stheravenbasic_string<_CharT, _Traits, _Allocator> 915227825Stheravenbitset<_Size>::to_string(_CharT __zero, _CharT __one) const 916227825Stheraven{ 917227825Stheraven basic_string<_CharT, _Traits, _Allocator> __r(_Size, __zero); 918227825Stheraven for (size_t __i = 0; __i < _Size; ++__i) 919227825Stheraven { 920227825Stheraven if ((*this)[__i]) 921227825Stheraven __r[_Size - 1 - __i] = __one; 922227825Stheraven } 923227825Stheraven return __r; 924227825Stheraven} 925227825Stheraven 926227825Stheraventemplate <size_t _Size> 927227825Stheraventemplate <class _CharT, class _Traits> 928227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 929227825Stheravenbasic_string<_CharT, _Traits, allocator<_CharT> > 930227825Stheravenbitset<_Size>::to_string(_CharT __zero, _CharT __one) const 931227825Stheraven{ 932227825Stheraven return to_string<_CharT, _Traits, allocator<_CharT> >(__zero, __one); 933227825Stheraven} 934227825Stheraven 935227825Stheraventemplate <size_t _Size> 936227825Stheraventemplate <class _CharT> 937227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 938227825Stheravenbasic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > 939227825Stheravenbitset<_Size>::to_string(_CharT __zero, _CharT __one) const 940227825Stheraven{ 941227825Stheraven return to_string<_CharT, char_traits<_CharT>, allocator<_CharT> >(__zero, __one); 942227825Stheraven} 943227825Stheraven 944227825Stheraventemplate <size_t _Size> 945227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 946227825Stheravenbasic_string<char, char_traits<char>, allocator<char> > 947227825Stheravenbitset<_Size>::to_string(char __zero, char __one) const 948227825Stheraven{ 949227825Stheraven return to_string<char, char_traits<char>, allocator<char> >(__zero, __one); 950227825Stheraven} 951227825Stheraven 952227825Stheraventemplate <size_t _Size> 953227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 954227825Stheravensize_t 955227825Stheravenbitset<_Size>::count() const _NOEXCEPT 956227825Stheraven{ 957227825Stheraven return static_cast<size_t>(_VSTD::count(base::__make_iter(0), base::__make_iter(_Size), true)); 958227825Stheraven} 959227825Stheraven 960227825Stheraventemplate <size_t _Size> 961227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 962227825Stheravenbool 963227825Stheravenbitset<_Size>::operator==(const bitset& __rhs) const _NOEXCEPT 964227825Stheraven{ 965227825Stheraven return _VSTD::equal(base::__make_iter(0), base::__make_iter(_Size), __rhs.__make_iter(0)); 966227825Stheraven} 967227825Stheraven 968227825Stheraventemplate <size_t _Size> 969227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 970227825Stheravenbool 971227825Stheravenbitset<_Size>::operator!=(const bitset& __rhs) const _NOEXCEPT 972227825Stheraven{ 973227825Stheraven return !(*this == __rhs); 974227825Stheraven} 975227825Stheraven 976227825Stheraventemplate <size_t _Size> 977227825Stheravenbool 978227825Stheravenbitset<_Size>::test(size_t __pos) const 979227825Stheraven{ 980227825Stheraven if (__pos >= _Size) 981227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 982227825Stheraven throw out_of_range("bitset test argument out of range"); 983227825Stheraven#else 984227825Stheraven assert(!"bitset test argument out of range"); 985227825Stheraven#endif 986227825Stheraven return (*this)[__pos]; 987227825Stheraven} 988227825Stheraven 989227825Stheraventemplate <size_t _Size> 990227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 991227825Stheravenbool 992227825Stheravenbitset<_Size>::all() const _NOEXCEPT 993227825Stheraven{ 994227825Stheraven return base::all(); 995227825Stheraven} 996227825Stheraven 997227825Stheraventemplate <size_t _Size> 998227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 999227825Stheravenbool 1000227825Stheravenbitset<_Size>::any() const _NOEXCEPT 1001227825Stheraven{ 1002227825Stheraven return base::any(); 1003227825Stheraven} 1004227825Stheraven 1005227825Stheraventemplate <size_t _Size> 1006227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 1007227825Stheravenbitset<_Size> 1008227825Stheravenbitset<_Size>::operator<<(size_t __pos) const _NOEXCEPT 1009227825Stheraven{ 1010227825Stheraven bitset __r = *this; 1011227825Stheraven __r <<= __pos; 1012227825Stheraven return __r; 1013227825Stheraven} 1014227825Stheraven 1015227825Stheraventemplate <size_t _Size> 1016227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 1017227825Stheravenbitset<_Size> 1018227825Stheravenbitset<_Size>::operator>>(size_t __pos) const _NOEXCEPT 1019227825Stheraven{ 1020227825Stheraven bitset __r = *this; 1021227825Stheraven __r >>= __pos; 1022227825Stheraven return __r; 1023227825Stheraven} 1024227825Stheraven 1025227825Stheraventemplate <size_t _Size> 1026227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 1027227825Stheravenbitset<_Size> 1028227825Stheravenoperator&(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT 1029227825Stheraven{ 1030227825Stheraven bitset<_Size> __r = __x; 1031227825Stheraven __r &= __y; 1032227825Stheraven return __r; 1033227825Stheraven} 1034227825Stheraven 1035227825Stheraventemplate <size_t _Size> 1036227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 1037227825Stheravenbitset<_Size> 1038227825Stheravenoperator|(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT 1039227825Stheraven{ 1040227825Stheraven bitset<_Size> __r = __x; 1041227825Stheraven __r |= __y; 1042227825Stheraven return __r; 1043227825Stheraven} 1044227825Stheraven 1045227825Stheraventemplate <size_t _Size> 1046227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 1047227825Stheravenbitset<_Size> 1048227825Stheravenoperator^(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT 1049227825Stheraven{ 1050227825Stheraven bitset<_Size> __r = __x; 1051227825Stheraven __r ^= __y; 1052227825Stheraven return __r; 1053227825Stheraven} 1054227825Stheraven 1055227825Stheraventemplate <size_t _Size> 1056227825Stheravenstruct _LIBCPP_VISIBLE hash<bitset<_Size> > 1057227825Stheraven : public unary_function<bitset<_Size>, size_t> 1058227825Stheraven{ 1059227825Stheraven _LIBCPP_INLINE_VISIBILITY 1060227825Stheraven size_t operator()(const bitset<_Size>& __bs) const _NOEXCEPT 1061227825Stheraven {return __bs.__hash_code();} 1062227825Stheraven}; 1063227825Stheraven 1064227825Stheraventemplate <class _CharT, class _Traits, size_t _Size> 1065227825Stheravenbasic_istream<_CharT, _Traits>& 1066227825Stheravenoperator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x); 1067227825Stheraven 1068227825Stheraventemplate <class _CharT, class _Traits, size_t _Size> 1069227825Stheravenbasic_ostream<_CharT, _Traits>& 1070227825Stheravenoperator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x); 1071227825Stheraven 1072227825Stheraven_LIBCPP_END_NAMESPACE_STD 1073227825Stheraven 1074227825Stheraven#endif // _LIBCPP_BITSET 1075