1*0b57cec5SDimitry Andric// -*- C++ -*- 2*0b57cec5SDimitry Andric//===---------------------------- bitset ----------------------------------===// 3*0b57cec5SDimitry Andric// 4*0b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5*0b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information. 6*0b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7*0b57cec5SDimitry Andric// 8*0b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 9*0b57cec5SDimitry Andric 10*0b57cec5SDimitry Andric#ifndef _LIBCPP_BITSET 11*0b57cec5SDimitry Andric#define _LIBCPP_BITSET 12*0b57cec5SDimitry Andric 13*0b57cec5SDimitry Andric/* 14*0b57cec5SDimitry Andric bitset synopsis 15*0b57cec5SDimitry Andric 16*0b57cec5SDimitry Andricnamespace std 17*0b57cec5SDimitry Andric{ 18*0b57cec5SDimitry Andric 19*0b57cec5SDimitry Andricnamespace std { 20*0b57cec5SDimitry Andric 21*0b57cec5SDimitry Andrictemplate <size_t N> 22*0b57cec5SDimitry Andricclass bitset 23*0b57cec5SDimitry Andric{ 24*0b57cec5SDimitry Andricpublic: 25*0b57cec5SDimitry Andric // bit reference: 26*0b57cec5SDimitry Andric class reference 27*0b57cec5SDimitry Andric { 28*0b57cec5SDimitry Andric friend class bitset; 29*0b57cec5SDimitry Andric reference() noexcept; 30*0b57cec5SDimitry Andric public: 31*0b57cec5SDimitry Andric ~reference() noexcept; 32*0b57cec5SDimitry Andric reference& operator=(bool x) noexcept; // for b[i] = x; 33*0b57cec5SDimitry Andric reference& operator=(const reference&) noexcept; // for b[i] = b[j]; 34*0b57cec5SDimitry Andric bool operator~() const noexcept; // flips the bit 35*0b57cec5SDimitry Andric operator bool() const noexcept; // for x = b[i]; 36*0b57cec5SDimitry Andric reference& flip() noexcept; // for b[i].flip(); 37*0b57cec5SDimitry Andric }; 38*0b57cec5SDimitry Andric 39*0b57cec5SDimitry Andric // 23.3.5.1 constructors: 40*0b57cec5SDimitry Andric constexpr bitset() noexcept; 41*0b57cec5SDimitry Andric constexpr bitset(unsigned long long val) noexcept; 42*0b57cec5SDimitry Andric template <class charT> 43*0b57cec5SDimitry Andric explicit bitset(const charT* str, 44*0b57cec5SDimitry Andric typename basic_string<charT>::size_type n = basic_string<charT>::npos, 45*0b57cec5SDimitry Andric charT zero = charT('0'), charT one = charT('1')); 46*0b57cec5SDimitry Andric template<class charT, class traits, class Allocator> 47*0b57cec5SDimitry Andric explicit bitset(const basic_string<charT,traits,Allocator>& str, 48*0b57cec5SDimitry Andric typename basic_string<charT,traits,Allocator>::size_type pos = 0, 49*0b57cec5SDimitry Andric typename basic_string<charT,traits,Allocator>::size_type n = 50*0b57cec5SDimitry Andric basic_string<charT,traits,Allocator>::npos, 51*0b57cec5SDimitry Andric charT zero = charT('0'), charT one = charT('1')); 52*0b57cec5SDimitry Andric 53*0b57cec5SDimitry Andric // 23.3.5.2 bitset operations: 54*0b57cec5SDimitry Andric bitset& operator&=(const bitset& rhs) noexcept; 55*0b57cec5SDimitry Andric bitset& operator|=(const bitset& rhs) noexcept; 56*0b57cec5SDimitry Andric bitset& operator^=(const bitset& rhs) noexcept; 57*0b57cec5SDimitry Andric bitset& operator<<=(size_t pos) noexcept; 58*0b57cec5SDimitry Andric bitset& operator>>=(size_t pos) noexcept; 59*0b57cec5SDimitry Andric bitset& set() noexcept; 60*0b57cec5SDimitry Andric bitset& set(size_t pos, bool val = true); 61*0b57cec5SDimitry Andric bitset& reset() noexcept; 62*0b57cec5SDimitry Andric bitset& reset(size_t pos); 63*0b57cec5SDimitry Andric bitset operator~() const noexcept; 64*0b57cec5SDimitry Andric bitset& flip() noexcept; 65*0b57cec5SDimitry Andric bitset& flip(size_t pos); 66*0b57cec5SDimitry Andric 67*0b57cec5SDimitry Andric // element access: 68*0b57cec5SDimitry Andric constexpr bool operator[](size_t pos) const; // for b[i]; 69*0b57cec5SDimitry Andric reference operator[](size_t pos); // for b[i]; 70*0b57cec5SDimitry Andric unsigned long to_ulong() const; 71*0b57cec5SDimitry Andric unsigned long long to_ullong() const; 72*0b57cec5SDimitry Andric template <class charT, class traits, class Allocator> 73*0b57cec5SDimitry Andric basic_string<charT, traits, Allocator> to_string(charT zero = charT('0'), charT one = charT('1')) const; 74*0b57cec5SDimitry Andric template <class charT, class traits> 75*0b57cec5SDimitry Andric basic_string<charT, traits, allocator<charT> > to_string(charT zero = charT('0'), charT one = charT('1')) const; 76*0b57cec5SDimitry Andric template <class charT> 77*0b57cec5SDimitry Andric basic_string<charT, char_traits<charT>, allocator<charT> > to_string(charT zero = charT('0'), charT one = charT('1')) const; 78*0b57cec5SDimitry Andric basic_string<char, char_traits<char>, allocator<char> > to_string(char zero = '0', char one = '1') const; 79*0b57cec5SDimitry Andric size_t count() const noexcept; 80*0b57cec5SDimitry Andric constexpr size_t size() const noexcept; 81*0b57cec5SDimitry Andric bool operator==(const bitset& rhs) const noexcept; 82*0b57cec5SDimitry Andric bool operator!=(const bitset& rhs) const noexcept; 83*0b57cec5SDimitry Andric bool test(size_t pos) const; 84*0b57cec5SDimitry Andric bool all() const noexcept; 85*0b57cec5SDimitry Andric bool any() const noexcept; 86*0b57cec5SDimitry Andric bool none() const noexcept; 87*0b57cec5SDimitry Andric bitset operator<<(size_t pos) const noexcept; 88*0b57cec5SDimitry Andric bitset operator>>(size_t pos) const noexcept; 89*0b57cec5SDimitry Andric}; 90*0b57cec5SDimitry Andric 91*0b57cec5SDimitry Andric// 23.3.5.3 bitset operators: 92*0b57cec5SDimitry Andrictemplate <size_t N> 93*0b57cec5SDimitry Andricbitset<N> operator&(const bitset<N>&, const bitset<N>&) noexcept; 94*0b57cec5SDimitry Andric 95*0b57cec5SDimitry Andrictemplate <size_t N> 96*0b57cec5SDimitry Andricbitset<N> operator|(const bitset<N>&, const bitset<N>&) noexcept; 97*0b57cec5SDimitry Andric 98*0b57cec5SDimitry Andrictemplate <size_t N> 99*0b57cec5SDimitry Andricbitset<N> operator^(const bitset<N>&, const bitset<N>&) noexcept; 100*0b57cec5SDimitry Andric 101*0b57cec5SDimitry Andrictemplate <class charT, class traits, size_t N> 102*0b57cec5SDimitry Andricbasic_istream<charT, traits>& 103*0b57cec5SDimitry Andricoperator>>(basic_istream<charT, traits>& is, bitset<N>& x); 104*0b57cec5SDimitry Andric 105*0b57cec5SDimitry Andrictemplate <class charT, class traits, size_t N> 106*0b57cec5SDimitry Andricbasic_ostream<charT, traits>& 107*0b57cec5SDimitry Andricoperator<<(basic_ostream<charT, traits>& os, const bitset<N>& x); 108*0b57cec5SDimitry Andric 109*0b57cec5SDimitry Andrictemplate <size_t N> struct hash<std::bitset<N>>; 110*0b57cec5SDimitry Andric 111*0b57cec5SDimitry Andric} // std 112*0b57cec5SDimitry Andric 113*0b57cec5SDimitry Andric*/ 114*0b57cec5SDimitry Andric 115*0b57cec5SDimitry Andric#include <__config> 116*0b57cec5SDimitry Andric#include <__bit_reference> 117*0b57cec5SDimitry Andric#include <cstddef> 118*0b57cec5SDimitry Andric#include <climits> 119*0b57cec5SDimitry Andric#include <string> 120*0b57cec5SDimitry Andric#include <stdexcept> 121*0b57cec5SDimitry Andric#include <iosfwd> 122*0b57cec5SDimitry Andric#include <__functional_base> 123*0b57cec5SDimitry Andric 124*0b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 125*0b57cec5SDimitry Andric#pragma GCC system_header 126*0b57cec5SDimitry Andric#endif 127*0b57cec5SDimitry Andric 128*0b57cec5SDimitry Andric_LIBCPP_PUSH_MACROS 129*0b57cec5SDimitry Andric#include <__undef_macros> 130*0b57cec5SDimitry Andric 131*0b57cec5SDimitry Andric 132*0b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD 133*0b57cec5SDimitry Andric 134*0b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 135*0b57cec5SDimitry Andricclass __bitset; 136*0b57cec5SDimitry Andric 137*0b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 138*0b57cec5SDimitry Andricstruct __has_storage_type<__bitset<_N_words, _Size> > 139*0b57cec5SDimitry Andric{ 140*0b57cec5SDimitry Andric static const bool value = true; 141*0b57cec5SDimitry Andric}; 142*0b57cec5SDimitry Andric 143*0b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 144*0b57cec5SDimitry Andricclass __bitset 145*0b57cec5SDimitry Andric{ 146*0b57cec5SDimitry Andricpublic: 147*0b57cec5SDimitry Andric typedef ptrdiff_t difference_type; 148*0b57cec5SDimitry Andric typedef size_t size_type; 149*0b57cec5SDimitry Andric typedef size_type __storage_type; 150*0b57cec5SDimitry Andricprotected: 151*0b57cec5SDimitry Andric typedef __bitset __self; 152*0b57cec5SDimitry Andric typedef __storage_type* __storage_pointer; 153*0b57cec5SDimitry Andric typedef const __storage_type* __const_storage_pointer; 154*0b57cec5SDimitry Andric static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT); 155*0b57cec5SDimitry Andric 156*0b57cec5SDimitry Andric friend class __bit_reference<__bitset>; 157*0b57cec5SDimitry Andric friend class __bit_const_reference<__bitset>; 158*0b57cec5SDimitry Andric friend class __bit_iterator<__bitset, false>; 159*0b57cec5SDimitry Andric friend class __bit_iterator<__bitset, true>; 160*0b57cec5SDimitry Andric friend struct __bit_array<__bitset>; 161*0b57cec5SDimitry Andric 162*0b57cec5SDimitry Andric __storage_type __first_[_N_words]; 163*0b57cec5SDimitry Andric 164*0b57cec5SDimitry Andric typedef __bit_reference<__bitset> reference; 165*0b57cec5SDimitry Andric typedef __bit_const_reference<__bitset> const_reference; 166*0b57cec5SDimitry Andric typedef __bit_iterator<__bitset, false> iterator; 167*0b57cec5SDimitry Andric typedef __bit_iterator<__bitset, true> const_iterator; 168*0b57cec5SDimitry Andric 169*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 170*0b57cec5SDimitry Andric _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT; 171*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 172*0b57cec5SDimitry Andric explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT; 173*0b57cec5SDimitry Andric 174*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t __pos) _NOEXCEPT 175*0b57cec5SDimitry Andric {return reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);} 176*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT 177*0b57cec5SDimitry Andric {return const_reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);} 178*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t __pos) _NOEXCEPT 179*0b57cec5SDimitry Andric {return iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);} 180*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t __pos) const _NOEXCEPT 181*0b57cec5SDimitry Andric {return const_iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);} 182*0b57cec5SDimitry Andric 183*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 184*0b57cec5SDimitry Andric void operator&=(const __bitset& __v) _NOEXCEPT; 185*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 186*0b57cec5SDimitry Andric void operator|=(const __bitset& __v) _NOEXCEPT; 187*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 188*0b57cec5SDimitry Andric void operator^=(const __bitset& __v) _NOEXCEPT; 189*0b57cec5SDimitry Andric 190*0b57cec5SDimitry Andric void flip() _NOEXCEPT; 191*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY unsigned long to_ulong() const 192*0b57cec5SDimitry Andric {return to_ulong(integral_constant<bool, _Size < sizeof(unsigned long) * CHAR_BIT>());} 193*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY unsigned long long to_ullong() const 194*0b57cec5SDimitry Andric {return to_ullong(integral_constant<bool, _Size < sizeof(unsigned long long) * CHAR_BIT>());} 195*0b57cec5SDimitry Andric 196*0b57cec5SDimitry Andric bool all() const _NOEXCEPT; 197*0b57cec5SDimitry Andric bool any() const _NOEXCEPT; 198*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 199*0b57cec5SDimitry Andric size_t __hash_code() const _NOEXCEPT; 200*0b57cec5SDimitry Andricprivate: 201*0b57cec5SDimitry Andric#ifdef _LIBCPP_CXX03_LANG 202*0b57cec5SDimitry Andric void __init(unsigned long long __v, false_type) _NOEXCEPT; 203*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 204*0b57cec5SDimitry Andric void __init(unsigned long long __v, true_type) _NOEXCEPT; 205*0b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 206*0b57cec5SDimitry Andric unsigned long to_ulong(false_type) const; 207*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 208*0b57cec5SDimitry Andric unsigned long to_ulong(true_type) const; 209*0b57cec5SDimitry Andric unsigned long long to_ullong(false_type) const; 210*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 211*0b57cec5SDimitry Andric unsigned long long to_ullong(true_type) const; 212*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 213*0b57cec5SDimitry Andric unsigned long long to_ullong(true_type, false_type) const; 214*0b57cec5SDimitry Andric unsigned long long to_ullong(true_type, true_type) const; 215*0b57cec5SDimitry Andric}; 216*0b57cec5SDimitry Andric 217*0b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 218*0b57cec5SDimitry Andricinline 219*0b57cec5SDimitry Andric_LIBCPP_CONSTEXPR 220*0b57cec5SDimitry Andric__bitset<_N_words, _Size>::__bitset() _NOEXCEPT 221*0b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 222*0b57cec5SDimitry Andric : __first_{0} 223*0b57cec5SDimitry Andric#endif 224*0b57cec5SDimitry Andric{ 225*0b57cec5SDimitry Andric#ifdef _LIBCPP_CXX03_LANG 226*0b57cec5SDimitry Andric _VSTD::fill_n(__first_, _N_words, __storage_type(0)); 227*0b57cec5SDimitry Andric#endif 228*0b57cec5SDimitry Andric} 229*0b57cec5SDimitry Andric 230*0b57cec5SDimitry Andric#ifdef _LIBCPP_CXX03_LANG 231*0b57cec5SDimitry Andric 232*0b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 233*0b57cec5SDimitry Andricvoid 234*0b57cec5SDimitry Andric__bitset<_N_words, _Size>::__init(unsigned long long __v, false_type) _NOEXCEPT 235*0b57cec5SDimitry Andric{ 236*0b57cec5SDimitry Andric __storage_type __t[sizeof(unsigned long long) / sizeof(__storage_type)]; 237*0b57cec5SDimitry Andric size_t __sz = _Size; 238*0b57cec5SDimitry Andric for (size_t __i = 0; __i < sizeof(__t)/sizeof(__t[0]); ++__i, __v >>= __bits_per_word, __sz -= __bits_per_word ) 239*0b57cec5SDimitry Andric if ( __sz < __bits_per_word) 240*0b57cec5SDimitry Andric __t[__i] = static_cast<__storage_type>(__v) & ( 1ULL << __sz ) - 1; 241*0b57cec5SDimitry Andric else 242*0b57cec5SDimitry Andric __t[__i] = static_cast<__storage_type>(__v); 243*0b57cec5SDimitry Andric 244*0b57cec5SDimitry Andric _VSTD::copy(__t, __t + sizeof(__t)/sizeof(__t[0]), __first_); 245*0b57cec5SDimitry Andric _VSTD::fill(__first_ + sizeof(__t)/sizeof(__t[0]), __first_ + sizeof(__first_)/sizeof(__first_[0]), 246*0b57cec5SDimitry Andric __storage_type(0)); 247*0b57cec5SDimitry Andric} 248*0b57cec5SDimitry Andric 249*0b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 250*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 251*0b57cec5SDimitry Andricvoid 252*0b57cec5SDimitry Andric__bitset<_N_words, _Size>::__init(unsigned long long __v, true_type) _NOEXCEPT 253*0b57cec5SDimitry Andric{ 254*0b57cec5SDimitry Andric __first_[0] = __v; 255*0b57cec5SDimitry Andric if (_Size < __bits_per_word) 256*0b57cec5SDimitry Andric __first_[0] &= ( 1ULL << _Size ) - 1; 257*0b57cec5SDimitry Andric 258*0b57cec5SDimitry Andric _VSTD::fill(__first_ + 1, __first_ + sizeof(__first_)/sizeof(__first_[0]), __storage_type(0)); 259*0b57cec5SDimitry Andric} 260*0b57cec5SDimitry Andric 261*0b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 262*0b57cec5SDimitry Andric 263*0b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 264*0b57cec5SDimitry Andricinline 265*0b57cec5SDimitry Andric_LIBCPP_CONSTEXPR 266*0b57cec5SDimitry Andric__bitset<_N_words, _Size>::__bitset(unsigned long long __v) _NOEXCEPT 267*0b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 268*0b57cec5SDimitry Andric#if __SIZEOF_SIZE_T__ == 8 269*0b57cec5SDimitry Andric : __first_{__v} 270*0b57cec5SDimitry Andric#elif __SIZEOF_SIZE_T__ == 4 271*0b57cec5SDimitry Andric : __first_{static_cast<__storage_type>(__v), 272*0b57cec5SDimitry Andric _Size >= 2 * __bits_per_word ? static_cast<__storage_type>(__v >> __bits_per_word) 273*0b57cec5SDimitry Andric : static_cast<__storage_type>((__v >> __bits_per_word) & (__storage_type(1) << (_Size - __bits_per_word)) - 1)} 274*0b57cec5SDimitry Andric#else 275*0b57cec5SDimitry Andric#error This constructor has not been ported to this platform 276*0b57cec5SDimitry Andric#endif 277*0b57cec5SDimitry Andric#endif 278*0b57cec5SDimitry Andric{ 279*0b57cec5SDimitry Andric#ifdef _LIBCPP_CXX03_LANG 280*0b57cec5SDimitry Andric __init(__v, integral_constant<bool, sizeof(unsigned long long) == sizeof(__storage_type)>()); 281*0b57cec5SDimitry Andric#endif 282*0b57cec5SDimitry Andric} 283*0b57cec5SDimitry Andric 284*0b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 285*0b57cec5SDimitry Andricinline 286*0b57cec5SDimitry Andricvoid 287*0b57cec5SDimitry Andric__bitset<_N_words, _Size>::operator&=(const __bitset& __v) _NOEXCEPT 288*0b57cec5SDimitry Andric{ 289*0b57cec5SDimitry Andric for (size_type __i = 0; __i < _N_words; ++__i) 290*0b57cec5SDimitry Andric __first_[__i] &= __v.__first_[__i]; 291*0b57cec5SDimitry Andric} 292*0b57cec5SDimitry Andric 293*0b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 294*0b57cec5SDimitry Andricinline 295*0b57cec5SDimitry Andricvoid 296*0b57cec5SDimitry Andric__bitset<_N_words, _Size>::operator|=(const __bitset& __v) _NOEXCEPT 297*0b57cec5SDimitry Andric{ 298*0b57cec5SDimitry Andric for (size_type __i = 0; __i < _N_words; ++__i) 299*0b57cec5SDimitry Andric __first_[__i] |= __v.__first_[__i]; 300*0b57cec5SDimitry Andric} 301*0b57cec5SDimitry Andric 302*0b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 303*0b57cec5SDimitry Andricinline 304*0b57cec5SDimitry Andricvoid 305*0b57cec5SDimitry Andric__bitset<_N_words, _Size>::operator^=(const __bitset& __v) _NOEXCEPT 306*0b57cec5SDimitry Andric{ 307*0b57cec5SDimitry Andric for (size_type __i = 0; __i < _N_words; ++__i) 308*0b57cec5SDimitry Andric __first_[__i] ^= __v.__first_[__i]; 309*0b57cec5SDimitry Andric} 310*0b57cec5SDimitry Andric 311*0b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 312*0b57cec5SDimitry Andricvoid 313*0b57cec5SDimitry Andric__bitset<_N_words, _Size>::flip() _NOEXCEPT 314*0b57cec5SDimitry Andric{ 315*0b57cec5SDimitry Andric // do middle whole words 316*0b57cec5SDimitry Andric size_type __n = _Size; 317*0b57cec5SDimitry Andric __storage_pointer __p = __first_; 318*0b57cec5SDimitry Andric for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) 319*0b57cec5SDimitry Andric *__p = ~*__p; 320*0b57cec5SDimitry Andric // do last partial word 321*0b57cec5SDimitry Andric if (__n > 0) 322*0b57cec5SDimitry Andric { 323*0b57cec5SDimitry Andric __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); 324*0b57cec5SDimitry Andric __storage_type __b = *__p & __m; 325*0b57cec5SDimitry Andric *__p &= ~__m; 326*0b57cec5SDimitry Andric *__p |= ~__b & __m; 327*0b57cec5SDimitry Andric } 328*0b57cec5SDimitry Andric} 329*0b57cec5SDimitry Andric 330*0b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 331*0b57cec5SDimitry Andricunsigned long 332*0b57cec5SDimitry Andric__bitset<_N_words, _Size>::to_ulong(false_type) const 333*0b57cec5SDimitry Andric{ 334*0b57cec5SDimitry Andric const_iterator __e = __make_iter(_Size); 335*0b57cec5SDimitry Andric const_iterator __i = _VSTD::find(__make_iter(sizeof(unsigned long) * CHAR_BIT), __e, true); 336*0b57cec5SDimitry Andric if (__i != __e) 337*0b57cec5SDimitry Andric __throw_overflow_error("bitset to_ulong overflow error"); 338*0b57cec5SDimitry Andric 339*0b57cec5SDimitry Andric return __first_[0]; 340*0b57cec5SDimitry Andric} 341*0b57cec5SDimitry Andric 342*0b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 343*0b57cec5SDimitry Andricinline 344*0b57cec5SDimitry Andricunsigned long 345*0b57cec5SDimitry Andric__bitset<_N_words, _Size>::to_ulong(true_type) const 346*0b57cec5SDimitry Andric{ 347*0b57cec5SDimitry Andric return __first_[0]; 348*0b57cec5SDimitry Andric} 349*0b57cec5SDimitry Andric 350*0b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 351*0b57cec5SDimitry Andricunsigned long long 352*0b57cec5SDimitry Andric__bitset<_N_words, _Size>::to_ullong(false_type) const 353*0b57cec5SDimitry Andric{ 354*0b57cec5SDimitry Andric const_iterator __e = __make_iter(_Size); 355*0b57cec5SDimitry Andric const_iterator __i = _VSTD::find(__make_iter(sizeof(unsigned long long) * CHAR_BIT), __e, true); 356*0b57cec5SDimitry Andric if (__i != __e) 357*0b57cec5SDimitry Andric __throw_overflow_error("bitset to_ullong overflow error"); 358*0b57cec5SDimitry Andric 359*0b57cec5SDimitry Andric return to_ullong(true_type()); 360*0b57cec5SDimitry Andric} 361*0b57cec5SDimitry Andric 362*0b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 363*0b57cec5SDimitry Andricinline 364*0b57cec5SDimitry Andricunsigned long long 365*0b57cec5SDimitry Andric__bitset<_N_words, _Size>::to_ullong(true_type) const 366*0b57cec5SDimitry Andric{ 367*0b57cec5SDimitry Andric return to_ullong(true_type(), integral_constant<bool, sizeof(__storage_type) < sizeof(unsigned long long)>()); 368*0b57cec5SDimitry Andric} 369*0b57cec5SDimitry Andric 370*0b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 371*0b57cec5SDimitry Andricinline 372*0b57cec5SDimitry Andricunsigned long long 373*0b57cec5SDimitry Andric__bitset<_N_words, _Size>::to_ullong(true_type, false_type) const 374*0b57cec5SDimitry Andric{ 375*0b57cec5SDimitry Andric return __first_[0]; 376*0b57cec5SDimitry Andric} 377*0b57cec5SDimitry Andric 378*0b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 379*0b57cec5SDimitry Andricunsigned long long 380*0b57cec5SDimitry Andric__bitset<_N_words, _Size>::to_ullong(true_type, true_type) const 381*0b57cec5SDimitry Andric{ 382*0b57cec5SDimitry Andric unsigned long long __r = __first_[0]; 383*0b57cec5SDimitry Andric for (std::size_t __i = 1; __i < sizeof(unsigned long long) / sizeof(__storage_type); ++__i) 384*0b57cec5SDimitry Andric __r |= static_cast<unsigned long long>(__first_[__i]) << (sizeof(__storage_type) * CHAR_BIT); 385*0b57cec5SDimitry Andric return __r; 386*0b57cec5SDimitry Andric} 387*0b57cec5SDimitry Andric 388*0b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 389*0b57cec5SDimitry Andricbool 390*0b57cec5SDimitry Andric__bitset<_N_words, _Size>::all() const _NOEXCEPT 391*0b57cec5SDimitry Andric{ 392*0b57cec5SDimitry Andric // do middle whole words 393*0b57cec5SDimitry Andric size_type __n = _Size; 394*0b57cec5SDimitry Andric __const_storage_pointer __p = __first_; 395*0b57cec5SDimitry Andric for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) 396*0b57cec5SDimitry Andric if (~*__p) 397*0b57cec5SDimitry Andric return false; 398*0b57cec5SDimitry Andric // do last partial word 399*0b57cec5SDimitry Andric if (__n > 0) 400*0b57cec5SDimitry Andric { 401*0b57cec5SDimitry Andric __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); 402*0b57cec5SDimitry Andric if (~*__p & __m) 403*0b57cec5SDimitry Andric return false; 404*0b57cec5SDimitry Andric } 405*0b57cec5SDimitry Andric return true; 406*0b57cec5SDimitry Andric} 407*0b57cec5SDimitry Andric 408*0b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 409*0b57cec5SDimitry Andricbool 410*0b57cec5SDimitry Andric__bitset<_N_words, _Size>::any() const _NOEXCEPT 411*0b57cec5SDimitry Andric{ 412*0b57cec5SDimitry Andric // do middle whole words 413*0b57cec5SDimitry Andric size_type __n = _Size; 414*0b57cec5SDimitry Andric __const_storage_pointer __p = __first_; 415*0b57cec5SDimitry Andric for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) 416*0b57cec5SDimitry Andric if (*__p) 417*0b57cec5SDimitry Andric return true; 418*0b57cec5SDimitry Andric // do last partial word 419*0b57cec5SDimitry Andric if (__n > 0) 420*0b57cec5SDimitry Andric { 421*0b57cec5SDimitry Andric __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); 422*0b57cec5SDimitry Andric if (*__p & __m) 423*0b57cec5SDimitry Andric return true; 424*0b57cec5SDimitry Andric } 425*0b57cec5SDimitry Andric return false; 426*0b57cec5SDimitry Andric} 427*0b57cec5SDimitry Andric 428*0b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 429*0b57cec5SDimitry Andricinline 430*0b57cec5SDimitry Andricsize_t 431*0b57cec5SDimitry Andric__bitset<_N_words, _Size>::__hash_code() const _NOEXCEPT 432*0b57cec5SDimitry Andric{ 433*0b57cec5SDimitry Andric size_t __h = 0; 434*0b57cec5SDimitry Andric for (size_type __i = 0; __i < _N_words; ++__i) 435*0b57cec5SDimitry Andric __h ^= __first_[__i]; 436*0b57cec5SDimitry Andric return __h; 437*0b57cec5SDimitry Andric} 438*0b57cec5SDimitry Andric 439*0b57cec5SDimitry Andrictemplate <size_t _Size> 440*0b57cec5SDimitry Andricclass __bitset<1, _Size> 441*0b57cec5SDimitry Andric{ 442*0b57cec5SDimitry Andricpublic: 443*0b57cec5SDimitry Andric typedef ptrdiff_t difference_type; 444*0b57cec5SDimitry Andric typedef size_t size_type; 445*0b57cec5SDimitry Andric typedef size_type __storage_type; 446*0b57cec5SDimitry Andricprotected: 447*0b57cec5SDimitry Andric typedef __bitset __self; 448*0b57cec5SDimitry Andric typedef __storage_type* __storage_pointer; 449*0b57cec5SDimitry Andric typedef const __storage_type* __const_storage_pointer; 450*0b57cec5SDimitry Andric static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT); 451*0b57cec5SDimitry Andric 452*0b57cec5SDimitry Andric friend class __bit_reference<__bitset>; 453*0b57cec5SDimitry Andric friend class __bit_const_reference<__bitset>; 454*0b57cec5SDimitry Andric friend class __bit_iterator<__bitset, false>; 455*0b57cec5SDimitry Andric friend class __bit_iterator<__bitset, true>; 456*0b57cec5SDimitry Andric friend struct __bit_array<__bitset>; 457*0b57cec5SDimitry Andric 458*0b57cec5SDimitry Andric __storage_type __first_; 459*0b57cec5SDimitry Andric 460*0b57cec5SDimitry Andric typedef __bit_reference<__bitset> reference; 461*0b57cec5SDimitry Andric typedef __bit_const_reference<__bitset> const_reference; 462*0b57cec5SDimitry Andric typedef __bit_iterator<__bitset, false> iterator; 463*0b57cec5SDimitry Andric typedef __bit_iterator<__bitset, true> const_iterator; 464*0b57cec5SDimitry Andric 465*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 466*0b57cec5SDimitry Andric _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT; 467*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 468*0b57cec5SDimitry Andric explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT; 469*0b57cec5SDimitry Andric 470*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t __pos) _NOEXCEPT 471*0b57cec5SDimitry Andric {return reference(&__first_, __storage_type(1) << __pos);} 472*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT 473*0b57cec5SDimitry Andric {return const_reference(&__first_, __storage_type(1) << __pos);} 474*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t __pos) _NOEXCEPT 475*0b57cec5SDimitry Andric {return iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);} 476*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t __pos) const _NOEXCEPT 477*0b57cec5SDimitry Andric {return const_iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);} 478*0b57cec5SDimitry Andric 479*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 480*0b57cec5SDimitry Andric void operator&=(const __bitset& __v) _NOEXCEPT; 481*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 482*0b57cec5SDimitry Andric void operator|=(const __bitset& __v) _NOEXCEPT; 483*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 484*0b57cec5SDimitry Andric void operator^=(const __bitset& __v) _NOEXCEPT; 485*0b57cec5SDimitry Andric 486*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 487*0b57cec5SDimitry Andric void flip() _NOEXCEPT; 488*0b57cec5SDimitry Andric 489*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 490*0b57cec5SDimitry Andric unsigned long to_ulong() const; 491*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 492*0b57cec5SDimitry Andric unsigned long long to_ullong() const; 493*0b57cec5SDimitry Andric 494*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 495*0b57cec5SDimitry Andric bool all() const _NOEXCEPT; 496*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 497*0b57cec5SDimitry Andric bool any() const _NOEXCEPT; 498*0b57cec5SDimitry Andric 499*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 500*0b57cec5SDimitry Andric size_t __hash_code() const _NOEXCEPT; 501*0b57cec5SDimitry Andric}; 502*0b57cec5SDimitry Andric 503*0b57cec5SDimitry Andrictemplate <size_t _Size> 504*0b57cec5SDimitry Andricinline 505*0b57cec5SDimitry Andric_LIBCPP_CONSTEXPR 506*0b57cec5SDimitry Andric__bitset<1, _Size>::__bitset() _NOEXCEPT 507*0b57cec5SDimitry Andric : __first_(0) 508*0b57cec5SDimitry Andric{ 509*0b57cec5SDimitry Andric} 510*0b57cec5SDimitry Andric 511*0b57cec5SDimitry Andrictemplate <size_t _Size> 512*0b57cec5SDimitry Andricinline 513*0b57cec5SDimitry Andric_LIBCPP_CONSTEXPR 514*0b57cec5SDimitry Andric__bitset<1, _Size>::__bitset(unsigned long long __v) _NOEXCEPT 515*0b57cec5SDimitry Andric : __first_( 516*0b57cec5SDimitry Andric _Size == __bits_per_word ? static_cast<__storage_type>(__v) 517*0b57cec5SDimitry Andric : static_cast<__storage_type>(__v) & ((__storage_type(1) << _Size) - 1) 518*0b57cec5SDimitry Andric ) 519*0b57cec5SDimitry Andric{ 520*0b57cec5SDimitry Andric} 521*0b57cec5SDimitry Andric 522*0b57cec5SDimitry Andrictemplate <size_t _Size> 523*0b57cec5SDimitry Andricinline 524*0b57cec5SDimitry Andricvoid 525*0b57cec5SDimitry Andric__bitset<1, _Size>::operator&=(const __bitset& __v) _NOEXCEPT 526*0b57cec5SDimitry Andric{ 527*0b57cec5SDimitry Andric __first_ &= __v.__first_; 528*0b57cec5SDimitry Andric} 529*0b57cec5SDimitry Andric 530*0b57cec5SDimitry Andrictemplate <size_t _Size> 531*0b57cec5SDimitry Andricinline 532*0b57cec5SDimitry Andricvoid 533*0b57cec5SDimitry Andric__bitset<1, _Size>::operator|=(const __bitset& __v) _NOEXCEPT 534*0b57cec5SDimitry Andric{ 535*0b57cec5SDimitry Andric __first_ |= __v.__first_; 536*0b57cec5SDimitry Andric} 537*0b57cec5SDimitry Andric 538*0b57cec5SDimitry Andrictemplate <size_t _Size> 539*0b57cec5SDimitry Andricinline 540*0b57cec5SDimitry Andricvoid 541*0b57cec5SDimitry Andric__bitset<1, _Size>::operator^=(const __bitset& __v) _NOEXCEPT 542*0b57cec5SDimitry Andric{ 543*0b57cec5SDimitry Andric __first_ ^= __v.__first_; 544*0b57cec5SDimitry Andric} 545*0b57cec5SDimitry Andric 546*0b57cec5SDimitry Andrictemplate <size_t _Size> 547*0b57cec5SDimitry Andricinline 548*0b57cec5SDimitry Andricvoid 549*0b57cec5SDimitry Andric__bitset<1, _Size>::flip() _NOEXCEPT 550*0b57cec5SDimitry Andric{ 551*0b57cec5SDimitry Andric __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size); 552*0b57cec5SDimitry Andric __first_ = ~__first_; 553*0b57cec5SDimitry Andric __first_ &= __m; 554*0b57cec5SDimitry Andric} 555*0b57cec5SDimitry Andric 556*0b57cec5SDimitry Andrictemplate <size_t _Size> 557*0b57cec5SDimitry Andricinline 558*0b57cec5SDimitry Andricunsigned long 559*0b57cec5SDimitry Andric__bitset<1, _Size>::to_ulong() const 560*0b57cec5SDimitry Andric{ 561*0b57cec5SDimitry Andric return __first_; 562*0b57cec5SDimitry Andric} 563*0b57cec5SDimitry Andric 564*0b57cec5SDimitry Andrictemplate <size_t _Size> 565*0b57cec5SDimitry Andricinline 566*0b57cec5SDimitry Andricunsigned long long 567*0b57cec5SDimitry Andric__bitset<1, _Size>::to_ullong() const 568*0b57cec5SDimitry Andric{ 569*0b57cec5SDimitry Andric return __first_; 570*0b57cec5SDimitry Andric} 571*0b57cec5SDimitry Andric 572*0b57cec5SDimitry Andrictemplate <size_t _Size> 573*0b57cec5SDimitry Andricinline 574*0b57cec5SDimitry Andricbool 575*0b57cec5SDimitry Andric__bitset<1, _Size>::all() const _NOEXCEPT 576*0b57cec5SDimitry Andric{ 577*0b57cec5SDimitry Andric __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size); 578*0b57cec5SDimitry Andric return !(~__first_ & __m); 579*0b57cec5SDimitry Andric} 580*0b57cec5SDimitry Andric 581*0b57cec5SDimitry Andrictemplate <size_t _Size> 582*0b57cec5SDimitry Andricinline 583*0b57cec5SDimitry Andricbool 584*0b57cec5SDimitry Andric__bitset<1, _Size>::any() const _NOEXCEPT 585*0b57cec5SDimitry Andric{ 586*0b57cec5SDimitry Andric __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size); 587*0b57cec5SDimitry Andric return __first_ & __m; 588*0b57cec5SDimitry Andric} 589*0b57cec5SDimitry Andric 590*0b57cec5SDimitry Andrictemplate <size_t _Size> 591*0b57cec5SDimitry Andricinline 592*0b57cec5SDimitry Andricsize_t 593*0b57cec5SDimitry Andric__bitset<1, _Size>::__hash_code() const _NOEXCEPT 594*0b57cec5SDimitry Andric{ 595*0b57cec5SDimitry Andric return __first_; 596*0b57cec5SDimitry Andric} 597*0b57cec5SDimitry Andric 598*0b57cec5SDimitry Andrictemplate <> 599*0b57cec5SDimitry Andricclass __bitset<0, 0> 600*0b57cec5SDimitry Andric{ 601*0b57cec5SDimitry Andricpublic: 602*0b57cec5SDimitry Andric typedef ptrdiff_t difference_type; 603*0b57cec5SDimitry Andric typedef size_t size_type; 604*0b57cec5SDimitry Andric typedef size_type __storage_type; 605*0b57cec5SDimitry Andricprotected: 606*0b57cec5SDimitry Andric typedef __bitset __self; 607*0b57cec5SDimitry Andric typedef __storage_type* __storage_pointer; 608*0b57cec5SDimitry Andric typedef const __storage_type* __const_storage_pointer; 609*0b57cec5SDimitry Andric static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT); 610*0b57cec5SDimitry Andric 611*0b57cec5SDimitry Andric friend class __bit_reference<__bitset>; 612*0b57cec5SDimitry Andric friend class __bit_const_reference<__bitset>; 613*0b57cec5SDimitry Andric friend class __bit_iterator<__bitset, false>; 614*0b57cec5SDimitry Andric friend class __bit_iterator<__bitset, true>; 615*0b57cec5SDimitry Andric friend struct __bit_array<__bitset>; 616*0b57cec5SDimitry Andric 617*0b57cec5SDimitry Andric typedef __bit_reference<__bitset> reference; 618*0b57cec5SDimitry Andric typedef __bit_const_reference<__bitset> const_reference; 619*0b57cec5SDimitry Andric typedef __bit_iterator<__bitset, false> iterator; 620*0b57cec5SDimitry Andric typedef __bit_iterator<__bitset, true> const_iterator; 621*0b57cec5SDimitry Andric 622*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 623*0b57cec5SDimitry Andric _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT; 624*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 625*0b57cec5SDimitry Andric explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long) _NOEXCEPT; 626*0b57cec5SDimitry Andric 627*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t) _NOEXCEPT 628*0b57cec5SDimitry Andric {return reference(0, 1);} 629*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t) const _NOEXCEPT 630*0b57cec5SDimitry Andric {return const_reference(0, 1);} 631*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t) _NOEXCEPT 632*0b57cec5SDimitry Andric {return iterator(0, 0);} 633*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t) const _NOEXCEPT 634*0b57cec5SDimitry Andric {return const_iterator(0, 0);} 635*0b57cec5SDimitry Andric 636*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY void operator&=(const __bitset&) _NOEXCEPT {} 637*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY void operator|=(const __bitset&) _NOEXCEPT {} 638*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY void operator^=(const __bitset&) _NOEXCEPT {} 639*0b57cec5SDimitry Andric 640*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY void flip() _NOEXCEPT {} 641*0b57cec5SDimitry Andric 642*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY unsigned long to_ulong() const {return 0;} 643*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY unsigned long long to_ullong() const {return 0;} 644*0b57cec5SDimitry Andric 645*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY bool all() const _NOEXCEPT {return true;} 646*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY bool any() const _NOEXCEPT {return false;} 647*0b57cec5SDimitry Andric 648*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY size_t __hash_code() const _NOEXCEPT {return 0;} 649*0b57cec5SDimitry Andric}; 650*0b57cec5SDimitry Andric 651*0b57cec5SDimitry Andricinline 652*0b57cec5SDimitry Andric_LIBCPP_CONSTEXPR 653*0b57cec5SDimitry Andric__bitset<0, 0>::__bitset() _NOEXCEPT 654*0b57cec5SDimitry Andric{ 655*0b57cec5SDimitry Andric} 656*0b57cec5SDimitry Andric 657*0b57cec5SDimitry Andricinline 658*0b57cec5SDimitry Andric_LIBCPP_CONSTEXPR 659*0b57cec5SDimitry Andric__bitset<0, 0>::__bitset(unsigned long long) _NOEXCEPT 660*0b57cec5SDimitry Andric{ 661*0b57cec5SDimitry Andric} 662*0b57cec5SDimitry Andric 663*0b57cec5SDimitry Andrictemplate <size_t _Size> class _LIBCPP_TEMPLATE_VIS bitset; 664*0b57cec5SDimitry Andrictemplate <size_t _Size> struct hash<bitset<_Size> >; 665*0b57cec5SDimitry Andric 666*0b57cec5SDimitry Andrictemplate <size_t _Size> 667*0b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS bitset 668*0b57cec5SDimitry Andric : private __bitset<_Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1, _Size> 669*0b57cec5SDimitry Andric{ 670*0b57cec5SDimitry Andricpublic: 671*0b57cec5SDimitry Andric static const unsigned __n_words = _Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1; 672*0b57cec5SDimitry Andric typedef __bitset<__n_words, _Size> base; 673*0b57cec5SDimitry Andric 674*0b57cec5SDimitry Andricpublic: 675*0b57cec5SDimitry Andric typedef typename base::reference reference; 676*0b57cec5SDimitry Andric typedef typename base::const_reference const_reference; 677*0b57cec5SDimitry Andric 678*0b57cec5SDimitry Andric // 23.3.5.1 constructors: 679*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bitset() _NOEXCEPT {} 680*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 681*0b57cec5SDimitry Andric bitset(unsigned long long __v) _NOEXCEPT : base(__v) {} 682*0b57cec5SDimitry Andric template<class _CharT, class = _EnableIf<_IsCharLikeType<_CharT>::value> > 683*0b57cec5SDimitry Andric explicit bitset(const _CharT* __str, 684*0b57cec5SDimitry Andric typename basic_string<_CharT>::size_type __n = basic_string<_CharT>::npos, 685*0b57cec5SDimitry Andric _CharT __zero = _CharT('0'), _CharT __one = _CharT('1')); 686*0b57cec5SDimitry Andric template<class _CharT, class _Traits, class _Allocator> 687*0b57cec5SDimitry Andric explicit bitset(const basic_string<_CharT,_Traits,_Allocator>& __str, 688*0b57cec5SDimitry Andric typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos = 0, 689*0b57cec5SDimitry Andric typename basic_string<_CharT,_Traits,_Allocator>::size_type __n = 690*0b57cec5SDimitry Andric (basic_string<_CharT,_Traits,_Allocator>::npos), 691*0b57cec5SDimitry Andric _CharT __zero = _CharT('0'), _CharT __one = _CharT('1')); 692*0b57cec5SDimitry Andric 693*0b57cec5SDimitry Andric // 23.3.5.2 bitset operations: 694*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 695*0b57cec5SDimitry Andric bitset& operator&=(const bitset& __rhs) _NOEXCEPT; 696*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 697*0b57cec5SDimitry Andric bitset& operator|=(const bitset& __rhs) _NOEXCEPT; 698*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 699*0b57cec5SDimitry Andric bitset& operator^=(const bitset& __rhs) _NOEXCEPT; 700*0b57cec5SDimitry Andric bitset& operator<<=(size_t __pos) _NOEXCEPT; 701*0b57cec5SDimitry Andric bitset& operator>>=(size_t __pos) _NOEXCEPT; 702*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 703*0b57cec5SDimitry Andric bitset& set() _NOEXCEPT; 704*0b57cec5SDimitry Andric bitset& set(size_t __pos, bool __val = true); 705*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 706*0b57cec5SDimitry Andric bitset& reset() _NOEXCEPT; 707*0b57cec5SDimitry Andric bitset& reset(size_t __pos); 708*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 709*0b57cec5SDimitry Andric bitset operator~() const _NOEXCEPT; 710*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 711*0b57cec5SDimitry Andric bitset& flip() _NOEXCEPT; 712*0b57cec5SDimitry Andric bitset& flip(size_t __pos); 713*0b57cec5SDimitry Andric 714*0b57cec5SDimitry Andric // element access: 715*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 716*0b57cec5SDimitry Andric const_reference operator[](size_t __p) const {return base::__make_ref(__p);} 717*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY reference operator[](size_t __p) {return base::__make_ref(__p);} 718*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 719*0b57cec5SDimitry Andric unsigned long to_ulong() const; 720*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 721*0b57cec5SDimitry Andric unsigned long long to_ullong() const; 722*0b57cec5SDimitry Andric template <class _CharT, class _Traits, class _Allocator> 723*0b57cec5SDimitry Andric basic_string<_CharT, _Traits, _Allocator> to_string(_CharT __zero = _CharT('0'), 724*0b57cec5SDimitry Andric _CharT __one = _CharT('1')) const; 725*0b57cec5SDimitry Andric template <class _CharT, class _Traits> 726*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 727*0b57cec5SDimitry Andric basic_string<_CharT, _Traits, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'), 728*0b57cec5SDimitry Andric _CharT __one = _CharT('1')) const; 729*0b57cec5SDimitry Andric template <class _CharT> 730*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 731*0b57cec5SDimitry Andric basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'), 732*0b57cec5SDimitry Andric _CharT __one = _CharT('1')) const; 733*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 734*0b57cec5SDimitry Andric basic_string<char, char_traits<char>, allocator<char> > to_string(char __zero = '0', 735*0b57cec5SDimitry Andric char __one = '1') const; 736*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 737*0b57cec5SDimitry Andric size_t count() const _NOEXCEPT; 738*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR size_t size() const _NOEXCEPT {return _Size;} 739*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 740*0b57cec5SDimitry Andric bool operator==(const bitset& __rhs) const _NOEXCEPT; 741*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 742*0b57cec5SDimitry Andric bool operator!=(const bitset& __rhs) const _NOEXCEPT; 743*0b57cec5SDimitry Andric bool test(size_t __pos) const; 744*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 745*0b57cec5SDimitry Andric bool all() const _NOEXCEPT; 746*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 747*0b57cec5SDimitry Andric bool any() const _NOEXCEPT; 748*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY bool none() const _NOEXCEPT {return !any();} 749*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 750*0b57cec5SDimitry Andric bitset operator<<(size_t __pos) const _NOEXCEPT; 751*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 752*0b57cec5SDimitry Andric bitset operator>>(size_t __pos) const _NOEXCEPT; 753*0b57cec5SDimitry Andric 754*0b57cec5SDimitry Andricprivate: 755*0b57cec5SDimitry Andric 756*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 757*0b57cec5SDimitry Andric size_t __hash_code() const _NOEXCEPT {return base::__hash_code();} 758*0b57cec5SDimitry Andric 759*0b57cec5SDimitry Andric friend struct hash<bitset>; 760*0b57cec5SDimitry Andric}; 761*0b57cec5SDimitry Andric 762*0b57cec5SDimitry Andrictemplate <size_t _Size> 763*0b57cec5SDimitry Andrictemplate<class _CharT, class> 764*0b57cec5SDimitry Andricbitset<_Size>::bitset(const _CharT* __str, 765*0b57cec5SDimitry Andric typename basic_string<_CharT>::size_type __n, 766*0b57cec5SDimitry Andric _CharT __zero, _CharT __one) 767*0b57cec5SDimitry Andric{ 768*0b57cec5SDimitry Andric size_t __rlen = _VSTD::min(__n, char_traits<_CharT>::length(__str)); 769*0b57cec5SDimitry Andric for (size_t __i = 0; __i < __rlen; ++__i) 770*0b57cec5SDimitry Andric if (__str[__i] != __zero && __str[__i] != __one) 771*0b57cec5SDimitry Andric __throw_invalid_argument("bitset string ctor has invalid argument"); 772*0b57cec5SDimitry Andric 773*0b57cec5SDimitry Andric size_t _Mp = _VSTD::min(__rlen, _Size); 774*0b57cec5SDimitry Andric size_t __i = 0; 775*0b57cec5SDimitry Andric for (; __i < _Mp; ++__i) 776*0b57cec5SDimitry Andric { 777*0b57cec5SDimitry Andric _CharT __c = __str[_Mp - 1 - __i]; 778*0b57cec5SDimitry Andric if (__c == __zero) 779*0b57cec5SDimitry Andric (*this)[__i] = false; 780*0b57cec5SDimitry Andric else 781*0b57cec5SDimitry Andric (*this)[__i] = true; 782*0b57cec5SDimitry Andric } 783*0b57cec5SDimitry Andric _VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false); 784*0b57cec5SDimitry Andric} 785*0b57cec5SDimitry Andric 786*0b57cec5SDimitry Andrictemplate <size_t _Size> 787*0b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 788*0b57cec5SDimitry Andricbitset<_Size>::bitset(const basic_string<_CharT,_Traits,_Allocator>& __str, 789*0b57cec5SDimitry Andric typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos, 790*0b57cec5SDimitry Andric typename basic_string<_CharT,_Traits,_Allocator>::size_type __n, 791*0b57cec5SDimitry Andric _CharT __zero, _CharT __one) 792*0b57cec5SDimitry Andric{ 793*0b57cec5SDimitry Andric if (__pos > __str.size()) 794*0b57cec5SDimitry Andric __throw_out_of_range("bitset string pos out of range"); 795*0b57cec5SDimitry Andric 796*0b57cec5SDimitry Andric size_t __rlen = _VSTD::min(__n, __str.size() - __pos); 797*0b57cec5SDimitry Andric for (size_t __i = __pos; __i < __pos + __rlen; ++__i) 798*0b57cec5SDimitry Andric if (!_Traits::eq(__str[__i], __zero) && !_Traits::eq(__str[__i], __one)) 799*0b57cec5SDimitry Andric __throw_invalid_argument("bitset string ctor has invalid argument"); 800*0b57cec5SDimitry Andric 801*0b57cec5SDimitry Andric size_t _Mp = _VSTD::min(__rlen, _Size); 802*0b57cec5SDimitry Andric size_t __i = 0; 803*0b57cec5SDimitry Andric for (; __i < _Mp; ++__i) 804*0b57cec5SDimitry Andric { 805*0b57cec5SDimitry Andric _CharT __c = __str[__pos + _Mp - 1 - __i]; 806*0b57cec5SDimitry Andric if (_Traits::eq(__c, __zero)) 807*0b57cec5SDimitry Andric (*this)[__i] = false; 808*0b57cec5SDimitry Andric else 809*0b57cec5SDimitry Andric (*this)[__i] = true; 810*0b57cec5SDimitry Andric } 811*0b57cec5SDimitry Andric _VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false); 812*0b57cec5SDimitry Andric} 813*0b57cec5SDimitry Andric 814*0b57cec5SDimitry Andrictemplate <size_t _Size> 815*0b57cec5SDimitry Andricinline 816*0b57cec5SDimitry Andricbitset<_Size>& 817*0b57cec5SDimitry Andricbitset<_Size>::operator&=(const bitset& __rhs) _NOEXCEPT 818*0b57cec5SDimitry Andric{ 819*0b57cec5SDimitry Andric base::operator&=(__rhs); 820*0b57cec5SDimitry Andric return *this; 821*0b57cec5SDimitry Andric} 822*0b57cec5SDimitry Andric 823*0b57cec5SDimitry Andrictemplate <size_t _Size> 824*0b57cec5SDimitry Andricinline 825*0b57cec5SDimitry Andricbitset<_Size>& 826*0b57cec5SDimitry Andricbitset<_Size>::operator|=(const bitset& __rhs) _NOEXCEPT 827*0b57cec5SDimitry Andric{ 828*0b57cec5SDimitry Andric base::operator|=(__rhs); 829*0b57cec5SDimitry Andric return *this; 830*0b57cec5SDimitry Andric} 831*0b57cec5SDimitry Andric 832*0b57cec5SDimitry Andrictemplate <size_t _Size> 833*0b57cec5SDimitry Andricinline 834*0b57cec5SDimitry Andricbitset<_Size>& 835*0b57cec5SDimitry Andricbitset<_Size>::operator^=(const bitset& __rhs) _NOEXCEPT 836*0b57cec5SDimitry Andric{ 837*0b57cec5SDimitry Andric base::operator^=(__rhs); 838*0b57cec5SDimitry Andric return *this; 839*0b57cec5SDimitry Andric} 840*0b57cec5SDimitry Andric 841*0b57cec5SDimitry Andrictemplate <size_t _Size> 842*0b57cec5SDimitry Andricbitset<_Size>& 843*0b57cec5SDimitry Andricbitset<_Size>::operator<<=(size_t __pos) _NOEXCEPT 844*0b57cec5SDimitry Andric{ 845*0b57cec5SDimitry Andric __pos = _VSTD::min(__pos, _Size); 846*0b57cec5SDimitry Andric _VSTD::copy_backward(base::__make_iter(0), base::__make_iter(_Size - __pos), base::__make_iter(_Size)); 847*0b57cec5SDimitry Andric _VSTD::fill_n(base::__make_iter(0), __pos, false); 848*0b57cec5SDimitry Andric return *this; 849*0b57cec5SDimitry Andric} 850*0b57cec5SDimitry Andric 851*0b57cec5SDimitry Andrictemplate <size_t _Size> 852*0b57cec5SDimitry Andricbitset<_Size>& 853*0b57cec5SDimitry Andricbitset<_Size>::operator>>=(size_t __pos) _NOEXCEPT 854*0b57cec5SDimitry Andric{ 855*0b57cec5SDimitry Andric __pos = _VSTD::min(__pos, _Size); 856*0b57cec5SDimitry Andric _VSTD::copy(base::__make_iter(__pos), base::__make_iter(_Size), base::__make_iter(0)); 857*0b57cec5SDimitry Andric _VSTD::fill_n(base::__make_iter(_Size - __pos), __pos, false); 858*0b57cec5SDimitry Andric return *this; 859*0b57cec5SDimitry Andric} 860*0b57cec5SDimitry Andric 861*0b57cec5SDimitry Andrictemplate <size_t _Size> 862*0b57cec5SDimitry Andricinline 863*0b57cec5SDimitry Andricbitset<_Size>& 864*0b57cec5SDimitry Andricbitset<_Size>::set() _NOEXCEPT 865*0b57cec5SDimitry Andric{ 866*0b57cec5SDimitry Andric _VSTD::fill_n(base::__make_iter(0), _Size, true); 867*0b57cec5SDimitry Andric return *this; 868*0b57cec5SDimitry Andric} 869*0b57cec5SDimitry Andric 870*0b57cec5SDimitry Andrictemplate <size_t _Size> 871*0b57cec5SDimitry Andricbitset<_Size>& 872*0b57cec5SDimitry Andricbitset<_Size>::set(size_t __pos, bool __val) 873*0b57cec5SDimitry Andric{ 874*0b57cec5SDimitry Andric if (__pos >= _Size) 875*0b57cec5SDimitry Andric __throw_out_of_range("bitset set argument out of range"); 876*0b57cec5SDimitry Andric 877*0b57cec5SDimitry Andric (*this)[__pos] = __val; 878*0b57cec5SDimitry Andric return *this; 879*0b57cec5SDimitry Andric} 880*0b57cec5SDimitry Andric 881*0b57cec5SDimitry Andrictemplate <size_t _Size> 882*0b57cec5SDimitry Andricinline 883*0b57cec5SDimitry Andricbitset<_Size>& 884*0b57cec5SDimitry Andricbitset<_Size>::reset() _NOEXCEPT 885*0b57cec5SDimitry Andric{ 886*0b57cec5SDimitry Andric _VSTD::fill_n(base::__make_iter(0), _Size, false); 887*0b57cec5SDimitry Andric return *this; 888*0b57cec5SDimitry Andric} 889*0b57cec5SDimitry Andric 890*0b57cec5SDimitry Andrictemplate <size_t _Size> 891*0b57cec5SDimitry Andricbitset<_Size>& 892*0b57cec5SDimitry Andricbitset<_Size>::reset(size_t __pos) 893*0b57cec5SDimitry Andric{ 894*0b57cec5SDimitry Andric if (__pos >= _Size) 895*0b57cec5SDimitry Andric __throw_out_of_range("bitset reset argument out of range"); 896*0b57cec5SDimitry Andric 897*0b57cec5SDimitry Andric (*this)[__pos] = false; 898*0b57cec5SDimitry Andric return *this; 899*0b57cec5SDimitry Andric} 900*0b57cec5SDimitry Andric 901*0b57cec5SDimitry Andrictemplate <size_t _Size> 902*0b57cec5SDimitry Andricinline 903*0b57cec5SDimitry Andricbitset<_Size> 904*0b57cec5SDimitry Andricbitset<_Size>::operator~() const _NOEXCEPT 905*0b57cec5SDimitry Andric{ 906*0b57cec5SDimitry Andric bitset __x(*this); 907*0b57cec5SDimitry Andric __x.flip(); 908*0b57cec5SDimitry Andric return __x; 909*0b57cec5SDimitry Andric} 910*0b57cec5SDimitry Andric 911*0b57cec5SDimitry Andrictemplate <size_t _Size> 912*0b57cec5SDimitry Andricinline 913*0b57cec5SDimitry Andricbitset<_Size>& 914*0b57cec5SDimitry Andricbitset<_Size>::flip() _NOEXCEPT 915*0b57cec5SDimitry Andric{ 916*0b57cec5SDimitry Andric base::flip(); 917*0b57cec5SDimitry Andric return *this; 918*0b57cec5SDimitry Andric} 919*0b57cec5SDimitry Andric 920*0b57cec5SDimitry Andrictemplate <size_t _Size> 921*0b57cec5SDimitry Andricbitset<_Size>& 922*0b57cec5SDimitry Andricbitset<_Size>::flip(size_t __pos) 923*0b57cec5SDimitry Andric{ 924*0b57cec5SDimitry Andric if (__pos >= _Size) 925*0b57cec5SDimitry Andric __throw_out_of_range("bitset flip argument out of range"); 926*0b57cec5SDimitry Andric 927*0b57cec5SDimitry Andric reference r = base::__make_ref(__pos); 928*0b57cec5SDimitry Andric r = ~r; 929*0b57cec5SDimitry Andric return *this; 930*0b57cec5SDimitry Andric} 931*0b57cec5SDimitry Andric 932*0b57cec5SDimitry Andrictemplate <size_t _Size> 933*0b57cec5SDimitry Andricinline 934*0b57cec5SDimitry Andricunsigned long 935*0b57cec5SDimitry Andricbitset<_Size>::to_ulong() const 936*0b57cec5SDimitry Andric{ 937*0b57cec5SDimitry Andric return base::to_ulong(); 938*0b57cec5SDimitry Andric} 939*0b57cec5SDimitry Andric 940*0b57cec5SDimitry Andrictemplate <size_t _Size> 941*0b57cec5SDimitry Andricinline 942*0b57cec5SDimitry Andricunsigned long long 943*0b57cec5SDimitry Andricbitset<_Size>::to_ullong() const 944*0b57cec5SDimitry Andric{ 945*0b57cec5SDimitry Andric return base::to_ullong(); 946*0b57cec5SDimitry Andric} 947*0b57cec5SDimitry Andric 948*0b57cec5SDimitry Andrictemplate <size_t _Size> 949*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 950*0b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator> 951*0b57cec5SDimitry Andricbitset<_Size>::to_string(_CharT __zero, _CharT __one) const 952*0b57cec5SDimitry Andric{ 953*0b57cec5SDimitry Andric basic_string<_CharT, _Traits, _Allocator> __r(_Size, __zero); 954*0b57cec5SDimitry Andric for (size_t __i = 0; __i < _Size; ++__i) 955*0b57cec5SDimitry Andric { 956*0b57cec5SDimitry Andric if ((*this)[__i]) 957*0b57cec5SDimitry Andric __r[_Size - 1 - __i] = __one; 958*0b57cec5SDimitry Andric } 959*0b57cec5SDimitry Andric return __r; 960*0b57cec5SDimitry Andric} 961*0b57cec5SDimitry Andric 962*0b57cec5SDimitry Andrictemplate <size_t _Size> 963*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits> 964*0b57cec5SDimitry Andricinline 965*0b57cec5SDimitry Andricbasic_string<_CharT, _Traits, allocator<_CharT> > 966*0b57cec5SDimitry Andricbitset<_Size>::to_string(_CharT __zero, _CharT __one) const 967*0b57cec5SDimitry Andric{ 968*0b57cec5SDimitry Andric return to_string<_CharT, _Traits, allocator<_CharT> >(__zero, __one); 969*0b57cec5SDimitry Andric} 970*0b57cec5SDimitry Andric 971*0b57cec5SDimitry Andrictemplate <size_t _Size> 972*0b57cec5SDimitry Andrictemplate <class _CharT> 973*0b57cec5SDimitry Andricinline 974*0b57cec5SDimitry Andricbasic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > 975*0b57cec5SDimitry Andricbitset<_Size>::to_string(_CharT __zero, _CharT __one) const 976*0b57cec5SDimitry Andric{ 977*0b57cec5SDimitry Andric return to_string<_CharT, char_traits<_CharT>, allocator<_CharT> >(__zero, __one); 978*0b57cec5SDimitry Andric} 979*0b57cec5SDimitry Andric 980*0b57cec5SDimitry Andrictemplate <size_t _Size> 981*0b57cec5SDimitry Andricinline 982*0b57cec5SDimitry Andricbasic_string<char, char_traits<char>, allocator<char> > 983*0b57cec5SDimitry Andricbitset<_Size>::to_string(char __zero, char __one) const 984*0b57cec5SDimitry Andric{ 985*0b57cec5SDimitry Andric return to_string<char, char_traits<char>, allocator<char> >(__zero, __one); 986*0b57cec5SDimitry Andric} 987*0b57cec5SDimitry Andric 988*0b57cec5SDimitry Andrictemplate <size_t _Size> 989*0b57cec5SDimitry Andricinline 990*0b57cec5SDimitry Andricsize_t 991*0b57cec5SDimitry Andricbitset<_Size>::count() const _NOEXCEPT 992*0b57cec5SDimitry Andric{ 993*0b57cec5SDimitry Andric return static_cast<size_t>(__count_bool_true(base::__make_iter(0), _Size)); 994*0b57cec5SDimitry Andric} 995*0b57cec5SDimitry Andric 996*0b57cec5SDimitry Andrictemplate <size_t _Size> 997*0b57cec5SDimitry Andricinline 998*0b57cec5SDimitry Andricbool 999*0b57cec5SDimitry Andricbitset<_Size>::operator==(const bitset& __rhs) const _NOEXCEPT 1000*0b57cec5SDimitry Andric{ 1001*0b57cec5SDimitry Andric return _VSTD::equal(base::__make_iter(0), base::__make_iter(_Size), __rhs.__make_iter(0)); 1002*0b57cec5SDimitry Andric} 1003*0b57cec5SDimitry Andric 1004*0b57cec5SDimitry Andrictemplate <size_t _Size> 1005*0b57cec5SDimitry Andricinline 1006*0b57cec5SDimitry Andricbool 1007*0b57cec5SDimitry Andricbitset<_Size>::operator!=(const bitset& __rhs) const _NOEXCEPT 1008*0b57cec5SDimitry Andric{ 1009*0b57cec5SDimitry Andric return !(*this == __rhs); 1010*0b57cec5SDimitry Andric} 1011*0b57cec5SDimitry Andric 1012*0b57cec5SDimitry Andrictemplate <size_t _Size> 1013*0b57cec5SDimitry Andricbool 1014*0b57cec5SDimitry Andricbitset<_Size>::test(size_t __pos) const 1015*0b57cec5SDimitry Andric{ 1016*0b57cec5SDimitry Andric if (__pos >= _Size) 1017*0b57cec5SDimitry Andric __throw_out_of_range("bitset test argument out of range"); 1018*0b57cec5SDimitry Andric 1019*0b57cec5SDimitry Andric return (*this)[__pos]; 1020*0b57cec5SDimitry Andric} 1021*0b57cec5SDimitry Andric 1022*0b57cec5SDimitry Andrictemplate <size_t _Size> 1023*0b57cec5SDimitry Andricinline 1024*0b57cec5SDimitry Andricbool 1025*0b57cec5SDimitry Andricbitset<_Size>::all() const _NOEXCEPT 1026*0b57cec5SDimitry Andric{ 1027*0b57cec5SDimitry Andric return base::all(); 1028*0b57cec5SDimitry Andric} 1029*0b57cec5SDimitry Andric 1030*0b57cec5SDimitry Andrictemplate <size_t _Size> 1031*0b57cec5SDimitry Andricinline 1032*0b57cec5SDimitry Andricbool 1033*0b57cec5SDimitry Andricbitset<_Size>::any() const _NOEXCEPT 1034*0b57cec5SDimitry Andric{ 1035*0b57cec5SDimitry Andric return base::any(); 1036*0b57cec5SDimitry Andric} 1037*0b57cec5SDimitry Andric 1038*0b57cec5SDimitry Andrictemplate <size_t _Size> 1039*0b57cec5SDimitry Andricinline 1040*0b57cec5SDimitry Andricbitset<_Size> 1041*0b57cec5SDimitry Andricbitset<_Size>::operator<<(size_t __pos) const _NOEXCEPT 1042*0b57cec5SDimitry Andric{ 1043*0b57cec5SDimitry Andric bitset __r = *this; 1044*0b57cec5SDimitry Andric __r <<= __pos; 1045*0b57cec5SDimitry Andric return __r; 1046*0b57cec5SDimitry Andric} 1047*0b57cec5SDimitry Andric 1048*0b57cec5SDimitry Andrictemplate <size_t _Size> 1049*0b57cec5SDimitry Andricinline 1050*0b57cec5SDimitry Andricbitset<_Size> 1051*0b57cec5SDimitry Andricbitset<_Size>::operator>>(size_t __pos) const _NOEXCEPT 1052*0b57cec5SDimitry Andric{ 1053*0b57cec5SDimitry Andric bitset __r = *this; 1054*0b57cec5SDimitry Andric __r >>= __pos; 1055*0b57cec5SDimitry Andric return __r; 1056*0b57cec5SDimitry Andric} 1057*0b57cec5SDimitry Andric 1058*0b57cec5SDimitry Andrictemplate <size_t _Size> 1059*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 1060*0b57cec5SDimitry Andricbitset<_Size> 1061*0b57cec5SDimitry Andricoperator&(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT 1062*0b57cec5SDimitry Andric{ 1063*0b57cec5SDimitry Andric bitset<_Size> __r = __x; 1064*0b57cec5SDimitry Andric __r &= __y; 1065*0b57cec5SDimitry Andric return __r; 1066*0b57cec5SDimitry Andric} 1067*0b57cec5SDimitry Andric 1068*0b57cec5SDimitry Andrictemplate <size_t _Size> 1069*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 1070*0b57cec5SDimitry Andricbitset<_Size> 1071*0b57cec5SDimitry Andricoperator|(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT 1072*0b57cec5SDimitry Andric{ 1073*0b57cec5SDimitry Andric bitset<_Size> __r = __x; 1074*0b57cec5SDimitry Andric __r |= __y; 1075*0b57cec5SDimitry Andric return __r; 1076*0b57cec5SDimitry Andric} 1077*0b57cec5SDimitry Andric 1078*0b57cec5SDimitry Andrictemplate <size_t _Size> 1079*0b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 1080*0b57cec5SDimitry Andricbitset<_Size> 1081*0b57cec5SDimitry Andricoperator^(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT 1082*0b57cec5SDimitry Andric{ 1083*0b57cec5SDimitry Andric bitset<_Size> __r = __x; 1084*0b57cec5SDimitry Andric __r ^= __y; 1085*0b57cec5SDimitry Andric return __r; 1086*0b57cec5SDimitry Andric} 1087*0b57cec5SDimitry Andric 1088*0b57cec5SDimitry Andrictemplate <size_t _Size> 1089*0b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS hash<bitset<_Size> > 1090*0b57cec5SDimitry Andric : public unary_function<bitset<_Size>, size_t> 1091*0b57cec5SDimitry Andric{ 1092*0b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1093*0b57cec5SDimitry Andric size_t operator()(const bitset<_Size>& __bs) const _NOEXCEPT 1094*0b57cec5SDimitry Andric {return __bs.__hash_code();} 1095*0b57cec5SDimitry Andric}; 1096*0b57cec5SDimitry Andric 1097*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, size_t _Size> 1098*0b57cec5SDimitry Andricbasic_istream<_CharT, _Traits>& 1099*0b57cec5SDimitry Andricoperator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x); 1100*0b57cec5SDimitry Andric 1101*0b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, size_t _Size> 1102*0b57cec5SDimitry Andricbasic_ostream<_CharT, _Traits>& 1103*0b57cec5SDimitry Andricoperator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x); 1104*0b57cec5SDimitry Andric 1105*0b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD 1106*0b57cec5SDimitry Andric 1107*0b57cec5SDimitry Andric_LIBCPP_POP_MACROS 1108*0b57cec5SDimitry Andric 1109*0b57cec5SDimitry Andric#endif // _LIBCPP_BITSET 1110