1227825Stheraven// -*- C++ -*- 2227825Stheraven//===---------------------------- bitset ----------------------------------===// 3227825Stheraven// 4353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5353358Sdim// See https://llvm.org/LICENSE.txt for license information. 6353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7227825Stheraven// 8227825Stheraven//===----------------------------------------------------------------------===// 9227825Stheraven 10227825Stheraven#ifndef _LIBCPP_BITSET 11227825Stheraven#define _LIBCPP_BITSET 12227825Stheraven 13227825Stheraven/* 14227825Stheraven bitset synopsis 15227825Stheraven 16227825Stheravennamespace std 17227825Stheraven{ 18227825Stheraven 19227825Stheravennamespace std { 20227825Stheraven 21227825Stheraventemplate <size_t N> 22227825Stheravenclass bitset 23227825Stheraven{ 24227825Stheravenpublic: 25227825Stheraven // bit reference: 26227825Stheraven class reference 27227825Stheraven { 28227825Stheraven friend class bitset; 29227825Stheraven reference() noexcept; 30227825Stheraven public: 31227825Stheraven ~reference() noexcept; 32227825Stheraven reference& operator=(bool x) noexcept; // for b[i] = x; 33227825Stheraven reference& operator=(const reference&) noexcept; // for b[i] = b[j]; 34227825Stheraven bool operator~() const noexcept; // flips the bit 35227825Stheraven operator bool() const noexcept; // for x = b[i]; 36227825Stheraven reference& flip() noexcept; // for b[i].flip(); 37227825Stheraven }; 38227825Stheraven 39227825Stheraven // 23.3.5.1 constructors: 40227825Stheraven constexpr bitset() noexcept; 41227825Stheraven constexpr bitset(unsigned long long val) noexcept; 42227825Stheraven template <class charT> 43227825Stheraven explicit bitset(const charT* str, 44227825Stheraven typename basic_string<charT>::size_type n = basic_string<charT>::npos, 45227825Stheraven charT zero = charT('0'), charT one = charT('1')); 46227825Stheraven template<class charT, class traits, class Allocator> 47227825Stheraven explicit bitset(const basic_string<charT,traits,Allocator>& str, 48227825Stheraven typename basic_string<charT,traits,Allocator>::size_type pos = 0, 49227825Stheraven typename basic_string<charT,traits,Allocator>::size_type n = 50227825Stheraven basic_string<charT,traits,Allocator>::npos, 51227825Stheraven charT zero = charT('0'), charT one = charT('1')); 52227825Stheraven 53227825Stheraven // 23.3.5.2 bitset operations: 54227825Stheraven bitset& operator&=(const bitset& rhs) noexcept; 55227825Stheraven bitset& operator|=(const bitset& rhs) noexcept; 56227825Stheraven bitset& operator^=(const bitset& rhs) noexcept; 57227825Stheraven bitset& operator<<=(size_t pos) noexcept; 58227825Stheraven bitset& operator>>=(size_t pos) noexcept; 59227825Stheraven bitset& set() noexcept; 60227825Stheraven bitset& set(size_t pos, bool val = true); 61227825Stheraven bitset& reset() noexcept; 62227825Stheraven bitset& reset(size_t pos); 63227825Stheraven bitset operator~() const noexcept; 64227825Stheraven bitset& flip() noexcept; 65227825Stheraven bitset& flip(size_t pos); 66227825Stheraven 67227825Stheraven // element access: 68227825Stheraven constexpr bool operator[](size_t pos) const; // for b[i]; 69227825Stheraven reference operator[](size_t pos); // for b[i]; 70227825Stheraven unsigned long to_ulong() const; 71227825Stheraven unsigned long long to_ullong() const; 72227825Stheraven template <class charT, class traits, class Allocator> 73227825Stheraven basic_string<charT, traits, Allocator> to_string(charT zero = charT('0'), charT one = charT('1')) const; 74227825Stheraven template <class charT, class traits> 75227825Stheraven basic_string<charT, traits, allocator<charT> > to_string(charT zero = charT('0'), charT one = charT('1')) const; 76227825Stheraven template <class charT> 77227825Stheraven basic_string<charT, char_traits<charT>, allocator<charT> > to_string(charT zero = charT('0'), charT one = charT('1')) const; 78227825Stheraven basic_string<char, char_traits<char>, allocator<char> > to_string(char zero = '0', char one = '1') const; 79227825Stheraven size_t count() const noexcept; 80227825Stheraven constexpr size_t size() const noexcept; 81227825Stheraven bool operator==(const bitset& rhs) const noexcept; 82227825Stheraven bool operator!=(const bitset& rhs) const noexcept; 83227825Stheraven bool test(size_t pos) const; 84227825Stheraven bool all() const noexcept; 85227825Stheraven bool any() const noexcept; 86227825Stheraven bool none() const noexcept; 87227825Stheraven bitset operator<<(size_t pos) const noexcept; 88227825Stheraven bitset operator>>(size_t pos) const noexcept; 89227825Stheraven}; 90227825Stheraven 91227825Stheraven// 23.3.5.3 bitset operators: 92227825Stheraventemplate <size_t N> 93227825Stheravenbitset<N> operator&(const bitset<N>&, const bitset<N>&) noexcept; 94227825Stheraven 95227825Stheraventemplate <size_t N> 96227825Stheravenbitset<N> operator|(const bitset<N>&, const bitset<N>&) noexcept; 97227825Stheraven 98227825Stheraventemplate <size_t N> 99227825Stheravenbitset<N> operator^(const bitset<N>&, const bitset<N>&) noexcept; 100227825Stheraven 101227825Stheraventemplate <class charT, class traits, size_t N> 102227825Stheravenbasic_istream<charT, traits>& 103227825Stheravenoperator>>(basic_istream<charT, traits>& is, bitset<N>& x); 104227825Stheraven 105227825Stheraventemplate <class charT, class traits, size_t N> 106227825Stheravenbasic_ostream<charT, traits>& 107227825Stheravenoperator<<(basic_ostream<charT, traits>& os, const bitset<N>& x); 108227825Stheraven 109227825Stheraventemplate <size_t N> struct hash<std::bitset<N>>; 110227825Stheraven 111227825Stheraven} // std 112227825Stheraven 113227825Stheraven*/ 114227825Stheraven 115227825Stheraven#include <__config> 116227825Stheraven#include <__bit_reference> 117227825Stheraven#include <cstddef> 118227825Stheraven#include <climits> 119227825Stheraven#include <string> 120227825Stheraven#include <stdexcept> 121227825Stheraven#include <iosfwd> 122227825Stheraven#include <__functional_base> 123227825Stheraven 124321369Sdim#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 125321369Sdim#pragma GCC system_header 126321369Sdim#endif 127232924Stheraven 128321369Sdim_LIBCPP_PUSH_MACROS 129321369Sdim#include <__undef_macros> 130321369Sdim 131321369Sdim 132227825Stheraven_LIBCPP_BEGIN_NAMESPACE_STD 133227825Stheraven 134227825Stheraventemplate <size_t _N_words, size_t _Size> 135227825Stheravenclass __bitset; 136227825Stheraven 137227825Stheraventemplate <size_t _N_words, size_t _Size> 138227825Stheravenstruct __has_storage_type<__bitset<_N_words, _Size> > 139227825Stheraven{ 140227825Stheraven static const bool value = true; 141227825Stheraven}; 142227825Stheraven 143227825Stheraventemplate <size_t _N_words, size_t _Size> 144227825Stheravenclass __bitset 145227825Stheraven{ 146227825Stheravenpublic: 147227825Stheraven typedef ptrdiff_t difference_type; 148227825Stheraven typedef size_t size_type; 149241900Sdim typedef size_type __storage_type; 150227825Stheravenprotected: 151227825Stheraven typedef __bitset __self; 152227825Stheraven typedef __storage_type* __storage_pointer; 153227825Stheraven typedef const __storage_type* __const_storage_pointer; 154227825Stheraven static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT); 155227825Stheraven 156227825Stheraven friend class __bit_reference<__bitset>; 157227825Stheraven friend class __bit_const_reference<__bitset>; 158227825Stheraven friend class __bit_iterator<__bitset, false>; 159227825Stheraven friend class __bit_iterator<__bitset, true>; 160241900Sdim friend struct __bit_array<__bitset>; 161227825Stheraven 162227825Stheraven __storage_type __first_[_N_words]; 163227825Stheraven 164227825Stheraven typedef __bit_reference<__bitset> reference; 165227825Stheraven typedef __bit_const_reference<__bitset> const_reference; 166227825Stheraven typedef __bit_iterator<__bitset, false> iterator; 167227825Stheraven typedef __bit_iterator<__bitset, true> const_iterator; 168227825Stheraven 169300770Sdim _LIBCPP_INLINE_VISIBILITY 170241900Sdim _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT; 171300770Sdim _LIBCPP_INLINE_VISIBILITY 172241900Sdim 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);} 176241900Sdim _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 183300770Sdim _LIBCPP_INLINE_VISIBILITY 184227825Stheraven void operator&=(const __bitset& __v) _NOEXCEPT; 185300770Sdim _LIBCPP_INLINE_VISIBILITY 186227825Stheraven void operator|=(const __bitset& __v) _NOEXCEPT; 187300770Sdim _LIBCPP_INLINE_VISIBILITY 188227825Stheraven void operator^=(const __bitset& __v) _NOEXCEPT; 189227825Stheraven 190227825Stheraven void flip() _NOEXCEPT; 191227825Stheraven _LIBCPP_INLINE_VISIBILITY unsigned long to_ulong() const 192227825Stheraven {return to_ulong(integral_constant<bool, _Size < sizeof(unsigned long) * CHAR_BIT>());} 193227825Stheraven _LIBCPP_INLINE_VISIBILITY unsigned long long to_ullong() const 194227825Stheraven {return to_ullong(integral_constant<bool, _Size < sizeof(unsigned long long) * CHAR_BIT>());} 195227825Stheraven 196227825Stheraven bool all() const _NOEXCEPT; 197227825Stheraven bool any() const _NOEXCEPT; 198300770Sdim _LIBCPP_INLINE_VISIBILITY 199227825Stheraven size_t __hash_code() const _NOEXCEPT; 200227825Stheravenprivate: 201321369Sdim#ifdef _LIBCPP_CXX03_LANG 202227825Stheraven void __init(unsigned long long __v, false_type) _NOEXCEPT; 203300770Sdim _LIBCPP_INLINE_VISIBILITY 204227825Stheraven void __init(unsigned long long __v, true_type) _NOEXCEPT; 205321369Sdim#endif // _LIBCPP_CXX03_LANG 206227825Stheraven unsigned long to_ulong(false_type) const; 207300770Sdim _LIBCPP_INLINE_VISIBILITY 208227825Stheraven unsigned long to_ulong(true_type) const; 209227825Stheraven unsigned long long to_ullong(false_type) const; 210300770Sdim _LIBCPP_INLINE_VISIBILITY 211227825Stheraven unsigned long long to_ullong(true_type) const; 212300770Sdim _LIBCPP_INLINE_VISIBILITY 213227825Stheraven unsigned long long to_ullong(true_type, false_type) const; 214227825Stheraven unsigned long long to_ullong(true_type, true_type) const; 215227825Stheraven}; 216227825Stheraven 217227825Stheraventemplate <size_t _N_words, size_t _Size> 218300770Sdiminline 219241900Sdim_LIBCPP_CONSTEXPR 220227825Stheraven__bitset<_N_words, _Size>::__bitset() _NOEXCEPT 221321369Sdim#ifndef _LIBCPP_CXX03_LANG 222241900Sdim : __first_{0} 223241900Sdim#endif 224227825Stheraven{ 225321369Sdim#ifdef _LIBCPP_CXX03_LANG 226227825Stheraven _VSTD::fill_n(__first_, _N_words, __storage_type(0)); 227241900Sdim#endif 228227825Stheraven} 229227825Stheraven 230321369Sdim#ifdef _LIBCPP_CXX03_LANG 231241900Sdim 232227825Stheraventemplate <size_t _N_words, size_t _Size> 233227825Stheravenvoid 234232924Stheraven__bitset<_N_words, _Size>::__init(unsigned long long __v, false_type) _NOEXCEPT 235227825Stheraven{ 236227825Stheraven __storage_type __t[sizeof(unsigned long long) / sizeof(__storage_type)]; 237327952Sdim size_t __sz = _Size; 238327952Sdim for (size_t __i = 0; __i < sizeof(__t)/sizeof(__t[0]); ++__i, __v >>= __bits_per_word, __sz -= __bits_per_word ) 239327952Sdim if ( __sz < __bits_per_word) 240344779Sdim __t[__i] = static_cast<__storage_type>(__v) & ( 1ULL << __sz ) - 1; 241327952Sdim else 242344779Sdim __t[__i] = static_cast<__storage_type>(__v); 243327952Sdim 244227825Stheraven _VSTD::copy(__t, __t + sizeof(__t)/sizeof(__t[0]), __first_); 245227825Stheraven _VSTD::fill(__first_ + sizeof(__t)/sizeof(__t[0]), __first_ + sizeof(__first_)/sizeof(__first_[0]), 246227825Stheraven __storage_type(0)); 247227825Stheraven} 248227825Stheraven 249227825Stheraventemplate <size_t _N_words, size_t _Size> 250227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 251227825Stheravenvoid 252232924Stheraven__bitset<_N_words, _Size>::__init(unsigned long long __v, true_type) _NOEXCEPT 253227825Stheraven{ 254227825Stheraven __first_[0] = __v; 255327952Sdim if (_Size < __bits_per_word) 256344779Sdim __first_[0] &= ( 1ULL << _Size ) - 1; 257327952Sdim 258227825Stheraven _VSTD::fill(__first_ + 1, __first_ + sizeof(__first_)/sizeof(__first_[0]), __storage_type(0)); 259227825Stheraven} 260227825Stheraven 261321369Sdim#endif // _LIBCPP_CXX03_LANG 262241900Sdim 263227825Stheraventemplate <size_t _N_words, size_t _Size> 264300770Sdiminline 265241900Sdim_LIBCPP_CONSTEXPR 266227825Stheraven__bitset<_N_words, _Size>::__bitset(unsigned long long __v) _NOEXCEPT 267321369Sdim#ifndef _LIBCPP_CXX03_LANG 268276792Sdim#if __SIZEOF_SIZE_T__ == 8 269241900Sdim : __first_{__v} 270276792Sdim#elif __SIZEOF_SIZE_T__ == 4 271344779Sdim : __first_{static_cast<__storage_type>(__v), 272344779Sdim _Size >= 2 * __bits_per_word ? static_cast<__storage_type>(__v >> __bits_per_word) 273344779Sdim : static_cast<__storage_type>((__v >> __bits_per_word) & (__storage_type(1) << (_Size - __bits_per_word)) - 1)} 274249989Sdim#else 275249989Sdim#error This constructor has not been ported to this platform 276241900Sdim#endif 277249989Sdim#endif 278227825Stheraven{ 279321369Sdim#ifdef _LIBCPP_CXX03_LANG 280227825Stheraven __init(__v, integral_constant<bool, sizeof(unsigned long long) == sizeof(__storage_type)>()); 281241900Sdim#endif 282227825Stheraven} 283227825Stheraven 284227825Stheraventemplate <size_t _N_words, size_t _Size> 285300770Sdiminline 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> 294300770Sdiminline 295227825Stheravenvoid 296227825Stheraven__bitset<_N_words, _Size>::operator|=(const __bitset& __v) _NOEXCEPT 297227825Stheraven{ 298227825Stheraven for (size_type __i = 0; __i < _N_words; ++__i) 299227825Stheraven __first_[__i] |= __v.__first_[__i]; 300227825Stheraven} 301227825Stheraven 302227825Stheraventemplate <size_t _N_words, size_t _Size> 303300770Sdiminline 304227825Stheravenvoid 305227825Stheraven__bitset<_N_words, _Size>::operator^=(const __bitset& __v) _NOEXCEPT 306227825Stheraven{ 307227825Stheraven for (size_type __i = 0; __i < _N_words; ++__i) 308227825Stheraven __first_[__i] ^= __v.__first_[__i]; 309227825Stheraven} 310227825Stheraven 311227825Stheraventemplate <size_t _N_words, size_t _Size> 312227825Stheravenvoid 313227825Stheraven__bitset<_N_words, _Size>::flip() _NOEXCEPT 314227825Stheraven{ 315227825Stheraven // do middle whole words 316227825Stheraven size_type __n = _Size; 317227825Stheraven __storage_pointer __p = __first_; 318227825Stheraven for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) 319227825Stheraven *__p = ~*__p; 320227825Stheraven // do last partial word 321227825Stheraven if (__n > 0) 322227825Stheraven { 323227825Stheraven __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); 324227825Stheraven __storage_type __b = *__p & __m; 325227825Stheraven *__p &= ~__m; 326227825Stheraven *__p |= ~__b & __m; 327227825Stheraven } 328227825Stheraven} 329227825Stheraven 330227825Stheraventemplate <size_t _N_words, size_t _Size> 331227825Stheravenunsigned long 332227825Stheraven__bitset<_N_words, _Size>::to_ulong(false_type) const 333227825Stheraven{ 334227825Stheraven const_iterator __e = __make_iter(_Size); 335227825Stheraven const_iterator __i = _VSTD::find(__make_iter(sizeof(unsigned long) * CHAR_BIT), __e, true); 336227825Stheraven if (__i != __e) 337314564Sdim __throw_overflow_error("bitset to_ulong overflow error"); 338314564Sdim 339227825Stheraven return __first_[0]; 340227825Stheraven} 341227825Stheraven 342227825Stheraventemplate <size_t _N_words, size_t _Size> 343300770Sdiminline 344227825Stheravenunsigned long 345227825Stheraven__bitset<_N_words, _Size>::to_ulong(true_type) const 346227825Stheraven{ 347227825Stheraven return __first_[0]; 348227825Stheraven} 349227825Stheraven 350227825Stheraventemplate <size_t _N_words, size_t _Size> 351227825Stheravenunsigned long long 352227825Stheraven__bitset<_N_words, _Size>::to_ullong(false_type) const 353227825Stheraven{ 354227825Stheraven const_iterator __e = __make_iter(_Size); 355227825Stheraven const_iterator __i = _VSTD::find(__make_iter(sizeof(unsigned long long) * CHAR_BIT), __e, true); 356227825Stheraven if (__i != __e) 357314564Sdim __throw_overflow_error("bitset to_ullong overflow error"); 358314564Sdim 359227825Stheraven return to_ullong(true_type()); 360227825Stheraven} 361227825Stheraven 362227825Stheraventemplate <size_t _N_words, size_t _Size> 363300770Sdiminline 364227825Stheravenunsigned long long 365227825Stheraven__bitset<_N_words, _Size>::to_ullong(true_type) const 366227825Stheraven{ 367227825Stheraven return to_ullong(true_type(), integral_constant<bool, sizeof(__storage_type) < sizeof(unsigned long long)>()); 368227825Stheraven} 369227825Stheraven 370227825Stheraventemplate <size_t _N_words, size_t _Size> 371300770Sdiminline 372227825Stheravenunsigned long long 373227825Stheraven__bitset<_N_words, _Size>::to_ullong(true_type, false_type) const 374227825Stheraven{ 375227825Stheraven return __first_[0]; 376227825Stheraven} 377227825Stheraven 378227825Stheraventemplate <size_t _N_words, size_t _Size> 379227825Stheravenunsigned long long 380227825Stheraven__bitset<_N_words, _Size>::to_ullong(true_type, true_type) const 381227825Stheraven{ 382227825Stheraven unsigned long long __r = __first_[0]; 383227825Stheraven for (std::size_t __i = 1; __i < sizeof(unsigned long long) / sizeof(__storage_type); ++__i) 384227825Stheraven __r |= static_cast<unsigned long long>(__first_[__i]) << (sizeof(__storage_type) * CHAR_BIT); 385227825Stheraven return __r; 386227825Stheraven} 387227825Stheraven 388227825Stheraventemplate <size_t _N_words, size_t _Size> 389227825Stheravenbool 390227825Stheraven__bitset<_N_words, _Size>::all() const _NOEXCEPT 391227825Stheraven{ 392227825Stheraven // do middle whole words 393227825Stheraven size_type __n = _Size; 394227825Stheraven __const_storage_pointer __p = __first_; 395227825Stheraven for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) 396227825Stheraven if (~*__p) 397227825Stheraven return false; 398227825Stheraven // do last partial word 399227825Stheraven if (__n > 0) 400227825Stheraven { 401227825Stheraven __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); 402227825Stheraven if (~*__p & __m) 403227825Stheraven return false; 404227825Stheraven } 405227825Stheraven return true; 406227825Stheraven} 407227825Stheraven 408227825Stheraventemplate <size_t _N_words, size_t _Size> 409227825Stheravenbool 410227825Stheraven__bitset<_N_words, _Size>::any() const _NOEXCEPT 411227825Stheraven{ 412227825Stheraven // do middle whole words 413227825Stheraven size_type __n = _Size; 414227825Stheraven __const_storage_pointer __p = __first_; 415227825Stheraven for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) 416227825Stheraven if (*__p) 417227825Stheraven return true; 418227825Stheraven // do last partial word 419227825Stheraven if (__n > 0) 420227825Stheraven { 421227825Stheraven __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); 422227825Stheraven if (*__p & __m) 423227825Stheraven return true; 424227825Stheraven } 425227825Stheraven return false; 426227825Stheraven} 427227825Stheraven 428227825Stheraventemplate <size_t _N_words, size_t _Size> 429300770Sdiminline 430227825Stheravensize_t 431227825Stheraven__bitset<_N_words, _Size>::__hash_code() const _NOEXCEPT 432227825Stheraven{ 433227825Stheraven size_t __h = 0; 434227825Stheraven for (size_type __i = 0; __i < _N_words; ++__i) 435227825Stheraven __h ^= __first_[__i]; 436227825Stheraven return __h; 437227825Stheraven} 438227825Stheraven 439227825Stheraventemplate <size_t _Size> 440227825Stheravenclass __bitset<1, _Size> 441227825Stheraven{ 442227825Stheravenpublic: 443227825Stheraven typedef ptrdiff_t difference_type; 444227825Stheraven typedef size_t size_type; 445241900Sdim typedef size_type __storage_type; 446227825Stheravenprotected: 447227825Stheraven typedef __bitset __self; 448227825Stheraven typedef __storage_type* __storage_pointer; 449227825Stheraven typedef const __storage_type* __const_storage_pointer; 450227825Stheraven static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT); 451227825Stheraven 452227825Stheraven friend class __bit_reference<__bitset>; 453227825Stheraven friend class __bit_const_reference<__bitset>; 454227825Stheraven friend class __bit_iterator<__bitset, false>; 455227825Stheraven friend class __bit_iterator<__bitset, true>; 456241900Sdim friend struct __bit_array<__bitset>; 457227825Stheraven 458227825Stheraven __storage_type __first_; 459227825Stheraven 460227825Stheraven typedef __bit_reference<__bitset> reference; 461227825Stheraven typedef __bit_const_reference<__bitset> const_reference; 462227825Stheraven typedef __bit_iterator<__bitset, false> iterator; 463227825Stheraven typedef __bit_iterator<__bitset, true> const_iterator; 464227825Stheraven 465300770Sdim _LIBCPP_INLINE_VISIBILITY 466241900Sdim _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT; 467300770Sdim _LIBCPP_INLINE_VISIBILITY 468241900Sdim explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT; 469227825Stheraven 470227825Stheraven _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t __pos) _NOEXCEPT 471227825Stheraven {return reference(&__first_, __storage_type(1) << __pos);} 472241900Sdim _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT 473227825Stheraven {return const_reference(&__first_, __storage_type(1) << __pos);} 474227825Stheraven _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t __pos) _NOEXCEPT 475227825Stheraven {return iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);} 476227825Stheraven _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t __pos) const _NOEXCEPT 477227825Stheraven {return const_iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);} 478227825Stheraven 479300770Sdim _LIBCPP_INLINE_VISIBILITY 480227825Stheraven void operator&=(const __bitset& __v) _NOEXCEPT; 481300770Sdim _LIBCPP_INLINE_VISIBILITY 482227825Stheraven void operator|=(const __bitset& __v) _NOEXCEPT; 483300770Sdim _LIBCPP_INLINE_VISIBILITY 484227825Stheraven void operator^=(const __bitset& __v) _NOEXCEPT; 485227825Stheraven 486300770Sdim _LIBCPP_INLINE_VISIBILITY 487227825Stheraven void flip() _NOEXCEPT; 488227825Stheraven 489300770Sdim _LIBCPP_INLINE_VISIBILITY 490227825Stheraven unsigned long to_ulong() const; 491300770Sdim _LIBCPP_INLINE_VISIBILITY 492227825Stheraven unsigned long long to_ullong() const; 493227825Stheraven 494300770Sdim _LIBCPP_INLINE_VISIBILITY 495227825Stheraven bool all() const _NOEXCEPT; 496300770Sdim _LIBCPP_INLINE_VISIBILITY 497227825Stheraven bool any() const _NOEXCEPT; 498227825Stheraven 499300770Sdim _LIBCPP_INLINE_VISIBILITY 500227825Stheraven size_t __hash_code() const _NOEXCEPT; 501227825Stheraven}; 502227825Stheraven 503227825Stheraventemplate <size_t _Size> 504300770Sdiminline 505241900Sdim_LIBCPP_CONSTEXPR 506227825Stheraven__bitset<1, _Size>::__bitset() _NOEXCEPT 507227825Stheraven : __first_(0) 508227825Stheraven{ 509227825Stheraven} 510227825Stheraven 511227825Stheraventemplate <size_t _Size> 512300770Sdiminline 513241900Sdim_LIBCPP_CONSTEXPR 514227825Stheraven__bitset<1, _Size>::__bitset(unsigned long long __v) _NOEXCEPT 515327952Sdim : __first_( 516327952Sdim _Size == __bits_per_word ? static_cast<__storage_type>(__v) 517327952Sdim : static_cast<__storage_type>(__v) & ((__storage_type(1) << _Size) - 1) 518327952Sdim ) 519227825Stheraven{ 520227825Stheraven} 521227825Stheraven 522227825Stheraventemplate <size_t _Size> 523300770Sdiminline 524227825Stheravenvoid 525227825Stheraven__bitset<1, _Size>::operator&=(const __bitset& __v) _NOEXCEPT 526227825Stheraven{ 527227825Stheraven __first_ &= __v.__first_; 528227825Stheraven} 529227825Stheraven 530227825Stheraventemplate <size_t _Size> 531300770Sdiminline 532227825Stheravenvoid 533227825Stheraven__bitset<1, _Size>::operator|=(const __bitset& __v) _NOEXCEPT 534227825Stheraven{ 535227825Stheraven __first_ |= __v.__first_; 536227825Stheraven} 537227825Stheraven 538227825Stheraventemplate <size_t _Size> 539300770Sdiminline 540227825Stheravenvoid 541227825Stheraven__bitset<1, _Size>::operator^=(const __bitset& __v) _NOEXCEPT 542227825Stheraven{ 543227825Stheraven __first_ ^= __v.__first_; 544227825Stheraven} 545227825Stheraven 546227825Stheraventemplate <size_t _Size> 547300770Sdiminline 548227825Stheravenvoid 549227825Stheraven__bitset<1, _Size>::flip() _NOEXCEPT 550227825Stheraven{ 551227825Stheraven __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size); 552227825Stheraven __first_ = ~__first_; 553227825Stheraven __first_ &= __m; 554227825Stheraven} 555227825Stheraven 556227825Stheraventemplate <size_t _Size> 557300770Sdiminline 558227825Stheravenunsigned long 559227825Stheraven__bitset<1, _Size>::to_ulong() const 560227825Stheraven{ 561227825Stheraven return __first_; 562227825Stheraven} 563227825Stheraven 564227825Stheraventemplate <size_t _Size> 565300770Sdiminline 566227825Stheravenunsigned long long 567227825Stheraven__bitset<1, _Size>::to_ullong() const 568227825Stheraven{ 569227825Stheraven return __first_; 570227825Stheraven} 571227825Stheraven 572227825Stheraventemplate <size_t _Size> 573300770Sdiminline 574227825Stheravenbool 575227825Stheraven__bitset<1, _Size>::all() const _NOEXCEPT 576227825Stheraven{ 577227825Stheraven __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size); 578227825Stheraven return !(~__first_ & __m); 579227825Stheraven} 580227825Stheraven 581227825Stheraventemplate <size_t _Size> 582300770Sdiminline 583227825Stheravenbool 584227825Stheraven__bitset<1, _Size>::any() const _NOEXCEPT 585227825Stheraven{ 586227825Stheraven __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size); 587227825Stheraven return __first_ & __m; 588227825Stheraven} 589227825Stheraven 590227825Stheraventemplate <size_t _Size> 591300770Sdiminline 592227825Stheravensize_t 593227825Stheraven__bitset<1, _Size>::__hash_code() const _NOEXCEPT 594227825Stheraven{ 595227825Stheraven return __first_; 596227825Stheraven} 597227825Stheraven 598227825Stheraventemplate <> 599227825Stheravenclass __bitset<0, 0> 600227825Stheraven{ 601227825Stheravenpublic: 602227825Stheraven typedef ptrdiff_t difference_type; 603227825Stheraven typedef size_t size_type; 604241900Sdim typedef size_type __storage_type; 605227825Stheravenprotected: 606227825Stheraven typedef __bitset __self; 607227825Stheraven typedef __storage_type* __storage_pointer; 608227825Stheraven typedef const __storage_type* __const_storage_pointer; 609227825Stheraven static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT); 610227825Stheraven 611227825Stheraven friend class __bit_reference<__bitset>; 612227825Stheraven friend class __bit_const_reference<__bitset>; 613227825Stheraven friend class __bit_iterator<__bitset, false>; 614227825Stheraven friend class __bit_iterator<__bitset, true>; 615232924Stheraven friend struct __bit_array<__bitset>; 616227825Stheraven 617227825Stheraven typedef __bit_reference<__bitset> reference; 618227825Stheraven typedef __bit_const_reference<__bitset> const_reference; 619227825Stheraven typedef __bit_iterator<__bitset, false> iterator; 620227825Stheraven typedef __bit_iterator<__bitset, true> const_iterator; 621227825Stheraven 622300770Sdim _LIBCPP_INLINE_VISIBILITY 623241900Sdim _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT; 624300770Sdim _LIBCPP_INLINE_VISIBILITY 625241900Sdim explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long) _NOEXCEPT; 626227825Stheraven 627227825Stheraven _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t) _NOEXCEPT 628227825Stheraven {return reference(0, 1);} 629241900Sdim _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t) const _NOEXCEPT 630227825Stheraven {return const_reference(0, 1);} 631232924Stheraven _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t) _NOEXCEPT 632227825Stheraven {return iterator(0, 0);} 633232924Stheraven _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t) const _NOEXCEPT 634227825Stheraven {return const_iterator(0, 0);} 635227825Stheraven 636227825Stheraven _LIBCPP_INLINE_VISIBILITY void operator&=(const __bitset&) _NOEXCEPT {} 637227825Stheraven _LIBCPP_INLINE_VISIBILITY void operator|=(const __bitset&) _NOEXCEPT {} 638227825Stheraven _LIBCPP_INLINE_VISIBILITY void operator^=(const __bitset&) _NOEXCEPT {} 639227825Stheraven 640227825Stheraven _LIBCPP_INLINE_VISIBILITY void flip() _NOEXCEPT {} 641227825Stheraven 642227825Stheraven _LIBCPP_INLINE_VISIBILITY unsigned long to_ulong() const {return 0;} 643227825Stheraven _LIBCPP_INLINE_VISIBILITY unsigned long long to_ullong() const {return 0;} 644227825Stheraven 645227825Stheraven _LIBCPP_INLINE_VISIBILITY bool all() const _NOEXCEPT {return true;} 646227825Stheraven _LIBCPP_INLINE_VISIBILITY bool any() const _NOEXCEPT {return false;} 647227825Stheraven 648227825Stheraven _LIBCPP_INLINE_VISIBILITY size_t __hash_code() const _NOEXCEPT {return 0;} 649227825Stheraven}; 650227825Stheraven 651300770Sdiminline 652241900Sdim_LIBCPP_CONSTEXPR 653227825Stheraven__bitset<0, 0>::__bitset() _NOEXCEPT 654227825Stheraven{ 655227825Stheraven} 656227825Stheraven 657300770Sdiminline 658241900Sdim_LIBCPP_CONSTEXPR 659227825Stheraven__bitset<0, 0>::__bitset(unsigned long long) _NOEXCEPT 660227825Stheraven{ 661227825Stheraven} 662227825Stheraven 663314564Sdimtemplate <size_t _Size> class _LIBCPP_TEMPLATE_VIS bitset; 664309124Sdimtemplate <size_t _Size> struct hash<bitset<_Size> >; 665227825Stheraven 666227825Stheraventemplate <size_t _Size> 667314564Sdimclass _LIBCPP_TEMPLATE_VIS bitset 668227825Stheraven : private __bitset<_Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1, _Size> 669227825Stheraven{ 670249989Sdimpublic: 671227825Stheraven static const unsigned __n_words = _Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1; 672227825Stheraven typedef __bitset<__n_words, _Size> base; 673227825Stheraven 674227825Stheravenpublic: 675227825Stheraven typedef typename base::reference reference; 676227825Stheraven typedef typename base::const_reference const_reference; 677227825Stheraven 678227825Stheraven // 23.3.5.1 constructors: 679241900Sdim _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bitset() _NOEXCEPT {} 680241900Sdim _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 681241900Sdim bitset(unsigned long long __v) _NOEXCEPT : base(__v) {} 682353358Sdim template<class _CharT, class = _EnableIf<_IsCharLikeType<_CharT>::value> > 683227825Stheraven explicit bitset(const _CharT* __str, 684227825Stheraven typename basic_string<_CharT>::size_type __n = basic_string<_CharT>::npos, 685227825Stheraven _CharT __zero = _CharT('0'), _CharT __one = _CharT('1')); 686227825Stheraven template<class _CharT, class _Traits, class _Allocator> 687227825Stheraven explicit bitset(const basic_string<_CharT,_Traits,_Allocator>& __str, 688227825Stheraven typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos = 0, 689227825Stheraven typename basic_string<_CharT,_Traits,_Allocator>::size_type __n = 690227825Stheraven (basic_string<_CharT,_Traits,_Allocator>::npos), 691227825Stheraven _CharT __zero = _CharT('0'), _CharT __one = _CharT('1')); 692227825Stheraven 693227825Stheraven // 23.3.5.2 bitset operations: 694300770Sdim _LIBCPP_INLINE_VISIBILITY 695227825Stheraven bitset& operator&=(const bitset& __rhs) _NOEXCEPT; 696300770Sdim _LIBCPP_INLINE_VISIBILITY 697227825Stheraven bitset& operator|=(const bitset& __rhs) _NOEXCEPT; 698300770Sdim _LIBCPP_INLINE_VISIBILITY 699227825Stheraven bitset& operator^=(const bitset& __rhs) _NOEXCEPT; 700227825Stheraven bitset& operator<<=(size_t __pos) _NOEXCEPT; 701227825Stheraven bitset& operator>>=(size_t __pos) _NOEXCEPT; 702300770Sdim _LIBCPP_INLINE_VISIBILITY 703227825Stheraven bitset& set() _NOEXCEPT; 704227825Stheraven bitset& set(size_t __pos, bool __val = true); 705300770Sdim _LIBCPP_INLINE_VISIBILITY 706227825Stheraven bitset& reset() _NOEXCEPT; 707227825Stheraven bitset& reset(size_t __pos); 708300770Sdim _LIBCPP_INLINE_VISIBILITY 709227825Stheraven bitset operator~() const _NOEXCEPT; 710300770Sdim _LIBCPP_INLINE_VISIBILITY 711227825Stheraven bitset& flip() _NOEXCEPT; 712227825Stheraven bitset& flip(size_t __pos); 713227825Stheraven 714227825Stheraven // element access: 715241900Sdim _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 716241900Sdim const_reference operator[](size_t __p) const {return base::__make_ref(__p);} 717227825Stheraven _LIBCPP_INLINE_VISIBILITY reference operator[](size_t __p) {return base::__make_ref(__p);} 718300770Sdim _LIBCPP_INLINE_VISIBILITY 719227825Stheraven unsigned long to_ulong() const; 720300770Sdim _LIBCPP_INLINE_VISIBILITY 721227825Stheraven unsigned long long to_ullong() const; 722227825Stheraven template <class _CharT, class _Traits, class _Allocator> 723227825Stheraven basic_string<_CharT, _Traits, _Allocator> to_string(_CharT __zero = _CharT('0'), 724227825Stheraven _CharT __one = _CharT('1')) const; 725227825Stheraven template <class _CharT, class _Traits> 726300770Sdim _LIBCPP_INLINE_VISIBILITY 727227825Stheraven basic_string<_CharT, _Traits, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'), 728227825Stheraven _CharT __one = _CharT('1')) const; 729227825Stheraven template <class _CharT> 730300770Sdim _LIBCPP_INLINE_VISIBILITY 731227825Stheraven basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'), 732227825Stheraven _CharT __one = _CharT('1')) const; 733300770Sdim _LIBCPP_INLINE_VISIBILITY 734227825Stheraven basic_string<char, char_traits<char>, allocator<char> > to_string(char __zero = '0', 735227825Stheraven char __one = '1') const; 736300770Sdim _LIBCPP_INLINE_VISIBILITY 737227825Stheraven size_t count() const _NOEXCEPT; 738241900Sdim _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR size_t size() const _NOEXCEPT {return _Size;} 739300770Sdim _LIBCPP_INLINE_VISIBILITY 740227825Stheraven bool operator==(const bitset& __rhs) const _NOEXCEPT; 741300770Sdim _LIBCPP_INLINE_VISIBILITY 742227825Stheraven bool operator!=(const bitset& __rhs) const _NOEXCEPT; 743227825Stheraven bool test(size_t __pos) const; 744300770Sdim _LIBCPP_INLINE_VISIBILITY 745227825Stheraven bool all() const _NOEXCEPT; 746300770Sdim _LIBCPP_INLINE_VISIBILITY 747227825Stheraven bool any() const _NOEXCEPT; 748227825Stheraven _LIBCPP_INLINE_VISIBILITY bool none() const _NOEXCEPT {return !any();} 749300770Sdim _LIBCPP_INLINE_VISIBILITY 750227825Stheraven bitset operator<<(size_t __pos) const _NOEXCEPT; 751300770Sdim _LIBCPP_INLINE_VISIBILITY 752227825Stheraven bitset operator>>(size_t __pos) const _NOEXCEPT; 753227825Stheraven 754227825Stheravenprivate: 755227825Stheraven 756227825Stheraven _LIBCPP_INLINE_VISIBILITY 757227825Stheraven size_t __hash_code() const _NOEXCEPT {return base::__hash_code();} 758227825Stheraven 759227825Stheraven friend struct hash<bitset>; 760227825Stheraven}; 761227825Stheraven 762227825Stheraventemplate <size_t _Size> 763353358Sdimtemplate<class _CharT, class> 764227825Stheravenbitset<_Size>::bitset(const _CharT* __str, 765227825Stheraven typename basic_string<_CharT>::size_type __n, 766227825Stheraven _CharT __zero, _CharT __one) 767227825Stheraven{ 768227825Stheraven size_t __rlen = _VSTD::min(__n, char_traits<_CharT>::length(__str)); 769227825Stheraven for (size_t __i = 0; __i < __rlen; ++__i) 770227825Stheraven if (__str[__i] != __zero && __str[__i] != __one) 771314564Sdim __throw_invalid_argument("bitset string ctor has invalid argument"); 772314564Sdim 773232924Stheraven size_t _Mp = _VSTD::min(__rlen, _Size); 774227825Stheraven size_t __i = 0; 775232924Stheraven for (; __i < _Mp; ++__i) 776227825Stheraven { 777232924Stheraven _CharT __c = __str[_Mp - 1 - __i]; 778227825Stheraven if (__c == __zero) 779227825Stheraven (*this)[__i] = false; 780227825Stheraven else 781227825Stheraven (*this)[__i] = true; 782227825Stheraven } 783227825Stheraven _VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false); 784227825Stheraven} 785227825Stheraven 786227825Stheraventemplate <size_t _Size> 787227825Stheraventemplate<class _CharT, class _Traits, class _Allocator> 788227825Stheravenbitset<_Size>::bitset(const basic_string<_CharT,_Traits,_Allocator>& __str, 789227825Stheraven typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos, 790227825Stheraven typename basic_string<_CharT,_Traits,_Allocator>::size_type __n, 791227825Stheraven _CharT __zero, _CharT __one) 792227825Stheraven{ 793227825Stheraven if (__pos > __str.size()) 794314564Sdim __throw_out_of_range("bitset string pos out of range"); 795314564Sdim 796227825Stheraven size_t __rlen = _VSTD::min(__n, __str.size() - __pos); 797227825Stheraven for (size_t __i = __pos; __i < __pos + __rlen; ++__i) 798227825Stheraven if (!_Traits::eq(__str[__i], __zero) && !_Traits::eq(__str[__i], __one)) 799314564Sdim __throw_invalid_argument("bitset string ctor has invalid argument"); 800314564Sdim 801232924Stheraven size_t _Mp = _VSTD::min(__rlen, _Size); 802227825Stheraven size_t __i = 0; 803232924Stheraven for (; __i < _Mp; ++__i) 804227825Stheraven { 805232924Stheraven _CharT __c = __str[__pos + _Mp - 1 - __i]; 806227825Stheraven if (_Traits::eq(__c, __zero)) 807227825Stheraven (*this)[__i] = false; 808227825Stheraven else 809227825Stheraven (*this)[__i] = true; 810227825Stheraven } 811227825Stheraven _VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false); 812227825Stheraven} 813227825Stheraven 814227825Stheraventemplate <size_t _Size> 815300770Sdiminline 816227825Stheravenbitset<_Size>& 817227825Stheravenbitset<_Size>::operator&=(const bitset& __rhs) _NOEXCEPT 818227825Stheraven{ 819227825Stheraven base::operator&=(__rhs); 820227825Stheraven return *this; 821227825Stheraven} 822227825Stheraven 823227825Stheraventemplate <size_t _Size> 824300770Sdiminline 825227825Stheravenbitset<_Size>& 826227825Stheravenbitset<_Size>::operator|=(const bitset& __rhs) _NOEXCEPT 827227825Stheraven{ 828227825Stheraven base::operator|=(__rhs); 829227825Stheraven return *this; 830227825Stheraven} 831227825Stheraven 832227825Stheraventemplate <size_t _Size> 833300770Sdiminline 834227825Stheravenbitset<_Size>& 835227825Stheravenbitset<_Size>::operator^=(const bitset& __rhs) _NOEXCEPT 836227825Stheraven{ 837227825Stheraven base::operator^=(__rhs); 838227825Stheraven return *this; 839227825Stheraven} 840227825Stheraven 841227825Stheraventemplate <size_t _Size> 842227825Stheravenbitset<_Size>& 843227825Stheravenbitset<_Size>::operator<<=(size_t __pos) _NOEXCEPT 844227825Stheraven{ 845227825Stheraven __pos = _VSTD::min(__pos, _Size); 846227825Stheraven _VSTD::copy_backward(base::__make_iter(0), base::__make_iter(_Size - __pos), base::__make_iter(_Size)); 847227825Stheraven _VSTD::fill_n(base::__make_iter(0), __pos, false); 848227825Stheraven return *this; 849227825Stheraven} 850227825Stheraven 851227825Stheraventemplate <size_t _Size> 852227825Stheravenbitset<_Size>& 853227825Stheravenbitset<_Size>::operator>>=(size_t __pos) _NOEXCEPT 854227825Stheraven{ 855227825Stheraven __pos = _VSTD::min(__pos, _Size); 856227825Stheraven _VSTD::copy(base::__make_iter(__pos), base::__make_iter(_Size), base::__make_iter(0)); 857227825Stheraven _VSTD::fill_n(base::__make_iter(_Size - __pos), __pos, false); 858227825Stheraven return *this; 859227825Stheraven} 860227825Stheraven 861227825Stheraventemplate <size_t _Size> 862300770Sdiminline 863227825Stheravenbitset<_Size>& 864227825Stheravenbitset<_Size>::set() _NOEXCEPT 865227825Stheraven{ 866227825Stheraven _VSTD::fill_n(base::__make_iter(0), _Size, true); 867227825Stheraven return *this; 868227825Stheraven} 869227825Stheraven 870227825Stheraventemplate <size_t _Size> 871227825Stheravenbitset<_Size>& 872227825Stheravenbitset<_Size>::set(size_t __pos, bool __val) 873227825Stheraven{ 874227825Stheraven if (__pos >= _Size) 875314564Sdim __throw_out_of_range("bitset set argument out of range"); 876314564Sdim 877227825Stheraven (*this)[__pos] = __val; 878227825Stheraven return *this; 879227825Stheraven} 880227825Stheraven 881227825Stheraventemplate <size_t _Size> 882300770Sdiminline 883227825Stheravenbitset<_Size>& 884227825Stheravenbitset<_Size>::reset() _NOEXCEPT 885227825Stheraven{ 886227825Stheraven _VSTD::fill_n(base::__make_iter(0), _Size, false); 887227825Stheraven return *this; 888227825Stheraven} 889227825Stheraven 890227825Stheraventemplate <size_t _Size> 891227825Stheravenbitset<_Size>& 892227825Stheravenbitset<_Size>::reset(size_t __pos) 893227825Stheraven{ 894227825Stheraven if (__pos >= _Size) 895314564Sdim __throw_out_of_range("bitset reset argument out of range"); 896314564Sdim 897227825Stheraven (*this)[__pos] = false; 898227825Stheraven return *this; 899227825Stheraven} 900227825Stheraven 901227825Stheraventemplate <size_t _Size> 902300770Sdiminline 903227825Stheravenbitset<_Size> 904227825Stheravenbitset<_Size>::operator~() const _NOEXCEPT 905227825Stheraven{ 906227825Stheraven bitset __x(*this); 907227825Stheraven __x.flip(); 908227825Stheraven return __x; 909227825Stheraven} 910227825Stheraven 911227825Stheraventemplate <size_t _Size> 912300770Sdiminline 913227825Stheravenbitset<_Size>& 914227825Stheravenbitset<_Size>::flip() _NOEXCEPT 915227825Stheraven{ 916227825Stheraven base::flip(); 917227825Stheraven return *this; 918227825Stheraven} 919227825Stheraven 920227825Stheraventemplate <size_t _Size> 921227825Stheravenbitset<_Size>& 922227825Stheravenbitset<_Size>::flip(size_t __pos) 923227825Stheraven{ 924227825Stheraven if (__pos >= _Size) 925314564Sdim __throw_out_of_range("bitset flip argument out of range"); 926314564Sdim 927227825Stheraven reference r = base::__make_ref(__pos); 928227825Stheraven r = ~r; 929227825Stheraven return *this; 930227825Stheraven} 931227825Stheraven 932227825Stheraventemplate <size_t _Size> 933300770Sdiminline 934227825Stheravenunsigned long 935227825Stheravenbitset<_Size>::to_ulong() const 936227825Stheraven{ 937227825Stheraven return base::to_ulong(); 938227825Stheraven} 939227825Stheraven 940227825Stheraventemplate <size_t _Size> 941300770Sdiminline 942227825Stheravenunsigned long long 943227825Stheravenbitset<_Size>::to_ullong() const 944227825Stheraven{ 945227825Stheraven return base::to_ullong(); 946227825Stheraven} 947227825Stheraven 948227825Stheraventemplate <size_t _Size> 949227825Stheraventemplate <class _CharT, class _Traits, class _Allocator> 950227825Stheravenbasic_string<_CharT, _Traits, _Allocator> 951227825Stheravenbitset<_Size>::to_string(_CharT __zero, _CharT __one) const 952227825Stheraven{ 953227825Stheraven basic_string<_CharT, _Traits, _Allocator> __r(_Size, __zero); 954227825Stheraven for (size_t __i = 0; __i < _Size; ++__i) 955227825Stheraven { 956227825Stheraven if ((*this)[__i]) 957227825Stheraven __r[_Size - 1 - __i] = __one; 958227825Stheraven } 959227825Stheraven return __r; 960227825Stheraven} 961227825Stheraven 962227825Stheraventemplate <size_t _Size> 963227825Stheraventemplate <class _CharT, class _Traits> 964300770Sdiminline 965227825Stheravenbasic_string<_CharT, _Traits, allocator<_CharT> > 966227825Stheravenbitset<_Size>::to_string(_CharT __zero, _CharT __one) const 967227825Stheraven{ 968227825Stheraven return to_string<_CharT, _Traits, allocator<_CharT> >(__zero, __one); 969227825Stheraven} 970227825Stheraven 971227825Stheraventemplate <size_t _Size> 972227825Stheraventemplate <class _CharT> 973300770Sdiminline 974227825Stheravenbasic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > 975227825Stheravenbitset<_Size>::to_string(_CharT __zero, _CharT __one) const 976227825Stheraven{ 977227825Stheraven return to_string<_CharT, char_traits<_CharT>, allocator<_CharT> >(__zero, __one); 978227825Stheraven} 979227825Stheraven 980227825Stheraventemplate <size_t _Size> 981300770Sdiminline 982227825Stheravenbasic_string<char, char_traits<char>, allocator<char> > 983227825Stheravenbitset<_Size>::to_string(char __zero, char __one) const 984227825Stheraven{ 985227825Stheraven return to_string<char, char_traits<char>, allocator<char> >(__zero, __one); 986227825Stheraven} 987227825Stheraven 988227825Stheraventemplate <size_t _Size> 989300770Sdiminline 990227825Stheravensize_t 991227825Stheravenbitset<_Size>::count() const _NOEXCEPT 992227825Stheraven{ 993344779Sdim return static_cast<size_t>(__count_bool_true(base::__make_iter(0), _Size)); 994227825Stheraven} 995227825Stheraven 996227825Stheraventemplate <size_t _Size> 997300770Sdiminline 998227825Stheravenbool 999227825Stheravenbitset<_Size>::operator==(const bitset& __rhs) const _NOEXCEPT 1000227825Stheraven{ 1001227825Stheraven return _VSTD::equal(base::__make_iter(0), base::__make_iter(_Size), __rhs.__make_iter(0)); 1002227825Stheraven} 1003227825Stheraven 1004227825Stheraventemplate <size_t _Size> 1005300770Sdiminline 1006227825Stheravenbool 1007227825Stheravenbitset<_Size>::operator!=(const bitset& __rhs) const _NOEXCEPT 1008227825Stheraven{ 1009227825Stheraven return !(*this == __rhs); 1010227825Stheraven} 1011227825Stheraven 1012227825Stheraventemplate <size_t _Size> 1013227825Stheravenbool 1014227825Stheravenbitset<_Size>::test(size_t __pos) const 1015227825Stheraven{ 1016227825Stheraven if (__pos >= _Size) 1017314564Sdim __throw_out_of_range("bitset test argument out of range"); 1018314564Sdim 1019227825Stheraven return (*this)[__pos]; 1020227825Stheraven} 1021227825Stheraven 1022227825Stheraventemplate <size_t _Size> 1023300770Sdiminline 1024227825Stheravenbool 1025227825Stheravenbitset<_Size>::all() const _NOEXCEPT 1026227825Stheraven{ 1027227825Stheraven return base::all(); 1028227825Stheraven} 1029227825Stheraven 1030227825Stheraventemplate <size_t _Size> 1031300770Sdiminline 1032227825Stheravenbool 1033227825Stheravenbitset<_Size>::any() const _NOEXCEPT 1034227825Stheraven{ 1035227825Stheraven return base::any(); 1036227825Stheraven} 1037227825Stheraven 1038227825Stheraventemplate <size_t _Size> 1039300770Sdiminline 1040227825Stheravenbitset<_Size> 1041227825Stheravenbitset<_Size>::operator<<(size_t __pos) const _NOEXCEPT 1042227825Stheraven{ 1043227825Stheraven bitset __r = *this; 1044227825Stheraven __r <<= __pos; 1045227825Stheraven return __r; 1046227825Stheraven} 1047227825Stheraven 1048227825Stheraventemplate <size_t _Size> 1049300770Sdiminline 1050227825Stheravenbitset<_Size> 1051227825Stheravenbitset<_Size>::operator>>(size_t __pos) const _NOEXCEPT 1052227825Stheraven{ 1053227825Stheraven bitset __r = *this; 1054227825Stheraven __r >>= __pos; 1055227825Stheraven return __r; 1056227825Stheraven} 1057227825Stheraven 1058227825Stheraventemplate <size_t _Size> 1059227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 1060227825Stheravenbitset<_Size> 1061227825Stheravenoperator&(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT 1062227825Stheraven{ 1063227825Stheraven bitset<_Size> __r = __x; 1064227825Stheraven __r &= __y; 1065227825Stheraven return __r; 1066227825Stheraven} 1067227825Stheraven 1068227825Stheraventemplate <size_t _Size> 1069227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 1070227825Stheravenbitset<_Size> 1071227825Stheravenoperator|(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT 1072227825Stheraven{ 1073227825Stheraven bitset<_Size> __r = __x; 1074227825Stheraven __r |= __y; 1075227825Stheraven return __r; 1076227825Stheraven} 1077227825Stheraven 1078227825Stheraventemplate <size_t _Size> 1079227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 1080227825Stheravenbitset<_Size> 1081227825Stheravenoperator^(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT 1082227825Stheraven{ 1083227825Stheraven bitset<_Size> __r = __x; 1084227825Stheraven __r ^= __y; 1085227825Stheraven return __r; 1086227825Stheraven} 1087227825Stheraven 1088227825Stheraventemplate <size_t _Size> 1089314564Sdimstruct _LIBCPP_TEMPLATE_VIS hash<bitset<_Size> > 1090227825Stheraven : public unary_function<bitset<_Size>, size_t> 1091227825Stheraven{ 1092227825Stheraven _LIBCPP_INLINE_VISIBILITY 1093227825Stheraven size_t operator()(const bitset<_Size>& __bs) const _NOEXCEPT 1094227825Stheraven {return __bs.__hash_code();} 1095227825Stheraven}; 1096227825Stheraven 1097227825Stheraventemplate <class _CharT, class _Traits, size_t _Size> 1098227825Stheravenbasic_istream<_CharT, _Traits>& 1099227825Stheravenoperator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x); 1100227825Stheraven 1101227825Stheraventemplate <class _CharT, class _Traits, size_t _Size> 1102227825Stheravenbasic_ostream<_CharT, _Traits>& 1103227825Stheravenoperator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x); 1104227825Stheraven 1105227825Stheraven_LIBCPP_END_NAMESPACE_STD 1106227825Stheraven 1107321369Sdim_LIBCPP_POP_MACROS 1108321369Sdim 1109227825Stheraven#endif // _LIBCPP_BITSET 1110