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 13*5f757f3fSDimitry Andric// clang-format off 14*5f757f3fSDimitry Andric 150b57cec5SDimitry Andric/* 160b57cec5SDimitry Andric bitset synopsis 170b57cec5SDimitry Andric 180b57cec5SDimitry Andricnamespace std 190b57cec5SDimitry Andric{ 200b57cec5SDimitry Andric 210b57cec5SDimitry Andricnamespace std { 220b57cec5SDimitry Andric 230b57cec5SDimitry Andrictemplate <size_t N> 240b57cec5SDimitry Andricclass bitset 250b57cec5SDimitry Andric{ 260b57cec5SDimitry Andricpublic: 270b57cec5SDimitry Andric // bit reference: 280b57cec5SDimitry Andric class reference 290b57cec5SDimitry Andric { 300b57cec5SDimitry Andric friend class bitset; 310b57cec5SDimitry Andric reference() noexcept; 320b57cec5SDimitry Andric public: 330b57cec5SDimitry Andric ~reference() noexcept; 340b57cec5SDimitry Andric reference& operator=(bool x) noexcept; // for b[i] = x; 350b57cec5SDimitry Andric reference& operator=(const reference&) noexcept; // for b[i] = b[j]; 360b57cec5SDimitry Andric bool operator~() const noexcept; // flips the bit 370b57cec5SDimitry Andric operator bool() const noexcept; // for x = b[i]; 380b57cec5SDimitry Andric reference& flip() noexcept; // for b[i].flip(); 390b57cec5SDimitry Andric }; 400b57cec5SDimitry Andric 410b57cec5SDimitry Andric // 23.3.5.1 constructors: 420b57cec5SDimitry Andric constexpr bitset() noexcept; 430b57cec5SDimitry Andric constexpr bitset(unsigned long long val) noexcept; 440b57cec5SDimitry Andric template <class charT> 45*5f757f3fSDimitry Andric constexpr explicit bitset(const charT* str, 460b57cec5SDimitry Andric typename basic_string<charT>::size_type n = basic_string<charT>::npos, 47*5f757f3fSDimitry Andric charT zero = charT('0'), charT one = charT('1')); // until C++26, constexpr since C++23 48*5f757f3fSDimitry Andric template <class charT> 49*5f757f3fSDimitry Andric constexpr explicit bitset(const charT* str, 50*5f757f3fSDimitry Andric typename basic_string_view<charT>::size_type n = basic_string_view<charT>::npos, 51*5f757f3fSDimitry Andric charT zero = charT('0'), charT one = charT('1')); // since C++26 52*5f757f3fSDimitry Andric template<class charT, class traits> 53*5f757f3fSDimitry Andric explicit bitset( 54*5f757f3fSDimitry Andric const basic_string_view<charT,traits>& str, 55*5f757f3fSDimitry Andric typename basic_string_view<charT,traits>::size_type pos = 0, 56*5f757f3fSDimitry Andric typename basic_string_view<charT,traits>::size_type n = basic_string_view<charT,traits>::npos, 57*5f757f3fSDimitry Andric charT zero = charT('0'), charT one = charT('1')); // since C++26 580b57cec5SDimitry Andric template<class charT, class traits, class Allocator> 59*5f757f3fSDimitry Andric constexpr explicit bitset( 60*5f757f3fSDimitry Andric const basic_string<charT,traits,Allocator>& str, 610b57cec5SDimitry Andric typename basic_string<charT,traits,Allocator>::size_type pos = 0, 62*5f757f3fSDimitry Andric typename basic_string<charT,traits,Allocator>::size_type n = basic_string<charT,traits,Allocator>::npos, 63bdd1243dSDimitry Andric charT zero = charT('0'), charT one = charT('1')); // constexpr since C++23 640b57cec5SDimitry Andric 650b57cec5SDimitry Andric // 23.3.5.2 bitset operations: 66bdd1243dSDimitry Andric bitset& operator&=(const bitset& rhs) noexcept; // constexpr since C++23 67bdd1243dSDimitry Andric bitset& operator|=(const bitset& rhs) noexcept; // constexpr since C++23 68bdd1243dSDimitry Andric bitset& operator^=(const bitset& rhs) noexcept; // constexpr since C++23 69bdd1243dSDimitry Andric bitset& operator<<=(size_t pos) noexcept; // constexpr since C++23 70bdd1243dSDimitry Andric bitset& operator>>=(size_t pos) noexcept; // constexpr since C++23 71bdd1243dSDimitry Andric bitset& set() noexcept; // constexpr since C++23 72bdd1243dSDimitry Andric bitset& set(size_t pos, bool val = true); // constexpr since C++23 73bdd1243dSDimitry Andric bitset& reset() noexcept; // constexpr since C++23 74bdd1243dSDimitry Andric bitset& reset(size_t pos); // constexpr since C++23 75bdd1243dSDimitry Andric bitset operator~() const noexcept; // constexpr since C++23 76bdd1243dSDimitry Andric bitset& flip() noexcept; // constexpr since C++23 77bdd1243dSDimitry Andric bitset& flip(size_t pos); // constexpr since C++23 780b57cec5SDimitry Andric 790b57cec5SDimitry Andric // element access: 80bdd1243dSDimitry Andric constexpr bool operator[](size_t pos) const; 81bdd1243dSDimitry Andric reference operator[](size_t pos); // constexpr since C++23 82bdd1243dSDimitry Andric unsigned long to_ulong() const; // constexpr since C++23 83bdd1243dSDimitry Andric unsigned long long to_ullong() const; // constexpr since C++23 84bdd1243dSDimitry Andric template <class charT, class traits, class Allocator> // constexpr since C++23 850b57cec5SDimitry Andric basic_string<charT, traits, Allocator> to_string(charT zero = charT('0'), charT one = charT('1')) const; 86bdd1243dSDimitry Andric template <class charT, class traits> // constexpr since C++23 870b57cec5SDimitry Andric basic_string<charT, traits, allocator<charT> > to_string(charT zero = charT('0'), charT one = charT('1')) const; 88bdd1243dSDimitry Andric template <class charT> // constexpr since C++23 890b57cec5SDimitry Andric basic_string<charT, char_traits<charT>, allocator<charT> > to_string(charT zero = charT('0'), charT one = charT('1')) const; 90bdd1243dSDimitry Andric basic_string<char, char_traits<char>, allocator<char> > to_string(char zero = '0', char one = '1') const; // constexpr since C++23 91bdd1243dSDimitry Andric size_t count() const noexcept; // constexpr since C++23 92bdd1243dSDimitry Andric constexpr size_t size() const noexcept; // constexpr since C++23 93bdd1243dSDimitry Andric bool operator==(const bitset& rhs) const noexcept; // constexpr since C++23 9406c3fb27SDimitry Andric bool operator!=(const bitset& rhs) const noexcept; // removed in C++20 95bdd1243dSDimitry Andric bool test(size_t pos) const; // constexpr since C++23 96bdd1243dSDimitry Andric bool all() const noexcept; // constexpr since C++23 97bdd1243dSDimitry Andric bool any() const noexcept; // constexpr since C++23 98bdd1243dSDimitry Andric bool none() const noexcept; // constexpr since C++23 99bdd1243dSDimitry Andric bitset<N> operator<<(size_t pos) const noexcept; // constexpr since C++23 100bdd1243dSDimitry Andric bitset<N> operator>>(size_t pos) const noexcept; // constexpr since C++23 1010b57cec5SDimitry Andric}; 1020b57cec5SDimitry Andric 1030b57cec5SDimitry Andric// 23.3.5.3 bitset operators: 1040b57cec5SDimitry Andrictemplate <size_t N> 105bdd1243dSDimitry Andricbitset<N> operator&(const bitset<N>&, const bitset<N>&) noexcept; // constexpr since C++23 1060b57cec5SDimitry Andric 1070b57cec5SDimitry Andrictemplate <size_t N> 108bdd1243dSDimitry Andricbitset<N> operator|(const bitset<N>&, const bitset<N>&) noexcept; // constexpr since C++23 1090b57cec5SDimitry Andric 1100b57cec5SDimitry Andrictemplate <size_t N> 111bdd1243dSDimitry Andricbitset<N> operator^(const bitset<N>&, const bitset<N>&) noexcept; // constexpr since C++23 1120b57cec5SDimitry Andric 1130b57cec5SDimitry Andrictemplate <class charT, class traits, size_t N> 1140b57cec5SDimitry Andricbasic_istream<charT, traits>& 1150b57cec5SDimitry Andricoperator>>(basic_istream<charT, traits>& is, bitset<N>& x); 1160b57cec5SDimitry Andric 1170b57cec5SDimitry Andrictemplate <class charT, class traits, size_t N> 1180b57cec5SDimitry Andricbasic_ostream<charT, traits>& 1190b57cec5SDimitry Andricoperator<<(basic_ostream<charT, traits>& os, const bitset<N>& x); 1200b57cec5SDimitry Andric 1210b57cec5SDimitry Andrictemplate <size_t N> struct hash<std::bitset<N>>; 1220b57cec5SDimitry Andric 1230b57cec5SDimitry Andric} // std 1240b57cec5SDimitry Andric 1250b57cec5SDimitry Andric*/ 1260b57cec5SDimitry Andric 127*5f757f3fSDimitry Andric// clang-format on 128*5f757f3fSDimitry Andric 129*5f757f3fSDimitry Andric#include <__algorithm/count.h> 13081ad6265SDimitry Andric#include <__algorithm/fill.h> 131*5f757f3fSDimitry Andric#include <__algorithm/find.h> 13281ad6265SDimitry Andric#include <__assert> // all public C++ headers provide the assertion handler 1330b57cec5SDimitry Andric#include <__bit_reference> 13404eeddc0SDimitry Andric#include <__config> 13581ad6265SDimitry Andric#include <__functional/hash.h> 13681ad6265SDimitry Andric#include <__functional/unary_function.h> 137bdd1243dSDimitry Andric#include <__type_traits/is_char_like_type.h> 138fe6060f1SDimitry Andric#include <climits> 139fe6060f1SDimitry Andric#include <cstddef> 140fe6060f1SDimitry Andric#include <stdexcept> 14106c3fb27SDimitry Andric#include <string_view> 14204eeddc0SDimitry Andric#include <version> 1430b57cec5SDimitry Andric 14481ad6265SDimitry Andric// standard-mandated includes 145bdd1243dSDimitry Andric 146bdd1243dSDimitry Andric// [bitset.syn] 14781ad6265SDimitry Andric#include <iosfwd> 14881ad6265SDimitry Andric#include <string> 14981ad6265SDimitry Andric 1500b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 1510b57cec5SDimitry Andric# pragma GCC system_header 1520b57cec5SDimitry Andric#endif 1530b57cec5SDimitry Andric 1540b57cec5SDimitry Andric_LIBCPP_PUSH_MACROS 1550b57cec5SDimitry Andric#include <__undef_macros> 1560b57cec5SDimitry Andric 1570b57cec5SDimitry Andric 1580b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD 1590b57cec5SDimitry Andric 1600b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 1610b57cec5SDimitry Andricclass __bitset; 1620b57cec5SDimitry Andric 1630b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 1640b57cec5SDimitry Andricstruct __has_storage_type<__bitset<_N_words, _Size> > 1650b57cec5SDimitry Andric{ 1660b57cec5SDimitry Andric static const bool value = true; 1670b57cec5SDimitry Andric}; 1680b57cec5SDimitry Andric 1690b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 1700b57cec5SDimitry Andricclass __bitset 1710b57cec5SDimitry Andric{ 1720b57cec5SDimitry Andricpublic: 1730b57cec5SDimitry Andric typedef ptrdiff_t difference_type; 1740b57cec5SDimitry Andric typedef size_t size_type; 1750b57cec5SDimitry Andric typedef size_type __storage_type; 1760b57cec5SDimitry Andricprotected: 1770b57cec5SDimitry Andric typedef __bitset __self; 1780b57cec5SDimitry Andric typedef __storage_type* __storage_pointer; 1790b57cec5SDimitry Andric typedef const __storage_type* __const_storage_pointer; 1800b57cec5SDimitry Andric static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT); 1810b57cec5SDimitry Andric 1820b57cec5SDimitry Andric friend class __bit_reference<__bitset>; 1830b57cec5SDimitry Andric friend class __bit_const_reference<__bitset>; 1840b57cec5SDimitry Andric friend class __bit_iterator<__bitset, false>; 1850b57cec5SDimitry Andric friend class __bit_iterator<__bitset, true>; 1860b57cec5SDimitry Andric friend struct __bit_array<__bitset>; 1870b57cec5SDimitry Andric 1880b57cec5SDimitry Andric __storage_type __first_[_N_words]; 1890b57cec5SDimitry Andric 1900b57cec5SDimitry Andric typedef __bit_reference<__bitset> reference; 1910b57cec5SDimitry Andric typedef __bit_const_reference<__bitset> const_reference; 1920b57cec5SDimitry Andric typedef __bit_iterator<__bitset, false> iterator; 1930b57cec5SDimitry Andric typedef __bit_iterator<__bitset, true> const_iterator; 1940b57cec5SDimitry Andric 195*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI 1960b57cec5SDimitry Andric _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT; 197*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI 1980b57cec5SDimitry Andric explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT; 1990b57cec5SDimitry Andric 200*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 reference __make_ref(size_t __pos) _NOEXCEPT 2010b57cec5SDimitry Andric {return reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);} 202*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT 2030b57cec5SDimitry Andric {return const_reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);} 204*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 iterator __make_iter(size_t __pos) _NOEXCEPT 2050b57cec5SDimitry Andric {return iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);} 206*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 const_iterator __make_iter(size_t __pos) const _NOEXCEPT 2070b57cec5SDimitry Andric {return const_iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);} 2080b57cec5SDimitry Andric 209*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 2100b57cec5SDimitry Andric void operator&=(const __bitset& __v) _NOEXCEPT; 211*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 2120b57cec5SDimitry Andric void operator|=(const __bitset& __v) _NOEXCEPT; 213*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 2140b57cec5SDimitry Andric void operator^=(const __bitset& __v) _NOEXCEPT; 2150b57cec5SDimitry Andric 216bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void flip() _NOEXCEPT; 217*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong() const 2180b57cec5SDimitry Andric {return to_ulong(integral_constant<bool, _Size < sizeof(unsigned long) * CHAR_BIT>());} 219*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong() const 2200b57cec5SDimitry Andric {return to_ullong(integral_constant<bool, _Size < sizeof(unsigned long long) * CHAR_BIT>());} 2210b57cec5SDimitry Andric 222bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT; 223bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT; 224*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI 2250b57cec5SDimitry Andric size_t __hash_code() const _NOEXCEPT; 2260b57cec5SDimitry Andricprivate: 2270b57cec5SDimitry Andric#ifdef _LIBCPP_CXX03_LANG 2280b57cec5SDimitry Andric void __init(unsigned long long __v, false_type) _NOEXCEPT; 229*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI 2300b57cec5SDimitry Andric void __init(unsigned long long __v, true_type) _NOEXCEPT; 2310b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 232bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 2330b57cec5SDimitry Andric unsigned long to_ulong(false_type) const; 234*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 2350b57cec5SDimitry Andric unsigned long to_ulong(true_type) const; 236bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 2370b57cec5SDimitry Andric unsigned long long to_ullong(false_type) const; 238*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 2390b57cec5SDimitry Andric unsigned long long to_ullong(true_type) const; 240*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 2410b57cec5SDimitry Andric unsigned long long to_ullong(true_type, false_type) const; 242bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 2430b57cec5SDimitry Andric unsigned long long to_ullong(true_type, true_type) const; 2440b57cec5SDimitry Andric}; 2450b57cec5SDimitry Andric 2460b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 2470b57cec5SDimitry Andricinline 2480b57cec5SDimitry Andric_LIBCPP_CONSTEXPR 2490b57cec5SDimitry Andric__bitset<_N_words, _Size>::__bitset() _NOEXCEPT 2500b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 2510b57cec5SDimitry Andric : __first_{0} 2520b57cec5SDimitry Andric#endif 2530b57cec5SDimitry Andric{ 2540b57cec5SDimitry Andric#ifdef _LIBCPP_CXX03_LANG 255*5f757f3fSDimitry Andric std::fill_n(__first_, _N_words, __storage_type(0)); 2560b57cec5SDimitry Andric#endif 2570b57cec5SDimitry Andric} 2580b57cec5SDimitry Andric 2590b57cec5SDimitry Andric#ifdef _LIBCPP_CXX03_LANG 2600b57cec5SDimitry Andric 2610b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 2620b57cec5SDimitry Andricvoid 2630b57cec5SDimitry Andric__bitset<_N_words, _Size>::__init(unsigned long long __v, false_type) _NOEXCEPT 2640b57cec5SDimitry Andric{ 2650b57cec5SDimitry Andric __storage_type __t[sizeof(unsigned long long) / sizeof(__storage_type)]; 2660b57cec5SDimitry Andric size_t __sz = _Size; 2670b57cec5SDimitry Andric for (size_t __i = 0; __i < sizeof(__t)/sizeof(__t[0]); ++__i, __v >>= __bits_per_word, __sz -= __bits_per_word ) 2680b57cec5SDimitry Andric if ( __sz < __bits_per_word) 2690b57cec5SDimitry Andric __t[__i] = static_cast<__storage_type>(__v) & ( 1ULL << __sz ) - 1; 2700b57cec5SDimitry Andric else 2710b57cec5SDimitry Andric __t[__i] = static_cast<__storage_type>(__v); 2720b57cec5SDimitry Andric 273*5f757f3fSDimitry Andric std::copy(__t, __t + sizeof(__t)/sizeof(__t[0]), __first_); 274*5f757f3fSDimitry Andric std::fill(__first_ + sizeof(__t)/sizeof(__t[0]), __first_ + sizeof(__first_)/sizeof(__first_[0]), 2750b57cec5SDimitry Andric __storage_type(0)); 2760b57cec5SDimitry Andric} 2770b57cec5SDimitry Andric 2780b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 279*5f757f3fSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 2800b57cec5SDimitry Andricvoid 2810b57cec5SDimitry Andric__bitset<_N_words, _Size>::__init(unsigned long long __v, true_type) _NOEXCEPT 2820b57cec5SDimitry Andric{ 2830b57cec5SDimitry Andric __first_[0] = __v; 2840b57cec5SDimitry Andric if (_Size < __bits_per_word) 2850b57cec5SDimitry Andric __first_[0] &= ( 1ULL << _Size ) - 1; 2860b57cec5SDimitry Andric 287*5f757f3fSDimitry Andric std::fill(__first_ + 1, __first_ + sizeof(__first_)/sizeof(__first_[0]), __storage_type(0)); 2880b57cec5SDimitry Andric} 2890b57cec5SDimitry Andric 2900b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 2910b57cec5SDimitry Andric 2920b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 2930b57cec5SDimitry Andricinline 2940b57cec5SDimitry Andric_LIBCPP_CONSTEXPR 2950b57cec5SDimitry Andric__bitset<_N_words, _Size>::__bitset(unsigned long long __v) _NOEXCEPT 2960b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 2970b57cec5SDimitry Andric#if __SIZEOF_SIZE_T__ == 8 2980b57cec5SDimitry Andric : __first_{__v} 2990b57cec5SDimitry Andric#elif __SIZEOF_SIZE_T__ == 4 3000b57cec5SDimitry Andric : __first_{static_cast<__storage_type>(__v), 3010b57cec5SDimitry Andric _Size >= 2 * __bits_per_word ? static_cast<__storage_type>(__v >> __bits_per_word) 3020b57cec5SDimitry Andric : static_cast<__storage_type>((__v >> __bits_per_word) & (__storage_type(1) << (_Size - __bits_per_word)) - 1)} 3030b57cec5SDimitry Andric#else 3040b57cec5SDimitry Andric#error This constructor has not been ported to this platform 3050b57cec5SDimitry Andric#endif 3060b57cec5SDimitry Andric#endif 3070b57cec5SDimitry Andric{ 3080b57cec5SDimitry Andric#ifdef _LIBCPP_CXX03_LANG 3090b57cec5SDimitry Andric __init(__v, integral_constant<bool, sizeof(unsigned long long) == sizeof(__storage_type)>()); 3100b57cec5SDimitry Andric#endif 3110b57cec5SDimitry Andric} 3120b57cec5SDimitry Andric 3130b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 3140b57cec5SDimitry Andricinline 315bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void 3160b57cec5SDimitry Andric__bitset<_N_words, _Size>::operator&=(const __bitset& __v) _NOEXCEPT 3170b57cec5SDimitry Andric{ 3180b57cec5SDimitry Andric for (size_type __i = 0; __i < _N_words; ++__i) 3190b57cec5SDimitry Andric __first_[__i] &= __v.__first_[__i]; 3200b57cec5SDimitry Andric} 3210b57cec5SDimitry Andric 3220b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 3230b57cec5SDimitry Andricinline 324bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void 3250b57cec5SDimitry Andric__bitset<_N_words, _Size>::operator|=(const __bitset& __v) _NOEXCEPT 3260b57cec5SDimitry Andric{ 3270b57cec5SDimitry Andric for (size_type __i = 0; __i < _N_words; ++__i) 3280b57cec5SDimitry Andric __first_[__i] |= __v.__first_[__i]; 3290b57cec5SDimitry Andric} 3300b57cec5SDimitry Andric 3310b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 3320b57cec5SDimitry Andricinline 333bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void 3340b57cec5SDimitry Andric__bitset<_N_words, _Size>::operator^=(const __bitset& __v) _NOEXCEPT 3350b57cec5SDimitry Andric{ 3360b57cec5SDimitry Andric for (size_type __i = 0; __i < _N_words; ++__i) 3370b57cec5SDimitry Andric __first_[__i] ^= __v.__first_[__i]; 3380b57cec5SDimitry Andric} 3390b57cec5SDimitry Andric 3400b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 341bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void 3420b57cec5SDimitry Andric__bitset<_N_words, _Size>::flip() _NOEXCEPT 3430b57cec5SDimitry Andric{ 3440b57cec5SDimitry Andric // do middle whole words 3450b57cec5SDimitry Andric size_type __n = _Size; 3460b57cec5SDimitry Andric __storage_pointer __p = __first_; 3470b57cec5SDimitry Andric for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) 3480b57cec5SDimitry Andric *__p = ~*__p; 3490b57cec5SDimitry Andric // do last partial word 3500b57cec5SDimitry Andric if (__n > 0) 3510b57cec5SDimitry Andric { 3520b57cec5SDimitry Andric __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); 3530b57cec5SDimitry Andric __storage_type __b = *__p & __m; 3540b57cec5SDimitry Andric *__p &= ~__m; 3550b57cec5SDimitry Andric *__p |= ~__b & __m; 3560b57cec5SDimitry Andric } 3570b57cec5SDimitry Andric} 3580b57cec5SDimitry Andric 3590b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 360bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long 3610b57cec5SDimitry Andric__bitset<_N_words, _Size>::to_ulong(false_type) const 3620b57cec5SDimitry Andric{ 3630b57cec5SDimitry Andric const_iterator __e = __make_iter(_Size); 364*5f757f3fSDimitry Andric const_iterator __i = std::find(__make_iter(sizeof(unsigned long) * CHAR_BIT), __e, true); 3650b57cec5SDimitry Andric if (__i != __e) 3660b57cec5SDimitry Andric __throw_overflow_error("bitset to_ulong overflow error"); 3670b57cec5SDimitry Andric 3680b57cec5SDimitry Andric return __first_[0]; 3690b57cec5SDimitry Andric} 3700b57cec5SDimitry Andric 3710b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 3720b57cec5SDimitry Andricinline 373bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long 3740b57cec5SDimitry Andric__bitset<_N_words, _Size>::to_ulong(true_type) const 3750b57cec5SDimitry Andric{ 3760b57cec5SDimitry Andric return __first_[0]; 3770b57cec5SDimitry Andric} 3780b57cec5SDimitry Andric 3790b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 380bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long 3810b57cec5SDimitry Andric__bitset<_N_words, _Size>::to_ullong(false_type) const 3820b57cec5SDimitry Andric{ 3830b57cec5SDimitry Andric const_iterator __e = __make_iter(_Size); 384*5f757f3fSDimitry Andric const_iterator __i = std::find(__make_iter(sizeof(unsigned long long) * CHAR_BIT), __e, true); 3850b57cec5SDimitry Andric if (__i != __e) 3860b57cec5SDimitry Andric __throw_overflow_error("bitset to_ullong overflow error"); 3870b57cec5SDimitry Andric 3880b57cec5SDimitry Andric return to_ullong(true_type()); 3890b57cec5SDimitry Andric} 3900b57cec5SDimitry Andric 3910b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 3920b57cec5SDimitry Andricinline 393bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long 3940b57cec5SDimitry Andric__bitset<_N_words, _Size>::to_ullong(true_type) const 3950b57cec5SDimitry Andric{ 3960b57cec5SDimitry Andric return to_ullong(true_type(), integral_constant<bool, sizeof(__storage_type) < sizeof(unsigned long long)>()); 3970b57cec5SDimitry Andric} 3980b57cec5SDimitry Andric 3990b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 4000b57cec5SDimitry Andricinline 401bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long 4020b57cec5SDimitry Andric__bitset<_N_words, _Size>::to_ullong(true_type, false_type) const 4030b57cec5SDimitry Andric{ 4040b57cec5SDimitry Andric return __first_[0]; 4050b57cec5SDimitry Andric} 4060b57cec5SDimitry Andric 4070b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 408bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long 4090b57cec5SDimitry Andric__bitset<_N_words, _Size>::to_ullong(true_type, true_type) const 4100b57cec5SDimitry Andric{ 4110b57cec5SDimitry Andric unsigned long long __r = __first_[0]; 412e8d8bef9SDimitry Andric for (size_t __i = 1; __i < sizeof(unsigned long long) / sizeof(__storage_type); ++__i) 4130b57cec5SDimitry Andric __r |= static_cast<unsigned long long>(__first_[__i]) << (sizeof(__storage_type) * CHAR_BIT); 4140b57cec5SDimitry Andric return __r; 4150b57cec5SDimitry Andric} 4160b57cec5SDimitry Andric 4170b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 418bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool 4190b57cec5SDimitry Andric__bitset<_N_words, _Size>::all() const _NOEXCEPT 4200b57cec5SDimitry Andric{ 4210b57cec5SDimitry Andric // do middle whole words 4220b57cec5SDimitry Andric size_type __n = _Size; 4230b57cec5SDimitry Andric __const_storage_pointer __p = __first_; 4240b57cec5SDimitry Andric for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) 4250b57cec5SDimitry Andric if (~*__p) 4260b57cec5SDimitry Andric return false; 4270b57cec5SDimitry Andric // do last partial word 4280b57cec5SDimitry Andric if (__n > 0) 4290b57cec5SDimitry Andric { 4300b57cec5SDimitry Andric __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); 4310b57cec5SDimitry Andric if (~*__p & __m) 4320b57cec5SDimitry Andric return false; 4330b57cec5SDimitry Andric } 4340b57cec5SDimitry Andric return true; 4350b57cec5SDimitry Andric} 4360b57cec5SDimitry Andric 4370b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 438bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool 4390b57cec5SDimitry Andric__bitset<_N_words, _Size>::any() const _NOEXCEPT 4400b57cec5SDimitry Andric{ 4410b57cec5SDimitry Andric // do middle whole words 4420b57cec5SDimitry Andric size_type __n = _Size; 4430b57cec5SDimitry Andric __const_storage_pointer __p = __first_; 4440b57cec5SDimitry Andric for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) 4450b57cec5SDimitry Andric if (*__p) 4460b57cec5SDimitry Andric return true; 4470b57cec5SDimitry Andric // do last partial word 4480b57cec5SDimitry Andric if (__n > 0) 4490b57cec5SDimitry Andric { 4500b57cec5SDimitry Andric __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); 4510b57cec5SDimitry Andric if (*__p & __m) 4520b57cec5SDimitry Andric return true; 4530b57cec5SDimitry Andric } 4540b57cec5SDimitry Andric return false; 4550b57cec5SDimitry Andric} 4560b57cec5SDimitry Andric 4570b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 4580b57cec5SDimitry Andricinline 4590b57cec5SDimitry Andricsize_t 4600b57cec5SDimitry Andric__bitset<_N_words, _Size>::__hash_code() const _NOEXCEPT 4610b57cec5SDimitry Andric{ 4620b57cec5SDimitry Andric size_t __h = 0; 4630b57cec5SDimitry Andric for (size_type __i = 0; __i < _N_words; ++__i) 4640b57cec5SDimitry Andric __h ^= __first_[__i]; 4650b57cec5SDimitry Andric return __h; 4660b57cec5SDimitry Andric} 4670b57cec5SDimitry Andric 4680b57cec5SDimitry Andrictemplate <size_t _Size> 4690b57cec5SDimitry Andricclass __bitset<1, _Size> 4700b57cec5SDimitry Andric{ 4710b57cec5SDimitry Andricpublic: 4720b57cec5SDimitry Andric typedef ptrdiff_t difference_type; 4730b57cec5SDimitry Andric typedef size_t size_type; 4740b57cec5SDimitry Andric typedef size_type __storage_type; 4750b57cec5SDimitry Andricprotected: 4760b57cec5SDimitry Andric typedef __bitset __self; 4770b57cec5SDimitry Andric typedef __storage_type* __storage_pointer; 4780b57cec5SDimitry Andric typedef const __storage_type* __const_storage_pointer; 4790b57cec5SDimitry Andric static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT); 4800b57cec5SDimitry Andric 4810b57cec5SDimitry Andric friend class __bit_reference<__bitset>; 4820b57cec5SDimitry Andric friend class __bit_const_reference<__bitset>; 4830b57cec5SDimitry Andric friend class __bit_iterator<__bitset, false>; 4840b57cec5SDimitry Andric friend class __bit_iterator<__bitset, true>; 4850b57cec5SDimitry Andric friend struct __bit_array<__bitset>; 4860b57cec5SDimitry Andric 4870b57cec5SDimitry Andric __storage_type __first_; 4880b57cec5SDimitry Andric 4890b57cec5SDimitry Andric typedef __bit_reference<__bitset> reference; 4900b57cec5SDimitry Andric typedef __bit_const_reference<__bitset> const_reference; 4910b57cec5SDimitry Andric typedef __bit_iterator<__bitset, false> iterator; 4920b57cec5SDimitry Andric typedef __bit_iterator<__bitset, true> const_iterator; 4930b57cec5SDimitry Andric 494*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI 4950b57cec5SDimitry Andric _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT; 496*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI 4970b57cec5SDimitry Andric explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT; 4980b57cec5SDimitry Andric 499*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 reference __make_ref(size_t __pos) _NOEXCEPT 5000b57cec5SDimitry Andric {return reference(&__first_, __storage_type(1) << __pos);} 501*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT 5020b57cec5SDimitry Andric {return const_reference(&__first_, __storage_type(1) << __pos);} 503*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 iterator __make_iter(size_t __pos) _NOEXCEPT 5040b57cec5SDimitry Andric {return iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);} 505*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 const_iterator __make_iter(size_t __pos) const _NOEXCEPT 5060b57cec5SDimitry Andric {return const_iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);} 5070b57cec5SDimitry Andric 508*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 5090b57cec5SDimitry Andric void operator&=(const __bitset& __v) _NOEXCEPT; 510*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 5110b57cec5SDimitry Andric void operator|=(const __bitset& __v) _NOEXCEPT; 512*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 5130b57cec5SDimitry Andric void operator^=(const __bitset& __v) _NOEXCEPT; 5140b57cec5SDimitry Andric 515*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 5160b57cec5SDimitry Andric void flip() _NOEXCEPT; 5170b57cec5SDimitry Andric 518*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 5190b57cec5SDimitry Andric unsigned long to_ulong() const; 520*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 5210b57cec5SDimitry Andric unsigned long long to_ullong() const; 5220b57cec5SDimitry Andric 523*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 5240b57cec5SDimitry Andric bool all() const _NOEXCEPT; 525*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 5260b57cec5SDimitry Andric bool any() const _NOEXCEPT; 5270b57cec5SDimitry Andric 528*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI 5290b57cec5SDimitry Andric size_t __hash_code() const _NOEXCEPT; 5300b57cec5SDimitry Andric}; 5310b57cec5SDimitry Andric 5320b57cec5SDimitry Andrictemplate <size_t _Size> 5330b57cec5SDimitry Andricinline 5340b57cec5SDimitry Andric_LIBCPP_CONSTEXPR 5350b57cec5SDimitry Andric__bitset<1, _Size>::__bitset() _NOEXCEPT 5360b57cec5SDimitry Andric : __first_(0) 5370b57cec5SDimitry Andric{ 5380b57cec5SDimitry Andric} 5390b57cec5SDimitry Andric 5400b57cec5SDimitry Andrictemplate <size_t _Size> 5410b57cec5SDimitry Andricinline 5420b57cec5SDimitry Andric_LIBCPP_CONSTEXPR 5430b57cec5SDimitry Andric__bitset<1, _Size>::__bitset(unsigned long long __v) _NOEXCEPT 5440b57cec5SDimitry Andric : __first_( 5450b57cec5SDimitry Andric _Size == __bits_per_word ? static_cast<__storage_type>(__v) 5460b57cec5SDimitry Andric : static_cast<__storage_type>(__v) & ((__storage_type(1) << _Size) - 1) 5470b57cec5SDimitry Andric ) 5480b57cec5SDimitry Andric{ 5490b57cec5SDimitry Andric} 5500b57cec5SDimitry Andric 5510b57cec5SDimitry Andrictemplate <size_t _Size> 5520b57cec5SDimitry Andricinline 553bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void 5540b57cec5SDimitry Andric__bitset<1, _Size>::operator&=(const __bitset& __v) _NOEXCEPT 5550b57cec5SDimitry Andric{ 5560b57cec5SDimitry Andric __first_ &= __v.__first_; 5570b57cec5SDimitry Andric} 5580b57cec5SDimitry Andric 5590b57cec5SDimitry Andrictemplate <size_t _Size> 5600b57cec5SDimitry Andricinline 561bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void 5620b57cec5SDimitry Andric__bitset<1, _Size>::operator|=(const __bitset& __v) _NOEXCEPT 5630b57cec5SDimitry Andric{ 5640b57cec5SDimitry Andric __first_ |= __v.__first_; 5650b57cec5SDimitry Andric} 5660b57cec5SDimitry Andric 5670b57cec5SDimitry Andrictemplate <size_t _Size> 5680b57cec5SDimitry Andricinline 569bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void 5700b57cec5SDimitry Andric__bitset<1, _Size>::operator^=(const __bitset& __v) _NOEXCEPT 5710b57cec5SDimitry Andric{ 5720b57cec5SDimitry Andric __first_ ^= __v.__first_; 5730b57cec5SDimitry Andric} 5740b57cec5SDimitry Andric 5750b57cec5SDimitry Andrictemplate <size_t _Size> 5760b57cec5SDimitry Andricinline 577bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void 5780b57cec5SDimitry Andric__bitset<1, _Size>::flip() _NOEXCEPT 5790b57cec5SDimitry Andric{ 5800b57cec5SDimitry Andric __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size); 5810b57cec5SDimitry Andric __first_ = ~__first_; 5820b57cec5SDimitry Andric __first_ &= __m; 5830b57cec5SDimitry Andric} 5840b57cec5SDimitry Andric 5850b57cec5SDimitry Andrictemplate <size_t _Size> 5860b57cec5SDimitry Andricinline 587bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long 5880b57cec5SDimitry Andric__bitset<1, _Size>::to_ulong() const 5890b57cec5SDimitry Andric{ 5900b57cec5SDimitry Andric return __first_; 5910b57cec5SDimitry Andric} 5920b57cec5SDimitry Andric 5930b57cec5SDimitry Andrictemplate <size_t _Size> 5940b57cec5SDimitry Andricinline 595bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long 5960b57cec5SDimitry Andric__bitset<1, _Size>::to_ullong() const 5970b57cec5SDimitry Andric{ 5980b57cec5SDimitry Andric return __first_; 5990b57cec5SDimitry Andric} 6000b57cec5SDimitry Andric 6010b57cec5SDimitry Andrictemplate <size_t _Size> 6020b57cec5SDimitry Andricinline 603bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool 6040b57cec5SDimitry Andric__bitset<1, _Size>::all() const _NOEXCEPT 6050b57cec5SDimitry Andric{ 6060b57cec5SDimitry Andric __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size); 6070b57cec5SDimitry Andric return !(~__first_ & __m); 6080b57cec5SDimitry Andric} 6090b57cec5SDimitry Andric 6100b57cec5SDimitry Andrictemplate <size_t _Size> 6110b57cec5SDimitry Andricinline 612bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool 6130b57cec5SDimitry Andric__bitset<1, _Size>::any() const _NOEXCEPT 6140b57cec5SDimitry Andric{ 6150b57cec5SDimitry Andric __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size); 6160b57cec5SDimitry Andric return __first_ & __m; 6170b57cec5SDimitry Andric} 6180b57cec5SDimitry Andric 6190b57cec5SDimitry Andrictemplate <size_t _Size> 6200b57cec5SDimitry Andricinline 6210b57cec5SDimitry Andricsize_t 6220b57cec5SDimitry Andric__bitset<1, _Size>::__hash_code() const _NOEXCEPT 6230b57cec5SDimitry Andric{ 6240b57cec5SDimitry Andric return __first_; 6250b57cec5SDimitry Andric} 6260b57cec5SDimitry Andric 6270b57cec5SDimitry Andrictemplate <> 6280b57cec5SDimitry Andricclass __bitset<0, 0> 6290b57cec5SDimitry Andric{ 6300b57cec5SDimitry Andricpublic: 6310b57cec5SDimitry Andric typedef ptrdiff_t difference_type; 6320b57cec5SDimitry Andric typedef size_t size_type; 6330b57cec5SDimitry Andric typedef size_type __storage_type; 6340b57cec5SDimitry Andricprotected: 6350b57cec5SDimitry Andric typedef __bitset __self; 6360b57cec5SDimitry Andric typedef __storage_type* __storage_pointer; 6370b57cec5SDimitry Andric typedef const __storage_type* __const_storage_pointer; 6380b57cec5SDimitry Andric static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT); 6390b57cec5SDimitry Andric 6400b57cec5SDimitry Andric friend class __bit_reference<__bitset>; 6410b57cec5SDimitry Andric friend class __bit_const_reference<__bitset>; 6420b57cec5SDimitry Andric friend class __bit_iterator<__bitset, false>; 6430b57cec5SDimitry Andric friend class __bit_iterator<__bitset, true>; 6440b57cec5SDimitry Andric friend struct __bit_array<__bitset>; 6450b57cec5SDimitry Andric 6460b57cec5SDimitry Andric typedef __bit_reference<__bitset> reference; 6470b57cec5SDimitry Andric typedef __bit_const_reference<__bitset> const_reference; 6480b57cec5SDimitry Andric typedef __bit_iterator<__bitset, false> iterator; 6490b57cec5SDimitry Andric typedef __bit_iterator<__bitset, true> const_iterator; 6500b57cec5SDimitry Andric 651*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI 6520b57cec5SDimitry Andric _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT; 653*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI 6540b57cec5SDimitry Andric explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long) _NOEXCEPT; 6550b57cec5SDimitry Andric 656*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 reference __make_ref(size_t) _NOEXCEPT 657e8d8bef9SDimitry Andric {return reference(nullptr, 1);} 658*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const_reference __make_ref(size_t) const _NOEXCEPT 659e8d8bef9SDimitry Andric {return const_reference(nullptr, 1);} 660*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 iterator __make_iter(size_t) _NOEXCEPT 661e8d8bef9SDimitry Andric {return iterator(nullptr, 0);} 662*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 const_iterator __make_iter(size_t) const _NOEXCEPT 663e8d8bef9SDimitry Andric {return const_iterator(nullptr, 0);} 6640b57cec5SDimitry Andric 665*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator&=(const __bitset&) _NOEXCEPT {} 666*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator|=(const __bitset&) _NOEXCEPT {} 667*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator^=(const __bitset&) _NOEXCEPT {} 6680b57cec5SDimitry Andric 669*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void flip() _NOEXCEPT {} 6700b57cec5SDimitry Andric 671*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong() const {return 0;} 672*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong() const {return 0;} 6730b57cec5SDimitry Andric 674*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT {return true;} 675*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT {return false;} 6760b57cec5SDimitry Andric 677*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI size_t __hash_code() const _NOEXCEPT {return 0;} 6780b57cec5SDimitry Andric}; 6790b57cec5SDimitry Andric 6800b57cec5SDimitry Andricinline 6810b57cec5SDimitry Andric_LIBCPP_CONSTEXPR 6820b57cec5SDimitry Andric__bitset<0, 0>::__bitset() _NOEXCEPT 6830b57cec5SDimitry Andric{ 6840b57cec5SDimitry Andric} 6850b57cec5SDimitry Andric 6860b57cec5SDimitry Andricinline 6870b57cec5SDimitry Andric_LIBCPP_CONSTEXPR 6880b57cec5SDimitry Andric__bitset<0, 0>::__bitset(unsigned long long) _NOEXCEPT 6890b57cec5SDimitry Andric{ 6900b57cec5SDimitry Andric} 6910b57cec5SDimitry Andric 6920b57cec5SDimitry Andrictemplate <size_t _Size> class _LIBCPP_TEMPLATE_VIS bitset; 6930b57cec5SDimitry Andrictemplate <size_t _Size> struct hash<bitset<_Size> >; 6940b57cec5SDimitry Andric 6950b57cec5SDimitry Andrictemplate <size_t _Size> 6960b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS bitset 6970b57cec5SDimitry Andric : private __bitset<_Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1, _Size> 6980b57cec5SDimitry Andric{ 6990b57cec5SDimitry Andricpublic: 7000b57cec5SDimitry Andric static const unsigned __n_words = _Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1; 7010b57cec5SDimitry Andric typedef __bitset<__n_words, _Size> base; 7020b57cec5SDimitry Andric 7030b57cec5SDimitry Andricpublic: 7040b57cec5SDimitry Andric typedef typename base::reference reference; 7050b57cec5SDimitry Andric typedef typename base::const_reference const_reference; 7060b57cec5SDimitry Andric 7070b57cec5SDimitry Andric // 23.3.5.1 constructors: 708*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bitset() _NOEXCEPT {} 709*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR 7100b57cec5SDimitry Andric bitset(unsigned long long __v) _NOEXCEPT : base(__v) {} 711349cc55cSDimitry Andric template <class _CharT, class = __enable_if_t<_IsCharLikeType<_CharT>::value> > 71206c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 explicit bitset( 71306c3fb27SDimitry Andric const _CharT* __str, 714*5f757f3fSDimitry Andric# if _LIBCPP_STD_VER >= 26 715*5f757f3fSDimitry Andric typename basic_string_view<_CharT>::size_type __n = basic_string_view<_CharT>::npos, 716*5f757f3fSDimitry Andric# else 7170b57cec5SDimitry Andric typename basic_string<_CharT>::size_type __n = basic_string<_CharT>::npos, 718*5f757f3fSDimitry Andric# endif 71906c3fb27SDimitry Andric _CharT __zero = _CharT('0'), 72006c3fb27SDimitry Andric _CharT __one = _CharT('1')) { 72106c3fb27SDimitry Andric 72206c3fb27SDimitry Andric size_t __rlen = std::min(__n, char_traits<_CharT>::length(__str)); 72306c3fb27SDimitry Andric __init_from_string_view(basic_string_view<_CharT>(__str, __rlen), __zero, __one); 72406c3fb27SDimitry Andric } 725*5f757f3fSDimitry Andric#if _LIBCPP_STD_VER >= 26 726*5f757f3fSDimitry Andric template <class _CharT, class _Traits> 727*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr explicit bitset( 728*5f757f3fSDimitry Andric basic_string_view<_CharT, _Traits> __str, 729*5f757f3fSDimitry Andric typename basic_string_view<_CharT, _Traits>::size_type __pos = 0, 730*5f757f3fSDimitry Andric typename basic_string_view<_CharT, _Traits>::size_type __n = basic_string_view<_CharT, _Traits>::npos, 731*5f757f3fSDimitry Andric _CharT __zero = _CharT('0'), 732*5f757f3fSDimitry Andric _CharT __one = _CharT('1')) { 733*5f757f3fSDimitry Andric if (__pos > __str.size()) 734*5f757f3fSDimitry Andric __throw_out_of_range("bitset string pos out of range"); 735*5f757f3fSDimitry Andric 736*5f757f3fSDimitry Andric size_t __rlen = std::min(__n, __str.size() - __pos); 737*5f757f3fSDimitry Andric __init_from_string_view(basic_string_view<_CharT, _Traits>(__str.data() + __pos, __rlen), __zero, __one); 738*5f757f3fSDimitry Andric } 739*5f757f3fSDimitry Andric#endif 7400b57cec5SDimitry Andric template <class _CharT, class _Traits, class _Allocator> 74106c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 explicit bitset( 74206c3fb27SDimitry Andric const basic_string<_CharT, _Traits, _Allocator>& __str, 7430b57cec5SDimitry Andric typename basic_string<_CharT, _Traits, _Allocator>::size_type __pos = 0, 7440b57cec5SDimitry Andric typename basic_string<_CharT, _Traits, _Allocator>::size_type __n = 74506c3fb27SDimitry Andric basic_string<_CharT, _Traits, _Allocator>::npos, 74606c3fb27SDimitry Andric _CharT __zero = _CharT('0'), 74706c3fb27SDimitry Andric _CharT __one = _CharT('1')) { 74806c3fb27SDimitry Andric if (__pos > __str.size()) 74906c3fb27SDimitry Andric std::__throw_out_of_range("bitset string pos out of range"); 75006c3fb27SDimitry Andric 75106c3fb27SDimitry Andric size_t __rlen = std::min(__n, __str.size() - __pos); 75206c3fb27SDimitry Andric __init_from_string_view(basic_string_view<_CharT, _Traits>(__str.data() + __pos, __rlen), __zero, __one); 75306c3fb27SDimitry Andric } 7540b57cec5SDimitry Andric 7550b57cec5SDimitry Andric // 23.3.5.2 bitset operations: 756*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 7570b57cec5SDimitry Andric bitset& operator&=(const bitset& __rhs) _NOEXCEPT; 758*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 7590b57cec5SDimitry Andric bitset& operator|=(const bitset& __rhs) _NOEXCEPT; 760*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 7610b57cec5SDimitry Andric bitset& operator^=(const bitset& __rhs) _NOEXCEPT; 762bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 7630b57cec5SDimitry Andric bitset& operator<<=(size_t __pos) _NOEXCEPT; 764bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 7650b57cec5SDimitry Andric bitset& operator>>=(size_t __pos) _NOEXCEPT; 766*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 7670b57cec5SDimitry Andric bitset& set() _NOEXCEPT; 768bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 7690b57cec5SDimitry Andric bitset& set(size_t __pos, bool __val = true); 770*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 7710b57cec5SDimitry Andric bitset& reset() _NOEXCEPT; 772bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 7730b57cec5SDimitry Andric bitset& reset(size_t __pos); 774*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 7750b57cec5SDimitry Andric bitset operator~() const _NOEXCEPT; 776*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 7770b57cec5SDimitry Andric bitset& flip() _NOEXCEPT; 778bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 7790b57cec5SDimitry Andric bitset& flip(size_t __pos); 7800b57cec5SDimitry Andric 7810b57cec5SDimitry Andric // element access: 78281ad6265SDimitry Andric#ifdef _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL 78381ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool operator[](size_t __p) const {return base::__make_ref(__p);} 78481ad6265SDimitry Andric#else 78581ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const_reference operator[](size_t __p) const {return base::__make_ref(__p);} 78681ad6265SDimitry Andric#endif 787bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 reference operator[](size_t __p) {return base::__make_ref(__p);} 788*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 7890b57cec5SDimitry Andric unsigned long to_ulong() const; 790*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 7910b57cec5SDimitry Andric unsigned long long to_ullong() const; 7920b57cec5SDimitry Andric template <class _CharT, class _Traits, class _Allocator> 793bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 7940b57cec5SDimitry Andric basic_string<_CharT, _Traits, _Allocator> to_string(_CharT __zero = _CharT('0'), 7950b57cec5SDimitry Andric _CharT __one = _CharT('1')) const; 7960b57cec5SDimitry Andric template <class _CharT, class _Traits> 797*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 7980b57cec5SDimitry Andric basic_string<_CharT, _Traits, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'), 7990b57cec5SDimitry Andric _CharT __one = _CharT('1')) const; 8000b57cec5SDimitry Andric template <class _CharT> 801*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 8020b57cec5SDimitry Andric basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'), 8030b57cec5SDimitry Andric _CharT __one = _CharT('1')) const; 804*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 8050b57cec5SDimitry Andric basic_string<char, char_traits<char>, allocator<char> > to_string(char __zero = '0', 8060b57cec5SDimitry Andric char __one = '1') const; 807*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 8080b57cec5SDimitry Andric size_t count() const _NOEXCEPT; 809*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR size_t size() const _NOEXCEPT {return _Size;} 810*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 8110b57cec5SDimitry Andric bool operator==(const bitset& __rhs) const _NOEXCEPT; 81206c3fb27SDimitry Andric#if _LIBCPP_STD_VER <= 17 813*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI 8140b57cec5SDimitry Andric bool operator!=(const bitset& __rhs) const _NOEXCEPT; 81506c3fb27SDimitry Andric#endif 816bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 8170b57cec5SDimitry Andric bool test(size_t __pos) const; 818*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 8190b57cec5SDimitry Andric bool all() const _NOEXCEPT; 820*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 8210b57cec5SDimitry Andric bool any() const _NOEXCEPT; 822*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool none() const _NOEXCEPT {return !any();} 823*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 8240b57cec5SDimitry Andric bitset operator<<(size_t __pos) const _NOEXCEPT; 825*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 8260b57cec5SDimitry Andric bitset operator>>(size_t __pos) const _NOEXCEPT; 8270b57cec5SDimitry Andric 8280b57cec5SDimitry Andricprivate: 82906c3fb27SDimitry Andric template <class _CharT, class _Traits> 83006c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void 83106c3fb27SDimitry Andric __init_from_string_view(basic_string_view<_CharT, _Traits> __str, _CharT __zero, _CharT __one) { 83206c3fb27SDimitry Andric 83306c3fb27SDimitry Andric for (size_t __i = 0; __i < __str.size(); ++__i) 83406c3fb27SDimitry Andric if (!_Traits::eq(__str[__i], __zero) && !_Traits::eq(__str[__i], __one)) 83506c3fb27SDimitry Andric std::__throw_invalid_argument("bitset string ctor has invalid argument"); 83606c3fb27SDimitry Andric 83706c3fb27SDimitry Andric size_t __mp = std::min(__str.size(), _Size); 83806c3fb27SDimitry Andric size_t __i = 0; 83906c3fb27SDimitry Andric for (; __i < __mp; ++__i) { 84006c3fb27SDimitry Andric _CharT __c = __str[__mp - 1 - __i]; 84106c3fb27SDimitry Andric (*this)[__i] = _Traits::eq(__c, __one); 84206c3fb27SDimitry Andric } 84306c3fb27SDimitry Andric std::fill(base::__make_iter(__i), base::__make_iter(_Size), false); 84406c3fb27SDimitry Andric } 8450b57cec5SDimitry Andric 846*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI 8470b57cec5SDimitry Andric size_t __hash_code() const _NOEXCEPT {return base::__hash_code();} 8480b57cec5SDimitry Andric 8490b57cec5SDimitry Andric friend struct hash<bitset>; 8500b57cec5SDimitry Andric}; 8510b57cec5SDimitry Andric 8520b57cec5SDimitry Andrictemplate <size_t _Size> 8530b57cec5SDimitry Andricinline 854bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 8550b57cec5SDimitry Andricbitset<_Size>& 8560b57cec5SDimitry Andricbitset<_Size>::operator&=(const bitset& __rhs) _NOEXCEPT 8570b57cec5SDimitry Andric{ 8580b57cec5SDimitry Andric base::operator&=(__rhs); 8590b57cec5SDimitry Andric return *this; 8600b57cec5SDimitry Andric} 8610b57cec5SDimitry Andric 8620b57cec5SDimitry Andrictemplate <size_t _Size> 8630b57cec5SDimitry Andricinline 864bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 8650b57cec5SDimitry Andricbitset<_Size>& 8660b57cec5SDimitry Andricbitset<_Size>::operator|=(const bitset& __rhs) _NOEXCEPT 8670b57cec5SDimitry Andric{ 8680b57cec5SDimitry Andric base::operator|=(__rhs); 8690b57cec5SDimitry Andric return *this; 8700b57cec5SDimitry Andric} 8710b57cec5SDimitry Andric 8720b57cec5SDimitry Andrictemplate <size_t _Size> 8730b57cec5SDimitry Andricinline 874bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 8750b57cec5SDimitry Andricbitset<_Size>& 8760b57cec5SDimitry Andricbitset<_Size>::operator^=(const bitset& __rhs) _NOEXCEPT 8770b57cec5SDimitry Andric{ 8780b57cec5SDimitry Andric base::operator^=(__rhs); 8790b57cec5SDimitry Andric return *this; 8800b57cec5SDimitry Andric} 8810b57cec5SDimitry Andric 8820b57cec5SDimitry Andrictemplate <size_t _Size> 883bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 8840b57cec5SDimitry Andricbitset<_Size>& 8850b57cec5SDimitry Andricbitset<_Size>::operator<<=(size_t __pos) _NOEXCEPT 8860b57cec5SDimitry Andric{ 887*5f757f3fSDimitry Andric __pos = std::min(__pos, _Size); 888*5f757f3fSDimitry Andric std::copy_backward(base::__make_iter(0), base::__make_iter(_Size - __pos), base::__make_iter(_Size)); 889*5f757f3fSDimitry Andric std::fill_n(base::__make_iter(0), __pos, false); 8900b57cec5SDimitry Andric return *this; 8910b57cec5SDimitry Andric} 8920b57cec5SDimitry Andric 8930b57cec5SDimitry Andrictemplate <size_t _Size> 894bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 8950b57cec5SDimitry Andricbitset<_Size>& 8960b57cec5SDimitry Andricbitset<_Size>::operator>>=(size_t __pos) _NOEXCEPT 8970b57cec5SDimitry Andric{ 898*5f757f3fSDimitry Andric __pos = std::min(__pos, _Size); 899*5f757f3fSDimitry Andric std::copy(base::__make_iter(__pos), base::__make_iter(_Size), base::__make_iter(0)); 900*5f757f3fSDimitry Andric std::fill_n(base::__make_iter(_Size - __pos), __pos, false); 9010b57cec5SDimitry Andric return *this; 9020b57cec5SDimitry Andric} 9030b57cec5SDimitry Andric 9040b57cec5SDimitry Andrictemplate <size_t _Size> 9050b57cec5SDimitry Andricinline 906bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 9070b57cec5SDimitry Andricbitset<_Size>& 9080b57cec5SDimitry Andricbitset<_Size>::set() _NOEXCEPT 9090b57cec5SDimitry Andric{ 910*5f757f3fSDimitry Andric std::fill_n(base::__make_iter(0), _Size, true); 9110b57cec5SDimitry Andric return *this; 9120b57cec5SDimitry Andric} 9130b57cec5SDimitry Andric 9140b57cec5SDimitry Andrictemplate <size_t _Size> 915bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 9160b57cec5SDimitry Andricbitset<_Size>& 9170b57cec5SDimitry Andricbitset<_Size>::set(size_t __pos, bool __val) 9180b57cec5SDimitry Andric{ 9190b57cec5SDimitry Andric if (__pos >= _Size) 9200b57cec5SDimitry Andric __throw_out_of_range("bitset set argument out of range"); 9210b57cec5SDimitry Andric 9220b57cec5SDimitry Andric (*this)[__pos] = __val; 9230b57cec5SDimitry Andric return *this; 9240b57cec5SDimitry Andric} 9250b57cec5SDimitry Andric 9260b57cec5SDimitry Andrictemplate <size_t _Size> 9270b57cec5SDimitry Andricinline 928bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 9290b57cec5SDimitry Andricbitset<_Size>& 9300b57cec5SDimitry Andricbitset<_Size>::reset() _NOEXCEPT 9310b57cec5SDimitry Andric{ 932*5f757f3fSDimitry Andric std::fill_n(base::__make_iter(0), _Size, false); 9330b57cec5SDimitry Andric return *this; 9340b57cec5SDimitry Andric} 9350b57cec5SDimitry Andric 9360b57cec5SDimitry Andrictemplate <size_t _Size> 937bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 9380b57cec5SDimitry Andricbitset<_Size>& 9390b57cec5SDimitry Andricbitset<_Size>::reset(size_t __pos) 9400b57cec5SDimitry Andric{ 9410b57cec5SDimitry Andric if (__pos >= _Size) 9420b57cec5SDimitry Andric __throw_out_of_range("bitset reset argument out of range"); 9430b57cec5SDimitry Andric 9440b57cec5SDimitry Andric (*this)[__pos] = false; 9450b57cec5SDimitry Andric return *this; 9460b57cec5SDimitry Andric} 9470b57cec5SDimitry Andric 9480b57cec5SDimitry Andrictemplate <size_t _Size> 9490b57cec5SDimitry Andricinline 950bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 9510b57cec5SDimitry Andricbitset<_Size> 9520b57cec5SDimitry Andricbitset<_Size>::operator~() const _NOEXCEPT 9530b57cec5SDimitry Andric{ 9540b57cec5SDimitry Andric bitset __x(*this); 9550b57cec5SDimitry Andric __x.flip(); 9560b57cec5SDimitry Andric return __x; 9570b57cec5SDimitry Andric} 9580b57cec5SDimitry Andric 9590b57cec5SDimitry Andrictemplate <size_t _Size> 9600b57cec5SDimitry Andricinline 961bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 9620b57cec5SDimitry Andricbitset<_Size>& 9630b57cec5SDimitry Andricbitset<_Size>::flip() _NOEXCEPT 9640b57cec5SDimitry Andric{ 9650b57cec5SDimitry Andric base::flip(); 9660b57cec5SDimitry Andric return *this; 9670b57cec5SDimitry Andric} 9680b57cec5SDimitry Andric 9690b57cec5SDimitry Andrictemplate <size_t _Size> 970bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 9710b57cec5SDimitry Andricbitset<_Size>& 9720b57cec5SDimitry Andricbitset<_Size>::flip(size_t __pos) 9730b57cec5SDimitry Andric{ 9740b57cec5SDimitry Andric if (__pos >= _Size) 9750b57cec5SDimitry Andric __throw_out_of_range("bitset flip argument out of range"); 9760b57cec5SDimitry Andric 97706c3fb27SDimitry Andric reference __r = base::__make_ref(__pos); 97806c3fb27SDimitry Andric __r = ~__r; 9790b57cec5SDimitry Andric return *this; 9800b57cec5SDimitry Andric} 9810b57cec5SDimitry Andric 9820b57cec5SDimitry Andrictemplate <size_t _Size> 9830b57cec5SDimitry Andricinline 984bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 9850b57cec5SDimitry Andricunsigned long 9860b57cec5SDimitry Andricbitset<_Size>::to_ulong() const 9870b57cec5SDimitry Andric{ 9880b57cec5SDimitry Andric return base::to_ulong(); 9890b57cec5SDimitry Andric} 9900b57cec5SDimitry Andric 9910b57cec5SDimitry Andrictemplate <size_t _Size> 9920b57cec5SDimitry Andricinline 993bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 9940b57cec5SDimitry Andricunsigned long long 9950b57cec5SDimitry Andricbitset<_Size>::to_ullong() const 9960b57cec5SDimitry Andric{ 9970b57cec5SDimitry Andric return base::to_ullong(); 9980b57cec5SDimitry Andric} 9990b57cec5SDimitry Andric 10000b57cec5SDimitry Andrictemplate <size_t _Size> 10010b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 1002bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 10030b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator> 10040b57cec5SDimitry Andricbitset<_Size>::to_string(_CharT __zero, _CharT __one) const 10050b57cec5SDimitry Andric{ 10060b57cec5SDimitry Andric basic_string<_CharT, _Traits, _Allocator> __r(_Size, __zero); 100781ad6265SDimitry Andric for (size_t __i = 0; __i != _Size; ++__i) 10080b57cec5SDimitry Andric { 10090b57cec5SDimitry Andric if ((*this)[__i]) 10100b57cec5SDimitry Andric __r[_Size - 1 - __i] = __one; 10110b57cec5SDimitry Andric } 10120b57cec5SDimitry Andric return __r; 10130b57cec5SDimitry Andric} 10140b57cec5SDimitry Andric 10150b57cec5SDimitry Andrictemplate <size_t _Size> 10160b57cec5SDimitry Andrictemplate <class _CharT, class _Traits> 10170b57cec5SDimitry Andricinline 1018bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 10190b57cec5SDimitry Andricbasic_string<_CharT, _Traits, allocator<_CharT> > 10200b57cec5SDimitry Andricbitset<_Size>::to_string(_CharT __zero, _CharT __one) const 10210b57cec5SDimitry Andric{ 10220b57cec5SDimitry Andric return to_string<_CharT, _Traits, allocator<_CharT> >(__zero, __one); 10230b57cec5SDimitry Andric} 10240b57cec5SDimitry Andric 10250b57cec5SDimitry Andrictemplate <size_t _Size> 10260b57cec5SDimitry Andrictemplate <class _CharT> 10270b57cec5SDimitry Andricinline 1028bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 10290b57cec5SDimitry Andricbasic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > 10300b57cec5SDimitry Andricbitset<_Size>::to_string(_CharT __zero, _CharT __one) const 10310b57cec5SDimitry Andric{ 10320b57cec5SDimitry Andric return to_string<_CharT, char_traits<_CharT>, allocator<_CharT> >(__zero, __one); 10330b57cec5SDimitry Andric} 10340b57cec5SDimitry Andric 10350b57cec5SDimitry Andrictemplate <size_t _Size> 10360b57cec5SDimitry Andricinline 1037bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 10380b57cec5SDimitry Andricbasic_string<char, char_traits<char>, allocator<char> > 10390b57cec5SDimitry Andricbitset<_Size>::to_string(char __zero, char __one) const 10400b57cec5SDimitry Andric{ 10410b57cec5SDimitry Andric return to_string<char, char_traits<char>, allocator<char> >(__zero, __one); 10420b57cec5SDimitry Andric} 10430b57cec5SDimitry Andric 10440b57cec5SDimitry Andrictemplate <size_t _Size> 10450b57cec5SDimitry Andricinline 1046bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 10470b57cec5SDimitry Andricsize_t 10480b57cec5SDimitry Andricbitset<_Size>::count() const _NOEXCEPT 10490b57cec5SDimitry Andric{ 1050*5f757f3fSDimitry Andric return static_cast<size_t>(std::count(base::__make_iter(0), base::__make_iter(_Size), true)); 10510b57cec5SDimitry Andric} 10520b57cec5SDimitry Andric 10530b57cec5SDimitry Andrictemplate <size_t _Size> 10540b57cec5SDimitry Andricinline 1055bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 10560b57cec5SDimitry Andricbool 10570b57cec5SDimitry Andricbitset<_Size>::operator==(const bitset& __rhs) const _NOEXCEPT 10580b57cec5SDimitry Andric{ 1059*5f757f3fSDimitry Andric return std::equal(base::__make_iter(0), base::__make_iter(_Size), __rhs.__make_iter(0)); 10600b57cec5SDimitry Andric} 10610b57cec5SDimitry Andric 106206c3fb27SDimitry Andric#if _LIBCPP_STD_VER <= 17 106306c3fb27SDimitry Andric 10640b57cec5SDimitry Andrictemplate <size_t _Size> 10650b57cec5SDimitry Andricinline 106606c3fb27SDimitry Andric_LIBCPP_HIDE_FROM_ABI 10670b57cec5SDimitry Andricbool 10680b57cec5SDimitry Andricbitset<_Size>::operator!=(const bitset& __rhs) const _NOEXCEPT 10690b57cec5SDimitry Andric{ 10700b57cec5SDimitry Andric return !(*this == __rhs); 10710b57cec5SDimitry Andric} 10720b57cec5SDimitry Andric 107306c3fb27SDimitry Andric#endif 107406c3fb27SDimitry Andric 10750b57cec5SDimitry Andrictemplate <size_t _Size> 1076bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 10770b57cec5SDimitry Andricbool 10780b57cec5SDimitry Andricbitset<_Size>::test(size_t __pos) const 10790b57cec5SDimitry Andric{ 10800b57cec5SDimitry Andric if (__pos >= _Size) 10810b57cec5SDimitry Andric __throw_out_of_range("bitset test argument out of range"); 10820b57cec5SDimitry Andric 10830b57cec5SDimitry Andric return (*this)[__pos]; 10840b57cec5SDimitry Andric} 10850b57cec5SDimitry Andric 10860b57cec5SDimitry Andrictemplate <size_t _Size> 10870b57cec5SDimitry Andricinline 1088bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 10890b57cec5SDimitry Andricbool 10900b57cec5SDimitry Andricbitset<_Size>::all() const _NOEXCEPT 10910b57cec5SDimitry Andric{ 10920b57cec5SDimitry Andric return base::all(); 10930b57cec5SDimitry Andric} 10940b57cec5SDimitry Andric 10950b57cec5SDimitry Andrictemplate <size_t _Size> 10960b57cec5SDimitry Andricinline 1097bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 10980b57cec5SDimitry Andricbool 10990b57cec5SDimitry Andricbitset<_Size>::any() const _NOEXCEPT 11000b57cec5SDimitry Andric{ 11010b57cec5SDimitry Andric return base::any(); 11020b57cec5SDimitry Andric} 11030b57cec5SDimitry Andric 11040b57cec5SDimitry Andrictemplate <size_t _Size> 11050b57cec5SDimitry Andricinline 1106bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 11070b57cec5SDimitry Andricbitset<_Size> 11080b57cec5SDimitry Andricbitset<_Size>::operator<<(size_t __pos) const _NOEXCEPT 11090b57cec5SDimitry Andric{ 11100b57cec5SDimitry Andric bitset __r = *this; 11110b57cec5SDimitry Andric __r <<= __pos; 11120b57cec5SDimitry Andric return __r; 11130b57cec5SDimitry Andric} 11140b57cec5SDimitry Andric 11150b57cec5SDimitry Andrictemplate <size_t _Size> 11160b57cec5SDimitry Andricinline 1117bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 11180b57cec5SDimitry Andricbitset<_Size> 11190b57cec5SDimitry Andricbitset<_Size>::operator>>(size_t __pos) const _NOEXCEPT 11200b57cec5SDimitry Andric{ 11210b57cec5SDimitry Andric bitset __r = *this; 11220b57cec5SDimitry Andric __r >>= __pos; 11230b57cec5SDimitry Andric return __r; 11240b57cec5SDimitry Andric} 11250b57cec5SDimitry Andric 11260b57cec5SDimitry Andrictemplate <size_t _Size> 1127*5f757f3fSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 11280b57cec5SDimitry Andricbitset<_Size> 11290b57cec5SDimitry Andricoperator&(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT 11300b57cec5SDimitry Andric{ 11310b57cec5SDimitry Andric bitset<_Size> __r = __x; 11320b57cec5SDimitry Andric __r &= __y; 11330b57cec5SDimitry Andric return __r; 11340b57cec5SDimitry Andric} 11350b57cec5SDimitry Andric 11360b57cec5SDimitry Andrictemplate <size_t _Size> 1137*5f757f3fSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 11380b57cec5SDimitry Andricbitset<_Size> 11390b57cec5SDimitry Andricoperator|(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT 11400b57cec5SDimitry Andric{ 11410b57cec5SDimitry Andric bitset<_Size> __r = __x; 11420b57cec5SDimitry Andric __r |= __y; 11430b57cec5SDimitry Andric return __r; 11440b57cec5SDimitry Andric} 11450b57cec5SDimitry Andric 11460b57cec5SDimitry Andrictemplate <size_t _Size> 1147*5f757f3fSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 11480b57cec5SDimitry Andricbitset<_Size> 11490b57cec5SDimitry Andricoperator^(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT 11500b57cec5SDimitry Andric{ 11510b57cec5SDimitry Andric bitset<_Size> __r = __x; 11520b57cec5SDimitry Andric __r ^= __y; 11530b57cec5SDimitry Andric return __r; 11540b57cec5SDimitry Andric} 11550b57cec5SDimitry Andric 11560b57cec5SDimitry Andrictemplate <size_t _Size> 11570b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS hash<bitset<_Size> > 115881ad6265SDimitry Andric : public __unary_function<bitset<_Size>, size_t> 11590b57cec5SDimitry Andric{ 1160*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI 11610b57cec5SDimitry Andric size_t operator()(const bitset<_Size>& __bs) const _NOEXCEPT 11620b57cec5SDimitry Andric {return __bs.__hash_code();} 11630b57cec5SDimitry Andric}; 11640b57cec5SDimitry Andric 11650b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, size_t _Size> 1166bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>& 11670b57cec5SDimitry Andricoperator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x); 11680b57cec5SDimitry Andric 11690b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, size_t _Size> 1170bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& 11710b57cec5SDimitry Andricoperator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x); 11720b57cec5SDimitry Andric 11730b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD 11740b57cec5SDimitry Andric 11750b57cec5SDimitry Andric_LIBCPP_POP_MACROS 11760b57cec5SDimitry Andric 1177bdd1243dSDimitry Andric#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 1178bdd1243dSDimitry Andric# include <concepts> 117906c3fb27SDimitry Andric# include <cstdlib> 118006c3fb27SDimitry Andric# include <type_traits> 1181bdd1243dSDimitry Andric#endif 1182bdd1243dSDimitry Andric 11830b57cec5SDimitry Andric#endif // _LIBCPP_BITSET 1184