10b57cec5SDimitry Andric// -*- C++ -*- 2349cc55cSDimitry Andric//===----------------------------------------------------------------------===// 30b57cec5SDimitry Andric// 40b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 50b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information. 60b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 70b57cec5SDimitry Andric// 80b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 90b57cec5SDimitry Andric 100b57cec5SDimitry Andric#ifndef _LIBCPP_BITSET 110b57cec5SDimitry Andric#define _LIBCPP_BITSET 120b57cec5SDimitry Andric 130b57cec5SDimitry Andric/* 140b57cec5SDimitry Andric bitset synopsis 150b57cec5SDimitry Andric 160b57cec5SDimitry Andricnamespace std 170b57cec5SDimitry Andric{ 180b57cec5SDimitry Andric 190b57cec5SDimitry Andricnamespace std { 200b57cec5SDimitry Andric 210b57cec5SDimitry Andrictemplate <size_t N> 220b57cec5SDimitry Andricclass bitset 230b57cec5SDimitry Andric{ 240b57cec5SDimitry Andricpublic: 250b57cec5SDimitry Andric // bit reference: 260b57cec5SDimitry Andric class reference 270b57cec5SDimitry Andric { 280b57cec5SDimitry Andric friend class bitset; 290b57cec5SDimitry Andric reference() noexcept; 300b57cec5SDimitry Andric public: 310b57cec5SDimitry Andric ~reference() noexcept; 320b57cec5SDimitry Andric reference& operator=(bool x) noexcept; // for b[i] = x; 330b57cec5SDimitry Andric reference& operator=(const reference&) noexcept; // for b[i] = b[j]; 340b57cec5SDimitry Andric bool operator~() const noexcept; // flips the bit 350b57cec5SDimitry Andric operator bool() const noexcept; // for x = b[i]; 360b57cec5SDimitry Andric reference& flip() noexcept; // for b[i].flip(); 370b57cec5SDimitry Andric }; 380b57cec5SDimitry Andric 390b57cec5SDimitry Andric // 23.3.5.1 constructors: 400b57cec5SDimitry Andric constexpr bitset() noexcept; 410b57cec5SDimitry Andric constexpr bitset(unsigned long long val) noexcept; 420b57cec5SDimitry Andric template <class charT> 430b57cec5SDimitry Andric explicit bitset(const charT* str, 440b57cec5SDimitry Andric typename basic_string<charT>::size_type n = basic_string<charT>::npos, 45*bdd1243dSDimitry Andric charT zero = charT('0'), charT one = charT('1')); // constexpr since C++23 460b57cec5SDimitry Andric template<class charT, class traits, class Allocator> 470b57cec5SDimitry Andric explicit bitset(const basic_string<charT,traits,Allocator>& str, 480b57cec5SDimitry Andric typename basic_string<charT,traits,Allocator>::size_type pos = 0, 490b57cec5SDimitry Andric typename basic_string<charT,traits,Allocator>::size_type n = 500b57cec5SDimitry Andric basic_string<charT,traits,Allocator>::npos, 51*bdd1243dSDimitry Andric charT zero = charT('0'), charT one = charT('1')); // constexpr since C++23 520b57cec5SDimitry Andric 530b57cec5SDimitry Andric // 23.3.5.2 bitset operations: 54*bdd1243dSDimitry Andric bitset& operator&=(const bitset& rhs) noexcept; // constexpr since C++23 55*bdd1243dSDimitry Andric bitset& operator|=(const bitset& rhs) noexcept; // constexpr since C++23 56*bdd1243dSDimitry Andric bitset& operator^=(const bitset& rhs) noexcept; // constexpr since C++23 57*bdd1243dSDimitry Andric bitset& operator<<=(size_t pos) noexcept; // constexpr since C++23 58*bdd1243dSDimitry Andric bitset& operator>>=(size_t pos) noexcept; // constexpr since C++23 59*bdd1243dSDimitry Andric bitset& set() noexcept; // constexpr since C++23 60*bdd1243dSDimitry Andric bitset& set(size_t pos, bool val = true); // constexpr since C++23 61*bdd1243dSDimitry Andric bitset& reset() noexcept; // constexpr since C++23 62*bdd1243dSDimitry Andric bitset& reset(size_t pos); // constexpr since C++23 63*bdd1243dSDimitry Andric bitset operator~() const noexcept; // constexpr since C++23 64*bdd1243dSDimitry Andric bitset& flip() noexcept; // constexpr since C++23 65*bdd1243dSDimitry Andric bitset& flip(size_t pos); // constexpr since C++23 660b57cec5SDimitry Andric 670b57cec5SDimitry Andric // element access: 68*bdd1243dSDimitry Andric constexpr bool operator[](size_t pos) const; 69*bdd1243dSDimitry Andric reference operator[](size_t pos); // constexpr since C++23 70*bdd1243dSDimitry Andric unsigned long to_ulong() const; // constexpr since C++23 71*bdd1243dSDimitry Andric unsigned long long to_ullong() const; // constexpr since C++23 72*bdd1243dSDimitry Andric template <class charT, class traits, class Allocator> // constexpr since C++23 730b57cec5SDimitry Andric basic_string<charT, traits, Allocator> to_string(charT zero = charT('0'), charT one = charT('1')) const; 74*bdd1243dSDimitry Andric template <class charT, class traits> // constexpr since C++23 750b57cec5SDimitry Andric basic_string<charT, traits, allocator<charT> > to_string(charT zero = charT('0'), charT one = charT('1')) const; 76*bdd1243dSDimitry Andric template <class charT> // constexpr since C++23 770b57cec5SDimitry Andric basic_string<charT, char_traits<charT>, allocator<charT> > to_string(charT zero = charT('0'), charT one = charT('1')) const; 78*bdd1243dSDimitry Andric basic_string<char, char_traits<char>, allocator<char> > to_string(char zero = '0', char one = '1') const; // constexpr since C++23 79*bdd1243dSDimitry Andric size_t count() const noexcept; // constexpr since C++23 80*bdd1243dSDimitry Andric constexpr size_t size() const noexcept; // constexpr since C++23 81*bdd1243dSDimitry Andric bool operator==(const bitset& rhs) const noexcept; // constexpr since C++23 82*bdd1243dSDimitry Andric bool operator!=(const bitset& rhs) const noexcept; // constexpr since C++23 83*bdd1243dSDimitry Andric bool test(size_t pos) const; // constexpr since C++23 84*bdd1243dSDimitry Andric bool all() const noexcept; // constexpr since C++23 85*bdd1243dSDimitry Andric bool any() const noexcept; // constexpr since C++23 86*bdd1243dSDimitry Andric bool none() const noexcept; // constexpr since C++23 87*bdd1243dSDimitry Andric bitset<N> operator<<(size_t pos) const noexcept; // constexpr since C++23 88*bdd1243dSDimitry Andric bitset<N> operator>>(size_t pos) const noexcept; // constexpr since C++23 890b57cec5SDimitry Andric}; 900b57cec5SDimitry Andric 910b57cec5SDimitry Andric// 23.3.5.3 bitset operators: 920b57cec5SDimitry Andrictemplate <size_t N> 93*bdd1243dSDimitry Andricbitset<N> operator&(const bitset<N>&, const bitset<N>&) noexcept; // constexpr since C++23 940b57cec5SDimitry Andric 950b57cec5SDimitry Andrictemplate <size_t N> 96*bdd1243dSDimitry Andricbitset<N> operator|(const bitset<N>&, const bitset<N>&) noexcept; // constexpr since C++23 970b57cec5SDimitry Andric 980b57cec5SDimitry Andrictemplate <size_t N> 99*bdd1243dSDimitry Andricbitset<N> operator^(const bitset<N>&, const bitset<N>&) noexcept; // constexpr since C++23 1000b57cec5SDimitry Andric 1010b57cec5SDimitry Andrictemplate <class charT, class traits, size_t N> 1020b57cec5SDimitry Andricbasic_istream<charT, traits>& 1030b57cec5SDimitry Andricoperator>>(basic_istream<charT, traits>& is, bitset<N>& x); 1040b57cec5SDimitry Andric 1050b57cec5SDimitry Andrictemplate <class charT, class traits, size_t N> 1060b57cec5SDimitry Andricbasic_ostream<charT, traits>& 1070b57cec5SDimitry Andricoperator<<(basic_ostream<charT, traits>& os, const bitset<N>& x); 1080b57cec5SDimitry Andric 1090b57cec5SDimitry Andrictemplate <size_t N> struct hash<std::bitset<N>>; 1100b57cec5SDimitry Andric 1110b57cec5SDimitry Andric} // std 1120b57cec5SDimitry Andric 1130b57cec5SDimitry Andric*/ 1140b57cec5SDimitry Andric 11581ad6265SDimitry Andric#include <__algorithm/fill.h> 11681ad6265SDimitry Andric#include <__assert> // all public C++ headers provide the assertion handler 1170b57cec5SDimitry Andric#include <__bit_reference> 11804eeddc0SDimitry Andric#include <__config> 11981ad6265SDimitry Andric#include <__functional/hash.h> 12081ad6265SDimitry Andric#include <__functional/unary_function.h> 121*bdd1243dSDimitry Andric#include <__type_traits/is_char_like_type.h> 122fe6060f1SDimitry Andric#include <climits> 123fe6060f1SDimitry Andric#include <cstddef> 124fe6060f1SDimitry Andric#include <stdexcept> 12504eeddc0SDimitry Andric#include <version> 1260b57cec5SDimitry Andric 12781ad6265SDimitry Andric// standard-mandated includes 128*bdd1243dSDimitry Andric 129*bdd1243dSDimitry Andric// [bitset.syn] 13081ad6265SDimitry Andric#include <iosfwd> 13181ad6265SDimitry Andric#include <string> 13281ad6265SDimitry Andric 1330b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 1340b57cec5SDimitry Andric# pragma GCC system_header 1350b57cec5SDimitry Andric#endif 1360b57cec5SDimitry Andric 1370b57cec5SDimitry Andric_LIBCPP_PUSH_MACROS 1380b57cec5SDimitry Andric#include <__undef_macros> 1390b57cec5SDimitry Andric 1400b57cec5SDimitry Andric 1410b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD 1420b57cec5SDimitry Andric 1430b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 1440b57cec5SDimitry Andricclass __bitset; 1450b57cec5SDimitry Andric 1460b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 1470b57cec5SDimitry Andricstruct __has_storage_type<__bitset<_N_words, _Size> > 1480b57cec5SDimitry Andric{ 1490b57cec5SDimitry Andric static const bool value = true; 1500b57cec5SDimitry Andric}; 1510b57cec5SDimitry Andric 1520b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 1530b57cec5SDimitry Andricclass __bitset 1540b57cec5SDimitry Andric{ 1550b57cec5SDimitry Andricpublic: 1560b57cec5SDimitry Andric typedef ptrdiff_t difference_type; 1570b57cec5SDimitry Andric typedef size_t size_type; 1580b57cec5SDimitry Andric typedef size_type __storage_type; 1590b57cec5SDimitry Andricprotected: 1600b57cec5SDimitry Andric typedef __bitset __self; 1610b57cec5SDimitry Andric typedef __storage_type* __storage_pointer; 1620b57cec5SDimitry Andric typedef const __storage_type* __const_storage_pointer; 1630b57cec5SDimitry Andric static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT); 1640b57cec5SDimitry Andric 1650b57cec5SDimitry Andric friend class __bit_reference<__bitset>; 1660b57cec5SDimitry Andric friend class __bit_const_reference<__bitset>; 1670b57cec5SDimitry Andric friend class __bit_iterator<__bitset, false>; 1680b57cec5SDimitry Andric friend class __bit_iterator<__bitset, true>; 1690b57cec5SDimitry Andric friend struct __bit_array<__bitset>; 1700b57cec5SDimitry Andric 1710b57cec5SDimitry Andric __storage_type __first_[_N_words]; 1720b57cec5SDimitry Andric 1730b57cec5SDimitry Andric typedef __bit_reference<__bitset> reference; 1740b57cec5SDimitry Andric typedef __bit_const_reference<__bitset> const_reference; 1750b57cec5SDimitry Andric typedef __bit_iterator<__bitset, false> iterator; 1760b57cec5SDimitry Andric typedef __bit_iterator<__bitset, true> const_iterator; 1770b57cec5SDimitry Andric 1780b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1790b57cec5SDimitry Andric _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT; 1800b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 1810b57cec5SDimitry Andric explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT; 1820b57cec5SDimitry Andric 183*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 reference __make_ref(size_t __pos) _NOEXCEPT 1840b57cec5SDimitry Andric {return reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);} 1850b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT 1860b57cec5SDimitry Andric {return const_reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);} 187*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 iterator __make_iter(size_t __pos) _NOEXCEPT 1880b57cec5SDimitry Andric {return iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);} 189*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 const_iterator __make_iter(size_t __pos) const _NOEXCEPT 1900b57cec5SDimitry Andric {return const_iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);} 1910b57cec5SDimitry Andric 192*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 1930b57cec5SDimitry Andric void operator&=(const __bitset& __v) _NOEXCEPT; 194*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 1950b57cec5SDimitry Andric void operator|=(const __bitset& __v) _NOEXCEPT; 196*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 1970b57cec5SDimitry Andric void operator^=(const __bitset& __v) _NOEXCEPT; 1980b57cec5SDimitry Andric 199*bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void flip() _NOEXCEPT; 200*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong() const 2010b57cec5SDimitry Andric {return to_ulong(integral_constant<bool, _Size < sizeof(unsigned long) * CHAR_BIT>());} 202*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong() const 2030b57cec5SDimitry Andric {return to_ullong(integral_constant<bool, _Size < sizeof(unsigned long long) * CHAR_BIT>());} 2040b57cec5SDimitry Andric 205*bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT; 206*bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT; 2070b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2080b57cec5SDimitry Andric size_t __hash_code() const _NOEXCEPT; 2090b57cec5SDimitry Andricprivate: 2100b57cec5SDimitry Andric#ifdef _LIBCPP_CXX03_LANG 2110b57cec5SDimitry Andric void __init(unsigned long long __v, false_type) _NOEXCEPT; 2120b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2130b57cec5SDimitry Andric void __init(unsigned long long __v, true_type) _NOEXCEPT; 2140b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 215*bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 2160b57cec5SDimitry Andric unsigned long to_ulong(false_type) const; 217*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 2180b57cec5SDimitry Andric unsigned long to_ulong(true_type) const; 219*bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 2200b57cec5SDimitry Andric unsigned long long to_ullong(false_type) const; 221*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 2220b57cec5SDimitry Andric unsigned long long to_ullong(true_type) const; 223*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 2240b57cec5SDimitry Andric unsigned long long to_ullong(true_type, false_type) const; 225*bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 2260b57cec5SDimitry Andric unsigned long long to_ullong(true_type, true_type) const; 2270b57cec5SDimitry Andric}; 2280b57cec5SDimitry Andric 2290b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 2300b57cec5SDimitry Andricinline 2310b57cec5SDimitry Andric_LIBCPP_CONSTEXPR 2320b57cec5SDimitry Andric__bitset<_N_words, _Size>::__bitset() _NOEXCEPT 2330b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 2340b57cec5SDimitry Andric : __first_{0} 2350b57cec5SDimitry Andric#endif 2360b57cec5SDimitry Andric{ 2370b57cec5SDimitry Andric#ifdef _LIBCPP_CXX03_LANG 2380b57cec5SDimitry Andric _VSTD::fill_n(__first_, _N_words, __storage_type(0)); 2390b57cec5SDimitry Andric#endif 2400b57cec5SDimitry Andric} 2410b57cec5SDimitry Andric 2420b57cec5SDimitry Andric#ifdef _LIBCPP_CXX03_LANG 2430b57cec5SDimitry Andric 2440b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 2450b57cec5SDimitry Andricvoid 2460b57cec5SDimitry Andric__bitset<_N_words, _Size>::__init(unsigned long long __v, false_type) _NOEXCEPT 2470b57cec5SDimitry Andric{ 2480b57cec5SDimitry Andric __storage_type __t[sizeof(unsigned long long) / sizeof(__storage_type)]; 2490b57cec5SDimitry Andric size_t __sz = _Size; 2500b57cec5SDimitry Andric for (size_t __i = 0; __i < sizeof(__t)/sizeof(__t[0]); ++__i, __v >>= __bits_per_word, __sz -= __bits_per_word ) 2510b57cec5SDimitry Andric if ( __sz < __bits_per_word) 2520b57cec5SDimitry Andric __t[__i] = static_cast<__storage_type>(__v) & ( 1ULL << __sz ) - 1; 2530b57cec5SDimitry Andric else 2540b57cec5SDimitry Andric __t[__i] = static_cast<__storage_type>(__v); 2550b57cec5SDimitry Andric 2560b57cec5SDimitry Andric _VSTD::copy(__t, __t + sizeof(__t)/sizeof(__t[0]), __first_); 2570b57cec5SDimitry Andric _VSTD::fill(__first_ + sizeof(__t)/sizeof(__t[0]), __first_ + sizeof(__first_)/sizeof(__first_[0]), 2580b57cec5SDimitry Andric __storage_type(0)); 2590b57cec5SDimitry Andric} 2600b57cec5SDimitry Andric 2610b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 2620b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 2630b57cec5SDimitry Andricvoid 2640b57cec5SDimitry Andric__bitset<_N_words, _Size>::__init(unsigned long long __v, true_type) _NOEXCEPT 2650b57cec5SDimitry Andric{ 2660b57cec5SDimitry Andric __first_[0] = __v; 2670b57cec5SDimitry Andric if (_Size < __bits_per_word) 2680b57cec5SDimitry Andric __first_[0] &= ( 1ULL << _Size ) - 1; 2690b57cec5SDimitry Andric 2700b57cec5SDimitry Andric _VSTD::fill(__first_ + 1, __first_ + sizeof(__first_)/sizeof(__first_[0]), __storage_type(0)); 2710b57cec5SDimitry Andric} 2720b57cec5SDimitry Andric 2730b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 2740b57cec5SDimitry Andric 2750b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 2760b57cec5SDimitry Andricinline 2770b57cec5SDimitry Andric_LIBCPP_CONSTEXPR 2780b57cec5SDimitry Andric__bitset<_N_words, _Size>::__bitset(unsigned long long __v) _NOEXCEPT 2790b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 2800b57cec5SDimitry Andric#if __SIZEOF_SIZE_T__ == 8 2810b57cec5SDimitry Andric : __first_{__v} 2820b57cec5SDimitry Andric#elif __SIZEOF_SIZE_T__ == 4 2830b57cec5SDimitry Andric : __first_{static_cast<__storage_type>(__v), 2840b57cec5SDimitry Andric _Size >= 2 * __bits_per_word ? static_cast<__storage_type>(__v >> __bits_per_word) 2850b57cec5SDimitry Andric : static_cast<__storage_type>((__v >> __bits_per_word) & (__storage_type(1) << (_Size - __bits_per_word)) - 1)} 2860b57cec5SDimitry Andric#else 2870b57cec5SDimitry Andric#error This constructor has not been ported to this platform 2880b57cec5SDimitry Andric#endif 2890b57cec5SDimitry Andric#endif 2900b57cec5SDimitry Andric{ 2910b57cec5SDimitry Andric#ifdef _LIBCPP_CXX03_LANG 2920b57cec5SDimitry Andric __init(__v, integral_constant<bool, sizeof(unsigned long long) == sizeof(__storage_type)>()); 2930b57cec5SDimitry Andric#endif 2940b57cec5SDimitry Andric} 2950b57cec5SDimitry Andric 2960b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 2970b57cec5SDimitry Andricinline 298*bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void 2990b57cec5SDimitry Andric__bitset<_N_words, _Size>::operator&=(const __bitset& __v) _NOEXCEPT 3000b57cec5SDimitry Andric{ 3010b57cec5SDimitry Andric for (size_type __i = 0; __i < _N_words; ++__i) 3020b57cec5SDimitry Andric __first_[__i] &= __v.__first_[__i]; 3030b57cec5SDimitry Andric} 3040b57cec5SDimitry Andric 3050b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 3060b57cec5SDimitry Andricinline 307*bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void 3080b57cec5SDimitry Andric__bitset<_N_words, _Size>::operator|=(const __bitset& __v) _NOEXCEPT 3090b57cec5SDimitry Andric{ 3100b57cec5SDimitry Andric for (size_type __i = 0; __i < _N_words; ++__i) 3110b57cec5SDimitry Andric __first_[__i] |= __v.__first_[__i]; 3120b57cec5SDimitry Andric} 3130b57cec5SDimitry Andric 3140b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 3150b57cec5SDimitry Andricinline 316*bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void 3170b57cec5SDimitry Andric__bitset<_N_words, _Size>::operator^=(const __bitset& __v) _NOEXCEPT 3180b57cec5SDimitry Andric{ 3190b57cec5SDimitry Andric for (size_type __i = 0; __i < _N_words; ++__i) 3200b57cec5SDimitry Andric __first_[__i] ^= __v.__first_[__i]; 3210b57cec5SDimitry Andric} 3220b57cec5SDimitry Andric 3230b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 324*bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void 3250b57cec5SDimitry Andric__bitset<_N_words, _Size>::flip() _NOEXCEPT 3260b57cec5SDimitry Andric{ 3270b57cec5SDimitry Andric // do middle whole words 3280b57cec5SDimitry Andric size_type __n = _Size; 3290b57cec5SDimitry Andric __storage_pointer __p = __first_; 3300b57cec5SDimitry Andric for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) 3310b57cec5SDimitry Andric *__p = ~*__p; 3320b57cec5SDimitry Andric // do last partial word 3330b57cec5SDimitry Andric if (__n > 0) 3340b57cec5SDimitry Andric { 3350b57cec5SDimitry Andric __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); 3360b57cec5SDimitry Andric __storage_type __b = *__p & __m; 3370b57cec5SDimitry Andric *__p &= ~__m; 3380b57cec5SDimitry Andric *__p |= ~__b & __m; 3390b57cec5SDimitry Andric } 3400b57cec5SDimitry Andric} 3410b57cec5SDimitry Andric 3420b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 343*bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long 3440b57cec5SDimitry Andric__bitset<_N_words, _Size>::to_ulong(false_type) const 3450b57cec5SDimitry Andric{ 3460b57cec5SDimitry Andric const_iterator __e = __make_iter(_Size); 3470b57cec5SDimitry Andric const_iterator __i = _VSTD::find(__make_iter(sizeof(unsigned long) * CHAR_BIT), __e, true); 3480b57cec5SDimitry Andric if (__i != __e) 3490b57cec5SDimitry Andric __throw_overflow_error("bitset to_ulong overflow error"); 3500b57cec5SDimitry Andric 3510b57cec5SDimitry Andric return __first_[0]; 3520b57cec5SDimitry Andric} 3530b57cec5SDimitry Andric 3540b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 3550b57cec5SDimitry Andricinline 356*bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long 3570b57cec5SDimitry Andric__bitset<_N_words, _Size>::to_ulong(true_type) const 3580b57cec5SDimitry Andric{ 3590b57cec5SDimitry Andric return __first_[0]; 3600b57cec5SDimitry Andric} 3610b57cec5SDimitry Andric 3620b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 363*bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long 3640b57cec5SDimitry Andric__bitset<_N_words, _Size>::to_ullong(false_type) const 3650b57cec5SDimitry Andric{ 3660b57cec5SDimitry Andric const_iterator __e = __make_iter(_Size); 3670b57cec5SDimitry Andric const_iterator __i = _VSTD::find(__make_iter(sizeof(unsigned long long) * CHAR_BIT), __e, true); 3680b57cec5SDimitry Andric if (__i != __e) 3690b57cec5SDimitry Andric __throw_overflow_error("bitset to_ullong overflow error"); 3700b57cec5SDimitry Andric 3710b57cec5SDimitry Andric return to_ullong(true_type()); 3720b57cec5SDimitry Andric} 3730b57cec5SDimitry Andric 3740b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 3750b57cec5SDimitry Andricinline 376*bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long 3770b57cec5SDimitry Andric__bitset<_N_words, _Size>::to_ullong(true_type) const 3780b57cec5SDimitry Andric{ 3790b57cec5SDimitry Andric return to_ullong(true_type(), integral_constant<bool, sizeof(__storage_type) < sizeof(unsigned long long)>()); 3800b57cec5SDimitry Andric} 3810b57cec5SDimitry Andric 3820b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 3830b57cec5SDimitry Andricinline 384*bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long 3850b57cec5SDimitry Andric__bitset<_N_words, _Size>::to_ullong(true_type, false_type) const 3860b57cec5SDimitry Andric{ 3870b57cec5SDimitry Andric return __first_[0]; 3880b57cec5SDimitry Andric} 3890b57cec5SDimitry Andric 3900b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 391*bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long 3920b57cec5SDimitry Andric__bitset<_N_words, _Size>::to_ullong(true_type, true_type) const 3930b57cec5SDimitry Andric{ 3940b57cec5SDimitry Andric unsigned long long __r = __first_[0]; 395e8d8bef9SDimitry Andric for (size_t __i = 1; __i < sizeof(unsigned long long) / sizeof(__storage_type); ++__i) 3960b57cec5SDimitry Andric __r |= static_cast<unsigned long long>(__first_[__i]) << (sizeof(__storage_type) * CHAR_BIT); 3970b57cec5SDimitry Andric return __r; 3980b57cec5SDimitry Andric} 3990b57cec5SDimitry Andric 4000b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 401*bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool 4020b57cec5SDimitry Andric__bitset<_N_words, _Size>::all() const _NOEXCEPT 4030b57cec5SDimitry Andric{ 4040b57cec5SDimitry Andric // do middle whole words 4050b57cec5SDimitry Andric size_type __n = _Size; 4060b57cec5SDimitry Andric __const_storage_pointer __p = __first_; 4070b57cec5SDimitry Andric for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) 4080b57cec5SDimitry Andric if (~*__p) 4090b57cec5SDimitry Andric return false; 4100b57cec5SDimitry Andric // do last partial word 4110b57cec5SDimitry Andric if (__n > 0) 4120b57cec5SDimitry Andric { 4130b57cec5SDimitry Andric __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); 4140b57cec5SDimitry Andric if (~*__p & __m) 4150b57cec5SDimitry Andric return false; 4160b57cec5SDimitry Andric } 4170b57cec5SDimitry Andric return true; 4180b57cec5SDimitry Andric} 4190b57cec5SDimitry Andric 4200b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 421*bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool 4220b57cec5SDimitry Andric__bitset<_N_words, _Size>::any() const _NOEXCEPT 4230b57cec5SDimitry Andric{ 4240b57cec5SDimitry Andric // do middle whole words 4250b57cec5SDimitry Andric size_type __n = _Size; 4260b57cec5SDimitry Andric __const_storage_pointer __p = __first_; 4270b57cec5SDimitry Andric for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) 4280b57cec5SDimitry Andric if (*__p) 4290b57cec5SDimitry Andric return true; 4300b57cec5SDimitry Andric // do last partial word 4310b57cec5SDimitry Andric if (__n > 0) 4320b57cec5SDimitry Andric { 4330b57cec5SDimitry Andric __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); 4340b57cec5SDimitry Andric if (*__p & __m) 4350b57cec5SDimitry Andric return true; 4360b57cec5SDimitry Andric } 4370b57cec5SDimitry Andric return false; 4380b57cec5SDimitry Andric} 4390b57cec5SDimitry Andric 4400b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 4410b57cec5SDimitry Andricinline 4420b57cec5SDimitry Andricsize_t 4430b57cec5SDimitry Andric__bitset<_N_words, _Size>::__hash_code() const _NOEXCEPT 4440b57cec5SDimitry Andric{ 4450b57cec5SDimitry Andric size_t __h = 0; 4460b57cec5SDimitry Andric for (size_type __i = 0; __i < _N_words; ++__i) 4470b57cec5SDimitry Andric __h ^= __first_[__i]; 4480b57cec5SDimitry Andric return __h; 4490b57cec5SDimitry Andric} 4500b57cec5SDimitry Andric 4510b57cec5SDimitry Andrictemplate <size_t _Size> 4520b57cec5SDimitry Andricclass __bitset<1, _Size> 4530b57cec5SDimitry Andric{ 4540b57cec5SDimitry Andricpublic: 4550b57cec5SDimitry Andric typedef ptrdiff_t difference_type; 4560b57cec5SDimitry Andric typedef size_t size_type; 4570b57cec5SDimitry Andric typedef size_type __storage_type; 4580b57cec5SDimitry Andricprotected: 4590b57cec5SDimitry Andric typedef __bitset __self; 4600b57cec5SDimitry Andric typedef __storage_type* __storage_pointer; 4610b57cec5SDimitry Andric typedef const __storage_type* __const_storage_pointer; 4620b57cec5SDimitry Andric static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT); 4630b57cec5SDimitry Andric 4640b57cec5SDimitry Andric friend class __bit_reference<__bitset>; 4650b57cec5SDimitry Andric friend class __bit_const_reference<__bitset>; 4660b57cec5SDimitry Andric friend class __bit_iterator<__bitset, false>; 4670b57cec5SDimitry Andric friend class __bit_iterator<__bitset, true>; 4680b57cec5SDimitry Andric friend struct __bit_array<__bitset>; 4690b57cec5SDimitry Andric 4700b57cec5SDimitry Andric __storage_type __first_; 4710b57cec5SDimitry Andric 4720b57cec5SDimitry Andric typedef __bit_reference<__bitset> reference; 4730b57cec5SDimitry Andric typedef __bit_const_reference<__bitset> const_reference; 4740b57cec5SDimitry Andric typedef __bit_iterator<__bitset, false> iterator; 4750b57cec5SDimitry Andric typedef __bit_iterator<__bitset, true> const_iterator; 4760b57cec5SDimitry Andric 4770b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4780b57cec5SDimitry Andric _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT; 4790b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4800b57cec5SDimitry Andric explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT; 4810b57cec5SDimitry Andric 482*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 reference __make_ref(size_t __pos) _NOEXCEPT 4830b57cec5SDimitry Andric {return reference(&__first_, __storage_type(1) << __pos);} 4840b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT 4850b57cec5SDimitry Andric {return const_reference(&__first_, __storage_type(1) << __pos);} 486*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 iterator __make_iter(size_t __pos) _NOEXCEPT 4870b57cec5SDimitry Andric {return iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);} 488*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 const_iterator __make_iter(size_t __pos) const _NOEXCEPT 4890b57cec5SDimitry Andric {return const_iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);} 4900b57cec5SDimitry Andric 491*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 4920b57cec5SDimitry Andric void operator&=(const __bitset& __v) _NOEXCEPT; 493*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 4940b57cec5SDimitry Andric void operator|=(const __bitset& __v) _NOEXCEPT; 495*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 4960b57cec5SDimitry Andric void operator^=(const __bitset& __v) _NOEXCEPT; 4970b57cec5SDimitry Andric 498*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 4990b57cec5SDimitry Andric void flip() _NOEXCEPT; 5000b57cec5SDimitry Andric 501*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 5020b57cec5SDimitry Andric unsigned long to_ulong() const; 503*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 5040b57cec5SDimitry Andric unsigned long long to_ullong() const; 5050b57cec5SDimitry Andric 506*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 5070b57cec5SDimitry Andric bool all() const _NOEXCEPT; 508*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 5090b57cec5SDimitry Andric bool any() const _NOEXCEPT; 5100b57cec5SDimitry Andric 5110b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5120b57cec5SDimitry Andric size_t __hash_code() const _NOEXCEPT; 5130b57cec5SDimitry Andric}; 5140b57cec5SDimitry Andric 5150b57cec5SDimitry Andrictemplate <size_t _Size> 5160b57cec5SDimitry Andricinline 5170b57cec5SDimitry Andric_LIBCPP_CONSTEXPR 5180b57cec5SDimitry Andric__bitset<1, _Size>::__bitset() _NOEXCEPT 5190b57cec5SDimitry Andric : __first_(0) 5200b57cec5SDimitry Andric{ 5210b57cec5SDimitry Andric} 5220b57cec5SDimitry Andric 5230b57cec5SDimitry Andrictemplate <size_t _Size> 5240b57cec5SDimitry Andricinline 5250b57cec5SDimitry Andric_LIBCPP_CONSTEXPR 5260b57cec5SDimitry Andric__bitset<1, _Size>::__bitset(unsigned long long __v) _NOEXCEPT 5270b57cec5SDimitry Andric : __first_( 5280b57cec5SDimitry Andric _Size == __bits_per_word ? static_cast<__storage_type>(__v) 5290b57cec5SDimitry Andric : static_cast<__storage_type>(__v) & ((__storage_type(1) << _Size) - 1) 5300b57cec5SDimitry Andric ) 5310b57cec5SDimitry Andric{ 5320b57cec5SDimitry Andric} 5330b57cec5SDimitry Andric 5340b57cec5SDimitry Andrictemplate <size_t _Size> 5350b57cec5SDimitry Andricinline 536*bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void 5370b57cec5SDimitry Andric__bitset<1, _Size>::operator&=(const __bitset& __v) _NOEXCEPT 5380b57cec5SDimitry Andric{ 5390b57cec5SDimitry Andric __first_ &= __v.__first_; 5400b57cec5SDimitry Andric} 5410b57cec5SDimitry Andric 5420b57cec5SDimitry Andrictemplate <size_t _Size> 5430b57cec5SDimitry Andricinline 544*bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void 5450b57cec5SDimitry Andric__bitset<1, _Size>::operator|=(const __bitset& __v) _NOEXCEPT 5460b57cec5SDimitry Andric{ 5470b57cec5SDimitry Andric __first_ |= __v.__first_; 5480b57cec5SDimitry Andric} 5490b57cec5SDimitry Andric 5500b57cec5SDimitry Andrictemplate <size_t _Size> 5510b57cec5SDimitry Andricinline 552*bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void 5530b57cec5SDimitry Andric__bitset<1, _Size>::operator^=(const __bitset& __v) _NOEXCEPT 5540b57cec5SDimitry Andric{ 5550b57cec5SDimitry Andric __first_ ^= __v.__first_; 5560b57cec5SDimitry Andric} 5570b57cec5SDimitry Andric 5580b57cec5SDimitry Andrictemplate <size_t _Size> 5590b57cec5SDimitry Andricinline 560*bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void 5610b57cec5SDimitry Andric__bitset<1, _Size>::flip() _NOEXCEPT 5620b57cec5SDimitry Andric{ 5630b57cec5SDimitry Andric __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size); 5640b57cec5SDimitry Andric __first_ = ~__first_; 5650b57cec5SDimitry Andric __first_ &= __m; 5660b57cec5SDimitry Andric} 5670b57cec5SDimitry Andric 5680b57cec5SDimitry Andrictemplate <size_t _Size> 5690b57cec5SDimitry Andricinline 570*bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long 5710b57cec5SDimitry Andric__bitset<1, _Size>::to_ulong() const 5720b57cec5SDimitry Andric{ 5730b57cec5SDimitry Andric return __first_; 5740b57cec5SDimitry Andric} 5750b57cec5SDimitry Andric 5760b57cec5SDimitry Andrictemplate <size_t _Size> 5770b57cec5SDimitry Andricinline 578*bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long 5790b57cec5SDimitry Andric__bitset<1, _Size>::to_ullong() const 5800b57cec5SDimitry Andric{ 5810b57cec5SDimitry Andric return __first_; 5820b57cec5SDimitry Andric} 5830b57cec5SDimitry Andric 5840b57cec5SDimitry Andrictemplate <size_t _Size> 5850b57cec5SDimitry Andricinline 586*bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool 5870b57cec5SDimitry Andric__bitset<1, _Size>::all() const _NOEXCEPT 5880b57cec5SDimitry Andric{ 5890b57cec5SDimitry Andric __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size); 5900b57cec5SDimitry Andric return !(~__first_ & __m); 5910b57cec5SDimitry Andric} 5920b57cec5SDimitry Andric 5930b57cec5SDimitry Andrictemplate <size_t _Size> 5940b57cec5SDimitry Andricinline 595*bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool 5960b57cec5SDimitry Andric__bitset<1, _Size>::any() const _NOEXCEPT 5970b57cec5SDimitry Andric{ 5980b57cec5SDimitry Andric __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size); 5990b57cec5SDimitry Andric return __first_ & __m; 6000b57cec5SDimitry Andric} 6010b57cec5SDimitry Andric 6020b57cec5SDimitry Andrictemplate <size_t _Size> 6030b57cec5SDimitry Andricinline 6040b57cec5SDimitry Andricsize_t 6050b57cec5SDimitry Andric__bitset<1, _Size>::__hash_code() const _NOEXCEPT 6060b57cec5SDimitry Andric{ 6070b57cec5SDimitry Andric return __first_; 6080b57cec5SDimitry Andric} 6090b57cec5SDimitry Andric 6100b57cec5SDimitry Andrictemplate <> 6110b57cec5SDimitry Andricclass __bitset<0, 0> 6120b57cec5SDimitry Andric{ 6130b57cec5SDimitry Andricpublic: 6140b57cec5SDimitry Andric typedef ptrdiff_t difference_type; 6150b57cec5SDimitry Andric typedef size_t size_type; 6160b57cec5SDimitry Andric typedef size_type __storage_type; 6170b57cec5SDimitry Andricprotected: 6180b57cec5SDimitry Andric typedef __bitset __self; 6190b57cec5SDimitry Andric typedef __storage_type* __storage_pointer; 6200b57cec5SDimitry Andric typedef const __storage_type* __const_storage_pointer; 6210b57cec5SDimitry Andric static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT); 6220b57cec5SDimitry Andric 6230b57cec5SDimitry Andric friend class __bit_reference<__bitset>; 6240b57cec5SDimitry Andric friend class __bit_const_reference<__bitset>; 6250b57cec5SDimitry Andric friend class __bit_iterator<__bitset, false>; 6260b57cec5SDimitry Andric friend class __bit_iterator<__bitset, true>; 6270b57cec5SDimitry Andric friend struct __bit_array<__bitset>; 6280b57cec5SDimitry Andric 6290b57cec5SDimitry Andric typedef __bit_reference<__bitset> reference; 6300b57cec5SDimitry Andric typedef __bit_const_reference<__bitset> const_reference; 6310b57cec5SDimitry Andric typedef __bit_iterator<__bitset, false> iterator; 6320b57cec5SDimitry Andric typedef __bit_iterator<__bitset, true> const_iterator; 6330b57cec5SDimitry Andric 6340b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6350b57cec5SDimitry Andric _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT; 6360b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6370b57cec5SDimitry Andric explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long) _NOEXCEPT; 6380b57cec5SDimitry Andric 639*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 reference __make_ref(size_t) _NOEXCEPT 640e8d8bef9SDimitry Andric {return reference(nullptr, 1);} 6410b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t) const _NOEXCEPT 642e8d8bef9SDimitry Andric {return const_reference(nullptr, 1);} 643*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 iterator __make_iter(size_t) _NOEXCEPT 644e8d8bef9SDimitry Andric {return iterator(nullptr, 0);} 645*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 const_iterator __make_iter(size_t) const _NOEXCEPT 646e8d8bef9SDimitry Andric {return const_iterator(nullptr, 0);} 6470b57cec5SDimitry Andric 648*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator&=(const __bitset&) _NOEXCEPT {} 649*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator|=(const __bitset&) _NOEXCEPT {} 650*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator^=(const __bitset&) _NOEXCEPT {} 6510b57cec5SDimitry Andric 652*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 void flip() _NOEXCEPT {} 6530b57cec5SDimitry Andric 654*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong() const {return 0;} 655*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong() const {return 0;} 6560b57cec5SDimitry Andric 657*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT {return true;} 658*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT {return false;} 6590b57cec5SDimitry Andric 6600b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY size_t __hash_code() const _NOEXCEPT {return 0;} 6610b57cec5SDimitry Andric}; 6620b57cec5SDimitry Andric 6630b57cec5SDimitry Andricinline 6640b57cec5SDimitry Andric_LIBCPP_CONSTEXPR 6650b57cec5SDimitry Andric__bitset<0, 0>::__bitset() _NOEXCEPT 6660b57cec5SDimitry Andric{ 6670b57cec5SDimitry Andric} 6680b57cec5SDimitry Andric 6690b57cec5SDimitry Andricinline 6700b57cec5SDimitry Andric_LIBCPP_CONSTEXPR 6710b57cec5SDimitry Andric__bitset<0, 0>::__bitset(unsigned long long) _NOEXCEPT 6720b57cec5SDimitry Andric{ 6730b57cec5SDimitry Andric} 6740b57cec5SDimitry Andric 6750b57cec5SDimitry Andrictemplate <size_t _Size> class _LIBCPP_TEMPLATE_VIS bitset; 6760b57cec5SDimitry Andrictemplate <size_t _Size> struct hash<bitset<_Size> >; 6770b57cec5SDimitry Andric 6780b57cec5SDimitry Andrictemplate <size_t _Size> 6790b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS bitset 6800b57cec5SDimitry Andric : private __bitset<_Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1, _Size> 6810b57cec5SDimitry Andric{ 6820b57cec5SDimitry Andricpublic: 6830b57cec5SDimitry Andric static const unsigned __n_words = _Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1; 6840b57cec5SDimitry Andric typedef __bitset<__n_words, _Size> base; 6850b57cec5SDimitry Andric 6860b57cec5SDimitry Andricpublic: 6870b57cec5SDimitry Andric typedef typename base::reference reference; 6880b57cec5SDimitry Andric typedef typename base::const_reference const_reference; 6890b57cec5SDimitry Andric 6900b57cec5SDimitry Andric // 23.3.5.1 constructors: 6910b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bitset() _NOEXCEPT {} 6920b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 6930b57cec5SDimitry Andric bitset(unsigned long long __v) _NOEXCEPT : base(__v) {} 694349cc55cSDimitry Andric template<class _CharT, class = __enable_if_t<_IsCharLikeType<_CharT>::value> > 695*bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 6960b57cec5SDimitry Andric explicit bitset(const _CharT* __str, 6970b57cec5SDimitry Andric typename basic_string<_CharT>::size_type __n = basic_string<_CharT>::npos, 6980b57cec5SDimitry Andric _CharT __zero = _CharT('0'), _CharT __one = _CharT('1')); 6990b57cec5SDimitry Andric template<class _CharT, class _Traits, class _Allocator> 700*bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 7010b57cec5SDimitry Andric explicit bitset(const basic_string<_CharT,_Traits,_Allocator>& __str, 7020b57cec5SDimitry Andric typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos = 0, 7030b57cec5SDimitry Andric typename basic_string<_CharT,_Traits,_Allocator>::size_type __n = 7040b57cec5SDimitry Andric (basic_string<_CharT,_Traits,_Allocator>::npos), 7050b57cec5SDimitry Andric _CharT __zero = _CharT('0'), _CharT __one = _CharT('1')); 7060b57cec5SDimitry Andric 7070b57cec5SDimitry Andric // 23.3.5.2 bitset operations: 708*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 7090b57cec5SDimitry Andric bitset& operator&=(const bitset& __rhs) _NOEXCEPT; 710*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 7110b57cec5SDimitry Andric bitset& operator|=(const bitset& __rhs) _NOEXCEPT; 712*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 7130b57cec5SDimitry Andric bitset& operator^=(const bitset& __rhs) _NOEXCEPT; 714*bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 7150b57cec5SDimitry Andric bitset& operator<<=(size_t __pos) _NOEXCEPT; 716*bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 7170b57cec5SDimitry Andric bitset& operator>>=(size_t __pos) _NOEXCEPT; 718*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 7190b57cec5SDimitry Andric bitset& set() _NOEXCEPT; 720*bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 7210b57cec5SDimitry Andric bitset& set(size_t __pos, bool __val = true); 722*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 7230b57cec5SDimitry Andric bitset& reset() _NOEXCEPT; 724*bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 7250b57cec5SDimitry Andric bitset& reset(size_t __pos); 726*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 7270b57cec5SDimitry Andric bitset operator~() const _NOEXCEPT; 728*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 7290b57cec5SDimitry Andric bitset& flip() _NOEXCEPT; 730*bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 7310b57cec5SDimitry Andric bitset& flip(size_t __pos); 7320b57cec5SDimitry Andric 7330b57cec5SDimitry Andric // element access: 73481ad6265SDimitry Andric#ifdef _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL 73581ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool operator[](size_t __p) const {return base::__make_ref(__p);} 73681ad6265SDimitry Andric#else 73781ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const_reference operator[](size_t __p) const {return base::__make_ref(__p);} 73881ad6265SDimitry Andric#endif 739*bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 reference operator[](size_t __p) {return base::__make_ref(__p);} 740*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 7410b57cec5SDimitry Andric unsigned long to_ulong() const; 742*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 7430b57cec5SDimitry Andric unsigned long long to_ullong() const; 7440b57cec5SDimitry Andric template <class _CharT, class _Traits, class _Allocator> 745*bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 7460b57cec5SDimitry Andric basic_string<_CharT, _Traits, _Allocator> to_string(_CharT __zero = _CharT('0'), 7470b57cec5SDimitry Andric _CharT __one = _CharT('1')) const; 7480b57cec5SDimitry Andric template <class _CharT, class _Traits> 749*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 7500b57cec5SDimitry Andric basic_string<_CharT, _Traits, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'), 7510b57cec5SDimitry Andric _CharT __one = _CharT('1')) const; 7520b57cec5SDimitry Andric template <class _CharT> 753*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 7540b57cec5SDimitry Andric basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'), 7550b57cec5SDimitry Andric _CharT __one = _CharT('1')) const; 756*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 7570b57cec5SDimitry Andric basic_string<char, char_traits<char>, allocator<char> > to_string(char __zero = '0', 7580b57cec5SDimitry Andric char __one = '1') const; 759*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 7600b57cec5SDimitry Andric size_t count() const _NOEXCEPT; 7610b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR size_t size() const _NOEXCEPT {return _Size;} 762*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 7630b57cec5SDimitry Andric bool operator==(const bitset& __rhs) const _NOEXCEPT; 764*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 7650b57cec5SDimitry Andric bool operator!=(const bitset& __rhs) const _NOEXCEPT; 766*bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 7670b57cec5SDimitry Andric bool test(size_t __pos) const; 768*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 7690b57cec5SDimitry Andric bool all() const _NOEXCEPT; 770*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 7710b57cec5SDimitry Andric bool any() const _NOEXCEPT; 772*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 bool none() const _NOEXCEPT {return !any();} 773*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 7740b57cec5SDimitry Andric bitset operator<<(size_t __pos) const _NOEXCEPT; 775*bdd1243dSDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 7760b57cec5SDimitry Andric bitset operator>>(size_t __pos) const _NOEXCEPT; 7770b57cec5SDimitry Andric 7780b57cec5SDimitry Andricprivate: 7790b57cec5SDimitry Andric 7800b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 7810b57cec5SDimitry Andric size_t __hash_code() const _NOEXCEPT {return base::__hash_code();} 7820b57cec5SDimitry Andric 7830b57cec5SDimitry Andric friend struct hash<bitset>; 7840b57cec5SDimitry Andric}; 7850b57cec5SDimitry Andric 7860b57cec5SDimitry Andrictemplate <size_t _Size> 7870b57cec5SDimitry Andrictemplate<class _CharT, class> 788*bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 7890b57cec5SDimitry Andricbitset<_Size>::bitset(const _CharT* __str, 7900b57cec5SDimitry Andric typename basic_string<_CharT>::size_type __n, 7910b57cec5SDimitry Andric _CharT __zero, _CharT __one) 7920b57cec5SDimitry Andric{ 7930b57cec5SDimitry Andric size_t __rlen = _VSTD::min(__n, char_traits<_CharT>::length(__str)); 7940b57cec5SDimitry Andric for (size_t __i = 0; __i < __rlen; ++__i) 7950b57cec5SDimitry Andric if (__str[__i] != __zero && __str[__i] != __one) 7960b57cec5SDimitry Andric __throw_invalid_argument("bitset string ctor has invalid argument"); 7970b57cec5SDimitry Andric 7980b57cec5SDimitry Andric size_t _Mp = _VSTD::min(__rlen, _Size); 7990b57cec5SDimitry Andric size_t __i = 0; 8000b57cec5SDimitry Andric for (; __i < _Mp; ++__i) 8010b57cec5SDimitry Andric { 8020b57cec5SDimitry Andric _CharT __c = __str[_Mp - 1 - __i]; 803fe6060f1SDimitry Andric (*this)[__i] = (__c == __one); 8040b57cec5SDimitry Andric } 8050b57cec5SDimitry Andric _VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false); 8060b57cec5SDimitry Andric} 8070b57cec5SDimitry Andric 8080b57cec5SDimitry Andrictemplate <size_t _Size> 8090b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 810*bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 8110b57cec5SDimitry Andricbitset<_Size>::bitset(const basic_string<_CharT,_Traits,_Allocator>& __str, 8120b57cec5SDimitry Andric typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos, 8130b57cec5SDimitry Andric typename basic_string<_CharT,_Traits,_Allocator>::size_type __n, 8140b57cec5SDimitry Andric _CharT __zero, _CharT __one) 8150b57cec5SDimitry Andric{ 8160b57cec5SDimitry Andric if (__pos > __str.size()) 8170b57cec5SDimitry Andric __throw_out_of_range("bitset string pos out of range"); 8180b57cec5SDimitry Andric 8190b57cec5SDimitry Andric size_t __rlen = _VSTD::min(__n, __str.size() - __pos); 8200b57cec5SDimitry Andric for (size_t __i = __pos; __i < __pos + __rlen; ++__i) 8210b57cec5SDimitry Andric if (!_Traits::eq(__str[__i], __zero) && !_Traits::eq(__str[__i], __one)) 8220b57cec5SDimitry Andric __throw_invalid_argument("bitset string ctor has invalid argument"); 8230b57cec5SDimitry Andric 8240b57cec5SDimitry Andric size_t _Mp = _VSTD::min(__rlen, _Size); 8250b57cec5SDimitry Andric size_t __i = 0; 8260b57cec5SDimitry Andric for (; __i < _Mp; ++__i) 8270b57cec5SDimitry Andric { 8280b57cec5SDimitry Andric _CharT __c = __str[__pos + _Mp - 1 - __i]; 829fe6060f1SDimitry Andric (*this)[__i] = _Traits::eq(__c, __one); 8300b57cec5SDimitry Andric } 8310b57cec5SDimitry Andric _VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false); 8320b57cec5SDimitry Andric} 8330b57cec5SDimitry Andric 8340b57cec5SDimitry Andrictemplate <size_t _Size> 8350b57cec5SDimitry Andricinline 836*bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 8370b57cec5SDimitry Andricbitset<_Size>& 8380b57cec5SDimitry Andricbitset<_Size>::operator&=(const bitset& __rhs) _NOEXCEPT 8390b57cec5SDimitry Andric{ 8400b57cec5SDimitry Andric base::operator&=(__rhs); 8410b57cec5SDimitry Andric return *this; 8420b57cec5SDimitry Andric} 8430b57cec5SDimitry Andric 8440b57cec5SDimitry Andrictemplate <size_t _Size> 8450b57cec5SDimitry Andricinline 846*bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 8470b57cec5SDimitry Andricbitset<_Size>& 8480b57cec5SDimitry Andricbitset<_Size>::operator|=(const bitset& __rhs) _NOEXCEPT 8490b57cec5SDimitry Andric{ 8500b57cec5SDimitry Andric base::operator|=(__rhs); 8510b57cec5SDimitry Andric return *this; 8520b57cec5SDimitry Andric} 8530b57cec5SDimitry Andric 8540b57cec5SDimitry Andrictemplate <size_t _Size> 8550b57cec5SDimitry Andricinline 856*bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 8570b57cec5SDimitry Andricbitset<_Size>& 8580b57cec5SDimitry Andricbitset<_Size>::operator^=(const bitset& __rhs) _NOEXCEPT 8590b57cec5SDimitry Andric{ 8600b57cec5SDimitry Andric base::operator^=(__rhs); 8610b57cec5SDimitry Andric return *this; 8620b57cec5SDimitry Andric} 8630b57cec5SDimitry Andric 8640b57cec5SDimitry Andrictemplate <size_t _Size> 865*bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 8660b57cec5SDimitry Andricbitset<_Size>& 8670b57cec5SDimitry Andricbitset<_Size>::operator<<=(size_t __pos) _NOEXCEPT 8680b57cec5SDimitry Andric{ 8690b57cec5SDimitry Andric __pos = _VSTD::min(__pos, _Size); 8700b57cec5SDimitry Andric _VSTD::copy_backward(base::__make_iter(0), base::__make_iter(_Size - __pos), base::__make_iter(_Size)); 8710b57cec5SDimitry Andric _VSTD::fill_n(base::__make_iter(0), __pos, false); 8720b57cec5SDimitry Andric return *this; 8730b57cec5SDimitry Andric} 8740b57cec5SDimitry Andric 8750b57cec5SDimitry Andrictemplate <size_t _Size> 876*bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 8770b57cec5SDimitry Andricbitset<_Size>& 8780b57cec5SDimitry Andricbitset<_Size>::operator>>=(size_t __pos) _NOEXCEPT 8790b57cec5SDimitry Andric{ 8800b57cec5SDimitry Andric __pos = _VSTD::min(__pos, _Size); 8810b57cec5SDimitry Andric _VSTD::copy(base::__make_iter(__pos), base::__make_iter(_Size), base::__make_iter(0)); 8820b57cec5SDimitry Andric _VSTD::fill_n(base::__make_iter(_Size - __pos), __pos, false); 8830b57cec5SDimitry Andric return *this; 8840b57cec5SDimitry Andric} 8850b57cec5SDimitry Andric 8860b57cec5SDimitry Andrictemplate <size_t _Size> 8870b57cec5SDimitry Andricinline 888*bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 8890b57cec5SDimitry Andricbitset<_Size>& 8900b57cec5SDimitry Andricbitset<_Size>::set() _NOEXCEPT 8910b57cec5SDimitry Andric{ 8920b57cec5SDimitry Andric _VSTD::fill_n(base::__make_iter(0), _Size, true); 8930b57cec5SDimitry Andric return *this; 8940b57cec5SDimitry Andric} 8950b57cec5SDimitry Andric 8960b57cec5SDimitry Andrictemplate <size_t _Size> 897*bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 8980b57cec5SDimitry Andricbitset<_Size>& 8990b57cec5SDimitry Andricbitset<_Size>::set(size_t __pos, bool __val) 9000b57cec5SDimitry Andric{ 9010b57cec5SDimitry Andric if (__pos >= _Size) 9020b57cec5SDimitry Andric __throw_out_of_range("bitset set argument out of range"); 9030b57cec5SDimitry Andric 9040b57cec5SDimitry Andric (*this)[__pos] = __val; 9050b57cec5SDimitry Andric return *this; 9060b57cec5SDimitry Andric} 9070b57cec5SDimitry Andric 9080b57cec5SDimitry Andrictemplate <size_t _Size> 9090b57cec5SDimitry Andricinline 910*bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 9110b57cec5SDimitry Andricbitset<_Size>& 9120b57cec5SDimitry Andricbitset<_Size>::reset() _NOEXCEPT 9130b57cec5SDimitry Andric{ 9140b57cec5SDimitry Andric _VSTD::fill_n(base::__make_iter(0), _Size, false); 9150b57cec5SDimitry Andric return *this; 9160b57cec5SDimitry Andric} 9170b57cec5SDimitry Andric 9180b57cec5SDimitry Andrictemplate <size_t _Size> 919*bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 9200b57cec5SDimitry Andricbitset<_Size>& 9210b57cec5SDimitry Andricbitset<_Size>::reset(size_t __pos) 9220b57cec5SDimitry Andric{ 9230b57cec5SDimitry Andric if (__pos >= _Size) 9240b57cec5SDimitry Andric __throw_out_of_range("bitset reset argument out of range"); 9250b57cec5SDimitry Andric 9260b57cec5SDimitry Andric (*this)[__pos] = false; 9270b57cec5SDimitry Andric return *this; 9280b57cec5SDimitry Andric} 9290b57cec5SDimitry Andric 9300b57cec5SDimitry Andrictemplate <size_t _Size> 9310b57cec5SDimitry Andricinline 932*bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 9330b57cec5SDimitry Andricbitset<_Size> 9340b57cec5SDimitry Andricbitset<_Size>::operator~() const _NOEXCEPT 9350b57cec5SDimitry Andric{ 9360b57cec5SDimitry Andric bitset __x(*this); 9370b57cec5SDimitry Andric __x.flip(); 9380b57cec5SDimitry Andric return __x; 9390b57cec5SDimitry Andric} 9400b57cec5SDimitry Andric 9410b57cec5SDimitry Andrictemplate <size_t _Size> 9420b57cec5SDimitry Andricinline 943*bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 9440b57cec5SDimitry Andricbitset<_Size>& 9450b57cec5SDimitry Andricbitset<_Size>::flip() _NOEXCEPT 9460b57cec5SDimitry Andric{ 9470b57cec5SDimitry Andric base::flip(); 9480b57cec5SDimitry Andric return *this; 9490b57cec5SDimitry Andric} 9500b57cec5SDimitry Andric 9510b57cec5SDimitry Andrictemplate <size_t _Size> 952*bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 9530b57cec5SDimitry Andricbitset<_Size>& 9540b57cec5SDimitry Andricbitset<_Size>::flip(size_t __pos) 9550b57cec5SDimitry Andric{ 9560b57cec5SDimitry Andric if (__pos >= _Size) 9570b57cec5SDimitry Andric __throw_out_of_range("bitset flip argument out of range"); 9580b57cec5SDimitry Andric 9590b57cec5SDimitry Andric reference r = base::__make_ref(__pos); 9600b57cec5SDimitry Andric r = ~r; 9610b57cec5SDimitry Andric return *this; 9620b57cec5SDimitry Andric} 9630b57cec5SDimitry Andric 9640b57cec5SDimitry Andrictemplate <size_t _Size> 9650b57cec5SDimitry Andricinline 966*bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 9670b57cec5SDimitry Andricunsigned long 9680b57cec5SDimitry Andricbitset<_Size>::to_ulong() const 9690b57cec5SDimitry Andric{ 9700b57cec5SDimitry Andric return base::to_ulong(); 9710b57cec5SDimitry Andric} 9720b57cec5SDimitry Andric 9730b57cec5SDimitry Andrictemplate <size_t _Size> 9740b57cec5SDimitry Andricinline 975*bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 9760b57cec5SDimitry Andricunsigned long long 9770b57cec5SDimitry Andricbitset<_Size>::to_ullong() const 9780b57cec5SDimitry Andric{ 9790b57cec5SDimitry Andric return base::to_ullong(); 9800b57cec5SDimitry Andric} 9810b57cec5SDimitry Andric 9820b57cec5SDimitry Andrictemplate <size_t _Size> 9830b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 984*bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 9850b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator> 9860b57cec5SDimitry Andricbitset<_Size>::to_string(_CharT __zero, _CharT __one) const 9870b57cec5SDimitry Andric{ 9880b57cec5SDimitry Andric basic_string<_CharT, _Traits, _Allocator> __r(_Size, __zero); 98981ad6265SDimitry Andric for (size_t __i = 0; __i != _Size; ++__i) 9900b57cec5SDimitry Andric { 9910b57cec5SDimitry Andric if ((*this)[__i]) 9920b57cec5SDimitry Andric __r[_Size - 1 - __i] = __one; 9930b57cec5SDimitry Andric } 9940b57cec5SDimitry Andric return __r; 9950b57cec5SDimitry Andric} 9960b57cec5SDimitry Andric 9970b57cec5SDimitry Andrictemplate <size_t _Size> 9980b57cec5SDimitry Andrictemplate <class _CharT, class _Traits> 9990b57cec5SDimitry Andricinline 1000*bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 10010b57cec5SDimitry Andricbasic_string<_CharT, _Traits, allocator<_CharT> > 10020b57cec5SDimitry Andricbitset<_Size>::to_string(_CharT __zero, _CharT __one) const 10030b57cec5SDimitry Andric{ 10040b57cec5SDimitry Andric return to_string<_CharT, _Traits, allocator<_CharT> >(__zero, __one); 10050b57cec5SDimitry Andric} 10060b57cec5SDimitry Andric 10070b57cec5SDimitry Andrictemplate <size_t _Size> 10080b57cec5SDimitry Andrictemplate <class _CharT> 10090b57cec5SDimitry Andricinline 1010*bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 10110b57cec5SDimitry Andricbasic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > 10120b57cec5SDimitry Andricbitset<_Size>::to_string(_CharT __zero, _CharT __one) const 10130b57cec5SDimitry Andric{ 10140b57cec5SDimitry Andric return to_string<_CharT, char_traits<_CharT>, allocator<_CharT> >(__zero, __one); 10150b57cec5SDimitry Andric} 10160b57cec5SDimitry Andric 10170b57cec5SDimitry Andrictemplate <size_t _Size> 10180b57cec5SDimitry Andricinline 1019*bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 10200b57cec5SDimitry Andricbasic_string<char, char_traits<char>, allocator<char> > 10210b57cec5SDimitry Andricbitset<_Size>::to_string(char __zero, char __one) const 10220b57cec5SDimitry Andric{ 10230b57cec5SDimitry Andric return to_string<char, char_traits<char>, allocator<char> >(__zero, __one); 10240b57cec5SDimitry Andric} 10250b57cec5SDimitry Andric 10260b57cec5SDimitry Andrictemplate <size_t _Size> 10270b57cec5SDimitry Andricinline 1028*bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 10290b57cec5SDimitry Andricsize_t 10300b57cec5SDimitry Andricbitset<_Size>::count() const _NOEXCEPT 10310b57cec5SDimitry Andric{ 1032e8d8bef9SDimitry Andric return static_cast<size_t>(_VSTD::__count_bool_true(base::__make_iter(0), _Size)); 10330b57cec5SDimitry Andric} 10340b57cec5SDimitry Andric 10350b57cec5SDimitry Andrictemplate <size_t _Size> 10360b57cec5SDimitry Andricinline 1037*bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 10380b57cec5SDimitry Andricbool 10390b57cec5SDimitry Andricbitset<_Size>::operator==(const bitset& __rhs) const _NOEXCEPT 10400b57cec5SDimitry Andric{ 10410b57cec5SDimitry Andric return _VSTD::equal(base::__make_iter(0), base::__make_iter(_Size), __rhs.__make_iter(0)); 10420b57cec5SDimitry Andric} 10430b57cec5SDimitry Andric 10440b57cec5SDimitry Andrictemplate <size_t _Size> 10450b57cec5SDimitry Andricinline 1046*bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 10470b57cec5SDimitry Andricbool 10480b57cec5SDimitry Andricbitset<_Size>::operator!=(const bitset& __rhs) const _NOEXCEPT 10490b57cec5SDimitry Andric{ 10500b57cec5SDimitry Andric return !(*this == __rhs); 10510b57cec5SDimitry Andric} 10520b57cec5SDimitry Andric 10530b57cec5SDimitry Andrictemplate <size_t _Size> 1054*bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 10550b57cec5SDimitry Andricbool 10560b57cec5SDimitry Andricbitset<_Size>::test(size_t __pos) const 10570b57cec5SDimitry Andric{ 10580b57cec5SDimitry Andric if (__pos >= _Size) 10590b57cec5SDimitry Andric __throw_out_of_range("bitset test argument out of range"); 10600b57cec5SDimitry Andric 10610b57cec5SDimitry Andric return (*this)[__pos]; 10620b57cec5SDimitry Andric} 10630b57cec5SDimitry Andric 10640b57cec5SDimitry Andrictemplate <size_t _Size> 10650b57cec5SDimitry Andricinline 1066*bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 10670b57cec5SDimitry Andricbool 10680b57cec5SDimitry Andricbitset<_Size>::all() const _NOEXCEPT 10690b57cec5SDimitry Andric{ 10700b57cec5SDimitry Andric return base::all(); 10710b57cec5SDimitry Andric} 10720b57cec5SDimitry Andric 10730b57cec5SDimitry Andrictemplate <size_t _Size> 10740b57cec5SDimitry Andricinline 1075*bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 10760b57cec5SDimitry Andricbool 10770b57cec5SDimitry Andricbitset<_Size>::any() const _NOEXCEPT 10780b57cec5SDimitry Andric{ 10790b57cec5SDimitry Andric return base::any(); 10800b57cec5SDimitry Andric} 10810b57cec5SDimitry Andric 10820b57cec5SDimitry Andrictemplate <size_t _Size> 10830b57cec5SDimitry Andricinline 1084*bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 10850b57cec5SDimitry Andricbitset<_Size> 10860b57cec5SDimitry Andricbitset<_Size>::operator<<(size_t __pos) const _NOEXCEPT 10870b57cec5SDimitry Andric{ 10880b57cec5SDimitry Andric bitset __r = *this; 10890b57cec5SDimitry Andric __r <<= __pos; 10900b57cec5SDimitry Andric return __r; 10910b57cec5SDimitry Andric} 10920b57cec5SDimitry Andric 10930b57cec5SDimitry Andrictemplate <size_t _Size> 10940b57cec5SDimitry Andricinline 1095*bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 10960b57cec5SDimitry Andricbitset<_Size> 10970b57cec5SDimitry Andricbitset<_Size>::operator>>(size_t __pos) const _NOEXCEPT 10980b57cec5SDimitry Andric{ 10990b57cec5SDimitry Andric bitset __r = *this; 11000b57cec5SDimitry Andric __r >>= __pos; 11010b57cec5SDimitry Andric return __r; 11020b57cec5SDimitry Andric} 11030b57cec5SDimitry Andric 11040b57cec5SDimitry Andrictemplate <size_t _Size> 1105*bdd1243dSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 11060b57cec5SDimitry Andricbitset<_Size> 11070b57cec5SDimitry Andricoperator&(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT 11080b57cec5SDimitry Andric{ 11090b57cec5SDimitry Andric bitset<_Size> __r = __x; 11100b57cec5SDimitry Andric __r &= __y; 11110b57cec5SDimitry Andric return __r; 11120b57cec5SDimitry Andric} 11130b57cec5SDimitry Andric 11140b57cec5SDimitry Andrictemplate <size_t _Size> 1115*bdd1243dSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 11160b57cec5SDimitry Andricbitset<_Size> 11170b57cec5SDimitry Andricoperator|(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT 11180b57cec5SDimitry Andric{ 11190b57cec5SDimitry Andric bitset<_Size> __r = __x; 11200b57cec5SDimitry Andric __r |= __y; 11210b57cec5SDimitry Andric return __r; 11220b57cec5SDimitry Andric} 11230b57cec5SDimitry Andric 11240b57cec5SDimitry Andrictemplate <size_t _Size> 1125*bdd1243dSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 11260b57cec5SDimitry Andricbitset<_Size> 11270b57cec5SDimitry Andricoperator^(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT 11280b57cec5SDimitry Andric{ 11290b57cec5SDimitry Andric bitset<_Size> __r = __x; 11300b57cec5SDimitry Andric __r ^= __y; 11310b57cec5SDimitry Andric return __r; 11320b57cec5SDimitry Andric} 11330b57cec5SDimitry Andric 11340b57cec5SDimitry Andrictemplate <size_t _Size> 11350b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS hash<bitset<_Size> > 113681ad6265SDimitry Andric : public __unary_function<bitset<_Size>, size_t> 11370b57cec5SDimitry Andric{ 11380b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 11390b57cec5SDimitry Andric size_t operator()(const bitset<_Size>& __bs) const _NOEXCEPT 11400b57cec5SDimitry Andric {return __bs.__hash_code();} 11410b57cec5SDimitry Andric}; 11420b57cec5SDimitry Andric 11430b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, size_t _Size> 1144*bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>& 11450b57cec5SDimitry Andricoperator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x); 11460b57cec5SDimitry Andric 11470b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, size_t _Size> 1148*bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& 11490b57cec5SDimitry Andricoperator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x); 11500b57cec5SDimitry Andric 11510b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD 11520b57cec5SDimitry Andric 11530b57cec5SDimitry Andric_LIBCPP_POP_MACROS 11540b57cec5SDimitry Andric 1155*bdd1243dSDimitry Andric#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 1156*bdd1243dSDimitry Andric# include <concepts> 1157*bdd1243dSDimitry Andric#endif 1158*bdd1243dSDimitry Andric 11590b57cec5SDimitry Andric#endif // _LIBCPP_BITSET 1160