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 135f757f3fSDimitry Andric// clang-format off 145f757f3fSDimitry 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> 455f757f3fSDimitry Andric constexpr explicit bitset(const charT* str, 460b57cec5SDimitry Andric typename basic_string<charT>::size_type n = basic_string<charT>::npos, 475f757f3fSDimitry Andric charT zero = charT('0'), charT one = charT('1')); // until C++26, constexpr since C++23 485f757f3fSDimitry Andric template <class charT> 495f757f3fSDimitry Andric constexpr explicit bitset(const charT* str, 505f757f3fSDimitry Andric typename basic_string_view<charT>::size_type n = basic_string_view<charT>::npos, 515f757f3fSDimitry Andric charT zero = charT('0'), charT one = charT('1')); // since C++26 525f757f3fSDimitry Andric template<class charT, class traits> 535f757f3fSDimitry Andric explicit bitset( 545f757f3fSDimitry Andric const basic_string_view<charT,traits>& str, 555f757f3fSDimitry Andric typename basic_string_view<charT,traits>::size_type pos = 0, 565f757f3fSDimitry Andric typename basic_string_view<charT,traits>::size_type n = basic_string_view<charT,traits>::npos, 575f757f3fSDimitry Andric charT zero = charT('0'), charT one = charT('1')); // since C++26 580b57cec5SDimitry Andric template<class charT, class traits, class Allocator> 595f757f3fSDimitry Andric constexpr explicit bitset( 605f757f3fSDimitry Andric const basic_string<charT,traits,Allocator>& str, 610b57cec5SDimitry Andric typename basic_string<charT,traits,Allocator>::size_type pos = 0, 625f757f3fSDimitry 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 1275f757f3fSDimitry Andric// clang-format on 1285f757f3fSDimitry Andric 1295f757f3fSDimitry Andric#include <__algorithm/count.h> 13081ad6265SDimitry Andric#include <__algorithm/fill.h> 1315f757f3fSDimitry Andric#include <__algorithm/find.h> 1320b57cec5SDimitry Andric#include <__bit_reference> 13304eeddc0SDimitry Andric#include <__config> 13481ad6265SDimitry Andric#include <__functional/hash.h> 13581ad6265SDimitry Andric#include <__functional/unary_function.h> 136bdd1243dSDimitry Andric#include <__type_traits/is_char_like_type.h> 137fe6060f1SDimitry Andric#include <climits> 138fe6060f1SDimitry Andric#include <cstddef> 139fe6060f1SDimitry Andric#include <stdexcept> 14006c3fb27SDimitry Andric#include <string_view> 14104eeddc0SDimitry Andric#include <version> 1420b57cec5SDimitry Andric 14381ad6265SDimitry Andric// standard-mandated includes 144bdd1243dSDimitry Andric 145bdd1243dSDimitry Andric// [bitset.syn] 14681ad6265SDimitry Andric#include <iosfwd> 14781ad6265SDimitry Andric#include <string> 14881ad6265SDimitry Andric 1490b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 1500b57cec5SDimitry Andric# pragma GCC system_header 1510b57cec5SDimitry Andric#endif 1520b57cec5SDimitry Andric 1530b57cec5SDimitry Andric_LIBCPP_PUSH_MACROS 1540b57cec5SDimitry Andric#include <__undef_macros> 1550b57cec5SDimitry Andric 1560b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD 1570b57cec5SDimitry Andric 1580b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 1590b57cec5SDimitry Andricclass __bitset; 1600b57cec5SDimitry Andric 1610b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 162cb14a3feSDimitry Andricstruct __has_storage_type<__bitset<_N_words, _Size> > { 1630b57cec5SDimitry Andric static const bool value = true; 1640b57cec5SDimitry Andric}; 1650b57cec5SDimitry Andric 1660b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 167cb14a3feSDimitry Andricclass __bitset { 1680b57cec5SDimitry Andricpublic: 1690b57cec5SDimitry Andric typedef ptrdiff_t difference_type; 1700b57cec5SDimitry Andric typedef size_t size_type; 1710b57cec5SDimitry Andric typedef size_type __storage_type; 172cb14a3feSDimitry Andric 1730b57cec5SDimitry Andricprotected: 1740b57cec5SDimitry Andric typedef __bitset __self; 1750b57cec5SDimitry Andric typedef __storage_type* __storage_pointer; 1760b57cec5SDimitry Andric typedef const __storage_type* __const_storage_pointer; 1770b57cec5SDimitry Andric static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT); 1780b57cec5SDimitry Andric 1790b57cec5SDimitry Andric friend class __bit_reference<__bitset>; 1800b57cec5SDimitry Andric friend class __bit_const_reference<__bitset>; 1810b57cec5SDimitry Andric friend class __bit_iterator<__bitset, false>; 1820b57cec5SDimitry Andric friend class __bit_iterator<__bitset, true>; 1830b57cec5SDimitry Andric friend struct __bit_array<__bitset>; 1840b57cec5SDimitry Andric 1850b57cec5SDimitry Andric __storage_type __first_[_N_words]; 1860b57cec5SDimitry Andric 1870b57cec5SDimitry Andric typedef __bit_reference<__bitset> reference; 1880b57cec5SDimitry Andric typedef __bit_const_reference<__bitset> const_reference; 1890b57cec5SDimitry Andric typedef __bit_iterator<__bitset, false> iterator; 1900b57cec5SDimitry Andric typedef __bit_iterator<__bitset, true> const_iterator; 1910b57cec5SDimitry Andric 192cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT; 193cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT; 1940b57cec5SDimitry Andric 195cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 reference __make_ref(size_t __pos) _NOEXCEPT { 196cb14a3feSDimitry Andric return reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word); 197cb14a3feSDimitry Andric } 198cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT { 199cb14a3feSDimitry Andric return const_reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word); 200cb14a3feSDimitry Andric } 201cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 iterator __make_iter(size_t __pos) _NOEXCEPT { 202cb14a3feSDimitry Andric return iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word); 203cb14a3feSDimitry Andric } 204cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 const_iterator __make_iter(size_t __pos) const _NOEXCEPT { 205cb14a3feSDimitry Andric return const_iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word); 206cb14a3feSDimitry Andric } 2070b57cec5SDimitry Andric 208cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator&=(const __bitset& __v) _NOEXCEPT; 209cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator|=(const __bitset& __v) _NOEXCEPT; 210cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator^=(const __bitset& __v) _NOEXCEPT; 2110b57cec5SDimitry Andric 212bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void flip() _NOEXCEPT; 213cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong() const { 214cb14a3feSDimitry Andric return to_ulong(integral_constant < bool, _Size< sizeof(unsigned long) * CHAR_BIT>()); 215cb14a3feSDimitry Andric } 216cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong() const { 217cb14a3feSDimitry Andric return to_ullong(integral_constant < bool, _Size< sizeof(unsigned long long) * CHAR_BIT>()); 218cb14a3feSDimitry Andric } 2190b57cec5SDimitry Andric 220bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT; 221bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT; 222cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI size_t __hash_code() const _NOEXCEPT; 223cb14a3feSDimitry Andric 2240b57cec5SDimitry Andricprivate: 2250b57cec5SDimitry Andric#ifdef _LIBCPP_CXX03_LANG 2260b57cec5SDimitry Andric void __init(unsigned long long __v, false_type) _NOEXCEPT; 227cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI void __init(unsigned long long __v, true_type) _NOEXCEPT; 2280b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 229cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong(false_type) const; 230cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong(true_type) const; 231cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong(false_type) const; 232cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong(true_type) const; 233cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong(true_type, false_type) const; 234cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong(true_type, true_type) const; 2350b57cec5SDimitry Andric}; 2360b57cec5SDimitry Andric 2370b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 238cb14a3feSDimitry Andricinline _LIBCPP_CONSTEXPR __bitset<_N_words, _Size>::__bitset() _NOEXCEPT 2390b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 2400b57cec5SDimitry Andric : __first_{0} 2410b57cec5SDimitry Andric#endif 2420b57cec5SDimitry Andric{ 2430b57cec5SDimitry Andric#ifdef _LIBCPP_CXX03_LANG 2445f757f3fSDimitry Andric std::fill_n(__first_, _N_words, __storage_type(0)); 2450b57cec5SDimitry Andric#endif 2460b57cec5SDimitry Andric} 2470b57cec5SDimitry Andric 2480b57cec5SDimitry Andric#ifdef _LIBCPP_CXX03_LANG 2490b57cec5SDimitry Andric 2500b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 251cb14a3feSDimitry Andricvoid __bitset<_N_words, _Size>::__init(unsigned long long __v, false_type) _NOEXCEPT { 2520b57cec5SDimitry Andric __storage_type __t[sizeof(unsigned long long) / sizeof(__storage_type)]; 2530b57cec5SDimitry Andric size_t __sz = _Size; 2540b57cec5SDimitry Andric for (size_t __i = 0; __i < sizeof(__t) / sizeof(__t[0]); ++__i, __v >>= __bits_per_word, __sz -= __bits_per_word) 2550b57cec5SDimitry Andric if (__sz < __bits_per_word) 2560b57cec5SDimitry Andric __t[__i] = static_cast<__storage_type>(__v) & (1ULL << __sz) - 1; 2570b57cec5SDimitry Andric else 2580b57cec5SDimitry Andric __t[__i] = static_cast<__storage_type>(__v); 2590b57cec5SDimitry Andric 2605f757f3fSDimitry Andric std::copy(__t, __t + sizeof(__t) / sizeof(__t[0]), __first_); 261cb14a3feSDimitry Andric std::fill( 262cb14a3feSDimitry Andric __first_ + sizeof(__t) / sizeof(__t[0]), __first_ + sizeof(__first_) / sizeof(__first_[0]), __storage_type(0)); 2630b57cec5SDimitry Andric} 2640b57cec5SDimitry Andric 2650b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 266cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI void __bitset<_N_words, _Size>::__init(unsigned long long __v, true_type) _NOEXCEPT { 2670b57cec5SDimitry Andric __first_[0] = __v; 2680b57cec5SDimitry Andric if (_Size < __bits_per_word) 2690b57cec5SDimitry Andric __first_[0] &= (1ULL << _Size) - 1; 2700b57cec5SDimitry Andric 2715f757f3fSDimitry Andric std::fill(__first_ + 1, __first_ + sizeof(__first_) / sizeof(__first_[0]), __storage_type(0)); 2720b57cec5SDimitry Andric} 2730b57cec5SDimitry Andric 2740b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 2750b57cec5SDimitry Andric 2760b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 277cb14a3feSDimitry Andricinline _LIBCPP_CONSTEXPR __bitset<_N_words, _Size>::__bitset(unsigned long long __v) _NOEXCEPT 2780b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 2790b57cec5SDimitry Andric# if __SIZEOF_SIZE_T__ == 8 2800b57cec5SDimitry Andric : __first_{__v} 2810b57cec5SDimitry Andric# elif __SIZEOF_SIZE_T__ == 4 2820b57cec5SDimitry Andric : __first_{static_cast<__storage_type>(__v), 283cb14a3feSDimitry Andric _Size >= 2 * __bits_per_word 284cb14a3feSDimitry Andric ? static_cast<__storage_type>(__v >> __bits_per_word) 285cb14a3feSDimitry Andric : static_cast<__storage_type>((__v >> __bits_per_word) & 286cb14a3feSDimitry Andric (__storage_type(1) << (_Size - __bits_per_word)) - 1)} 2870b57cec5SDimitry Andric# else 2880b57cec5SDimitry Andric# error This constructor has not been ported to this platform 2890b57cec5SDimitry Andric# endif 2900b57cec5SDimitry Andric#endif 2910b57cec5SDimitry Andric{ 2920b57cec5SDimitry Andric#ifdef _LIBCPP_CXX03_LANG 2930b57cec5SDimitry Andric __init(__v, integral_constant<bool, sizeof(unsigned long long) == sizeof(__storage_type)>()); 2940b57cec5SDimitry Andric#endif 2950b57cec5SDimitry Andric} 2960b57cec5SDimitry Andric 2970b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 298cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void 299cb14a3feSDimitry Andric__bitset<_N_words, _Size>::operator&=(const __bitset& __v) _NOEXCEPT { 3000b57cec5SDimitry Andric for (size_type __i = 0; __i < _N_words; ++__i) 3010b57cec5SDimitry Andric __first_[__i] &= __v.__first_[__i]; 3020b57cec5SDimitry Andric} 3030b57cec5SDimitry Andric 3040b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 305cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void 306cb14a3feSDimitry Andric__bitset<_N_words, _Size>::operator|=(const __bitset& __v) _NOEXCEPT { 3070b57cec5SDimitry Andric for (size_type __i = 0; __i < _N_words; ++__i) 3080b57cec5SDimitry Andric __first_[__i] |= __v.__first_[__i]; 3090b57cec5SDimitry Andric} 3100b57cec5SDimitry Andric 3110b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 312cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void 313cb14a3feSDimitry Andric__bitset<_N_words, _Size>::operator^=(const __bitset& __v) _NOEXCEPT { 3140b57cec5SDimitry Andric for (size_type __i = 0; __i < _N_words; ++__i) 3150b57cec5SDimitry Andric __first_[__i] ^= __v.__first_[__i]; 3160b57cec5SDimitry Andric} 3170b57cec5SDimitry Andric 3180b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 319cb14a3feSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void __bitset<_N_words, _Size>::flip() _NOEXCEPT { 3200b57cec5SDimitry Andric // do middle whole words 3210b57cec5SDimitry Andric size_type __n = _Size; 3220b57cec5SDimitry Andric __storage_pointer __p = __first_; 3230b57cec5SDimitry Andric for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) 3240b57cec5SDimitry Andric *__p = ~*__p; 3250b57cec5SDimitry Andric // do last partial word 326cb14a3feSDimitry Andric if (__n > 0) { 3270b57cec5SDimitry Andric __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); 3280b57cec5SDimitry Andric __storage_type __b = *__p & __m; 3290b57cec5SDimitry Andric *__p &= ~__m; 3300b57cec5SDimitry Andric *__p |= ~__b & __m; 3310b57cec5SDimitry Andric } 3320b57cec5SDimitry Andric} 3330b57cec5SDimitry Andric 3340b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 335bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long 336cb14a3feSDimitry Andric__bitset<_N_words, _Size>::to_ulong(false_type) const { 3370b57cec5SDimitry Andric const_iterator __e = __make_iter(_Size); 3385f757f3fSDimitry Andric const_iterator __i = std::find(__make_iter(sizeof(unsigned long) * CHAR_BIT), __e, true); 3390b57cec5SDimitry Andric if (__i != __e) 3400b57cec5SDimitry Andric __throw_overflow_error("bitset to_ulong overflow error"); 3410b57cec5SDimitry Andric 3420b57cec5SDimitry Andric return __first_[0]; 3430b57cec5SDimitry Andric} 3440b57cec5SDimitry Andric 3450b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 346cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long 347cb14a3feSDimitry Andric__bitset<_N_words, _Size>::to_ulong(true_type) const { 3480b57cec5SDimitry Andric return __first_[0]; 3490b57cec5SDimitry Andric} 3500b57cec5SDimitry Andric 3510b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 352bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long 353cb14a3feSDimitry Andric__bitset<_N_words, _Size>::to_ullong(false_type) const { 3540b57cec5SDimitry Andric const_iterator __e = __make_iter(_Size); 3555f757f3fSDimitry Andric const_iterator __i = std::find(__make_iter(sizeof(unsigned long long) * CHAR_BIT), __e, true); 3560b57cec5SDimitry Andric if (__i != __e) 3570b57cec5SDimitry Andric __throw_overflow_error("bitset to_ullong overflow error"); 3580b57cec5SDimitry Andric 3590b57cec5SDimitry Andric return to_ullong(true_type()); 3600b57cec5SDimitry Andric} 3610b57cec5SDimitry Andric 3620b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 363cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long 364cb14a3feSDimitry Andric__bitset<_N_words, _Size>::to_ullong(true_type) const { 3650b57cec5SDimitry Andric return to_ullong(true_type(), integral_constant<bool, sizeof(__storage_type) < sizeof(unsigned long long)>()); 3660b57cec5SDimitry Andric} 3670b57cec5SDimitry Andric 3680b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 369cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long 370cb14a3feSDimitry Andric__bitset<_N_words, _Size>::to_ullong(true_type, false_type) const { 3710b57cec5SDimitry Andric return __first_[0]; 3720b57cec5SDimitry Andric} 3730b57cec5SDimitry Andric 3740b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 375bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long 376cb14a3feSDimitry Andric__bitset<_N_words, _Size>::to_ullong(true_type, true_type) const { 3770b57cec5SDimitry Andric unsigned long long __r = __first_[0]; 3789bc30046SJohn Baldwin _LIBCPP_DIAGNOSTIC_PUSH 3799bc30046SJohn Baldwin _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wshift-count-overflow") 380e8d8bef9SDimitry Andric for (size_t __i = 1; __i < sizeof(unsigned long long) / sizeof(__storage_type); ++__i) 3810b57cec5SDimitry Andric __r |= static_cast<unsigned long long>(__first_[__i]) << (sizeof(__storage_type) * CHAR_BIT); 3829bc30046SJohn Baldwin _LIBCPP_DIAGNOSTIC_POP 3830b57cec5SDimitry Andric return __r; 3840b57cec5SDimitry Andric} 3850b57cec5SDimitry Andric 3860b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 387cb14a3feSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool __bitset<_N_words, _Size>::all() const _NOEXCEPT { 3880b57cec5SDimitry Andric // do middle whole words 3890b57cec5SDimitry Andric size_type __n = _Size; 3900b57cec5SDimitry Andric __const_storage_pointer __p = __first_; 3910b57cec5SDimitry Andric for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) 3920b57cec5SDimitry Andric if (~*__p) 3930b57cec5SDimitry Andric return false; 3940b57cec5SDimitry Andric // do last partial word 395cb14a3feSDimitry Andric if (__n > 0) { 3960b57cec5SDimitry Andric __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); 3970b57cec5SDimitry Andric if (~*__p & __m) 3980b57cec5SDimitry Andric return false; 3990b57cec5SDimitry Andric } 4000b57cec5SDimitry Andric return true; 4010b57cec5SDimitry Andric} 4020b57cec5SDimitry Andric 4030b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 404cb14a3feSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool __bitset<_N_words, _Size>::any() const _NOEXCEPT { 4050b57cec5SDimitry Andric // do middle whole words 4060b57cec5SDimitry Andric size_type __n = _Size; 4070b57cec5SDimitry Andric __const_storage_pointer __p = __first_; 4080b57cec5SDimitry Andric for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) 4090b57cec5SDimitry Andric if (*__p) 4100b57cec5SDimitry Andric return true; 4110b57cec5SDimitry Andric // do last partial word 412cb14a3feSDimitry Andric if (__n > 0) { 4130b57cec5SDimitry Andric __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); 4140b57cec5SDimitry Andric if (*__p & __m) 4150b57cec5SDimitry Andric return true; 4160b57cec5SDimitry Andric } 4170b57cec5SDimitry Andric return false; 4180b57cec5SDimitry Andric} 4190b57cec5SDimitry Andric 4200b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size> 421cb14a3feSDimitry Andricinline size_t __bitset<_N_words, _Size>::__hash_code() const _NOEXCEPT { 4220b57cec5SDimitry Andric size_t __h = 0; 4230b57cec5SDimitry Andric for (size_type __i = 0; __i < _N_words; ++__i) 4240b57cec5SDimitry Andric __h ^= __first_[__i]; 4250b57cec5SDimitry Andric return __h; 4260b57cec5SDimitry Andric} 4270b57cec5SDimitry Andric 4280b57cec5SDimitry Andrictemplate <size_t _Size> 429cb14a3feSDimitry Andricclass __bitset<1, _Size> { 4300b57cec5SDimitry Andricpublic: 4310b57cec5SDimitry Andric typedef ptrdiff_t difference_type; 4320b57cec5SDimitry Andric typedef size_t size_type; 4330b57cec5SDimitry Andric typedef size_type __storage_type; 434cb14a3feSDimitry Andric 4350b57cec5SDimitry Andricprotected: 4360b57cec5SDimitry Andric typedef __bitset __self; 4370b57cec5SDimitry Andric typedef __storage_type* __storage_pointer; 4380b57cec5SDimitry Andric typedef const __storage_type* __const_storage_pointer; 4390b57cec5SDimitry Andric static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT); 4400b57cec5SDimitry Andric 4410b57cec5SDimitry Andric friend class __bit_reference<__bitset>; 4420b57cec5SDimitry Andric friend class __bit_const_reference<__bitset>; 4430b57cec5SDimitry Andric friend class __bit_iterator<__bitset, false>; 4440b57cec5SDimitry Andric friend class __bit_iterator<__bitset, true>; 4450b57cec5SDimitry Andric friend struct __bit_array<__bitset>; 4460b57cec5SDimitry Andric 4470b57cec5SDimitry Andric __storage_type __first_; 4480b57cec5SDimitry Andric 4490b57cec5SDimitry Andric typedef __bit_reference<__bitset> reference; 4500b57cec5SDimitry Andric typedef __bit_const_reference<__bitset> const_reference; 4510b57cec5SDimitry Andric typedef __bit_iterator<__bitset, false> iterator; 4520b57cec5SDimitry Andric typedef __bit_iterator<__bitset, true> const_iterator; 4530b57cec5SDimitry Andric 454cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT; 455cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT; 4560b57cec5SDimitry Andric 457cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 reference __make_ref(size_t __pos) _NOEXCEPT { 458cb14a3feSDimitry Andric return reference(&__first_, __storage_type(1) << __pos); 459cb14a3feSDimitry Andric } 460cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT { 461cb14a3feSDimitry Andric return const_reference(&__first_, __storage_type(1) << __pos); 462cb14a3feSDimitry Andric } 463cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 iterator __make_iter(size_t __pos) _NOEXCEPT { 464cb14a3feSDimitry Andric return iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word); 465cb14a3feSDimitry Andric } 466cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 const_iterator __make_iter(size_t __pos) const _NOEXCEPT { 467cb14a3feSDimitry Andric return const_iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word); 468cb14a3feSDimitry Andric } 4690b57cec5SDimitry Andric 470cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator&=(const __bitset& __v) _NOEXCEPT; 471cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator|=(const __bitset& __v) _NOEXCEPT; 472cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator^=(const __bitset& __v) _NOEXCEPT; 4730b57cec5SDimitry Andric 474cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void flip() _NOEXCEPT; 4750b57cec5SDimitry Andric 476cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong() const; 477cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong() const; 4780b57cec5SDimitry Andric 479cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT; 480cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT; 4810b57cec5SDimitry Andric 482cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI size_t __hash_code() const _NOEXCEPT; 4830b57cec5SDimitry Andric}; 4840b57cec5SDimitry Andric 4850b57cec5SDimitry Andrictemplate <size_t _Size> 486cb14a3feSDimitry Andricinline _LIBCPP_CONSTEXPR __bitset<1, _Size>::__bitset() _NOEXCEPT : __first_(0) {} 4870b57cec5SDimitry Andric 4880b57cec5SDimitry Andrictemplate <size_t _Size> 489cb14a3feSDimitry Andricinline _LIBCPP_CONSTEXPR __bitset<1, _Size>::__bitset(unsigned long long __v) _NOEXCEPT 490cb14a3feSDimitry Andric : __first_(_Size == __bits_per_word ? static_cast<__storage_type>(__v) 491cb14a3feSDimitry Andric : static_cast<__storage_type>(__v) & ((__storage_type(1) << _Size) - 1)) {} 4920b57cec5SDimitry Andric 4930b57cec5SDimitry Andrictemplate <size_t _Size> 494cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void 495cb14a3feSDimitry Andric__bitset<1, _Size>::operator&=(const __bitset& __v) _NOEXCEPT { 4960b57cec5SDimitry Andric __first_ &= __v.__first_; 4970b57cec5SDimitry Andric} 4980b57cec5SDimitry Andric 4990b57cec5SDimitry Andrictemplate <size_t _Size> 500cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void 501cb14a3feSDimitry Andric__bitset<1, _Size>::operator|=(const __bitset& __v) _NOEXCEPT { 5020b57cec5SDimitry Andric __first_ |= __v.__first_; 5030b57cec5SDimitry Andric} 5040b57cec5SDimitry Andric 5050b57cec5SDimitry Andrictemplate <size_t _Size> 506cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void 507cb14a3feSDimitry Andric__bitset<1, _Size>::operator^=(const __bitset& __v) _NOEXCEPT { 5080b57cec5SDimitry Andric __first_ ^= __v.__first_; 5090b57cec5SDimitry Andric} 5100b57cec5SDimitry Andric 5110b57cec5SDimitry Andrictemplate <size_t _Size> 512cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void __bitset<1, _Size>::flip() _NOEXCEPT { 5130b57cec5SDimitry Andric __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size); 5140b57cec5SDimitry Andric __first_ = ~__first_; 5150b57cec5SDimitry Andric __first_ &= __m; 5160b57cec5SDimitry Andric} 5170b57cec5SDimitry Andric 5180b57cec5SDimitry Andrictemplate <size_t _Size> 519cb14a3feSDimitry Andricinline _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long __bitset<1, _Size>::to_ulong() const { 5200b57cec5SDimitry Andric return __first_; 5210b57cec5SDimitry Andric} 5220b57cec5SDimitry Andric 5230b57cec5SDimitry Andrictemplate <size_t _Size> 524cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long __bitset<1, _Size>::to_ullong() const { 5250b57cec5SDimitry Andric return __first_; 5260b57cec5SDimitry Andric} 5270b57cec5SDimitry Andric 5280b57cec5SDimitry Andrictemplate <size_t _Size> 529cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool __bitset<1, _Size>::all() const _NOEXCEPT { 5300b57cec5SDimitry Andric __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size); 5310b57cec5SDimitry Andric return !(~__first_ & __m); 5320b57cec5SDimitry Andric} 5330b57cec5SDimitry Andric 5340b57cec5SDimitry Andrictemplate <size_t _Size> 535cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool __bitset<1, _Size>::any() const _NOEXCEPT { 5360b57cec5SDimitry Andric __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size); 5370b57cec5SDimitry Andric return __first_ & __m; 5380b57cec5SDimitry Andric} 5390b57cec5SDimitry Andric 5400b57cec5SDimitry Andrictemplate <size_t _Size> 541cb14a3feSDimitry Andricinline size_t __bitset<1, _Size>::__hash_code() const _NOEXCEPT { 5420b57cec5SDimitry Andric return __first_; 5430b57cec5SDimitry Andric} 5440b57cec5SDimitry Andric 5450b57cec5SDimitry Andrictemplate <> 546cb14a3feSDimitry Andricclass __bitset<0, 0> { 5470b57cec5SDimitry Andricpublic: 5480b57cec5SDimitry Andric typedef ptrdiff_t difference_type; 5490b57cec5SDimitry Andric typedef size_t size_type; 5500b57cec5SDimitry Andric typedef size_type __storage_type; 551cb14a3feSDimitry Andric 5520b57cec5SDimitry Andricprotected: 5530b57cec5SDimitry Andric typedef __bitset __self; 5540b57cec5SDimitry Andric typedef __storage_type* __storage_pointer; 5550b57cec5SDimitry Andric typedef const __storage_type* __const_storage_pointer; 5560b57cec5SDimitry Andric static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT); 5570b57cec5SDimitry Andric 5580b57cec5SDimitry Andric friend class __bit_reference<__bitset>; 5590b57cec5SDimitry Andric friend class __bit_const_reference<__bitset>; 5600b57cec5SDimitry Andric friend class __bit_iterator<__bitset, false>; 5610b57cec5SDimitry Andric friend class __bit_iterator<__bitset, true>; 5620b57cec5SDimitry Andric friend struct __bit_array<__bitset>; 5630b57cec5SDimitry Andric 5640b57cec5SDimitry Andric typedef __bit_reference<__bitset> reference; 5650b57cec5SDimitry Andric typedef __bit_const_reference<__bitset> const_reference; 5660b57cec5SDimitry Andric typedef __bit_iterator<__bitset, false> iterator; 5670b57cec5SDimitry Andric typedef __bit_iterator<__bitset, true> const_iterator; 5680b57cec5SDimitry Andric 569cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT; 570cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long) _NOEXCEPT; 5710b57cec5SDimitry Andric 572cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 reference __make_ref(size_t) _NOEXCEPT { 573cb14a3feSDimitry Andric return reference(nullptr, 1); 574cb14a3feSDimitry Andric } 575cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const_reference __make_ref(size_t) const _NOEXCEPT { 576cb14a3feSDimitry Andric return const_reference(nullptr, 1); 577cb14a3feSDimitry Andric } 578cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 iterator __make_iter(size_t) _NOEXCEPT { 579cb14a3feSDimitry Andric return iterator(nullptr, 0); 580cb14a3feSDimitry Andric } 581cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 const_iterator __make_iter(size_t) const _NOEXCEPT { 582cb14a3feSDimitry Andric return const_iterator(nullptr, 0); 583cb14a3feSDimitry Andric } 5840b57cec5SDimitry Andric 5855f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator&=(const __bitset&) _NOEXCEPT {} 5865f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator|=(const __bitset&) _NOEXCEPT {} 5875f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator^=(const __bitset&) _NOEXCEPT {} 5880b57cec5SDimitry Andric 5895f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void flip() _NOEXCEPT {} 5900b57cec5SDimitry Andric 5915f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong() const { return 0; } 5925f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong() const { return 0; } 5930b57cec5SDimitry Andric 5945f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT { return true; } 5955f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT { return false; } 5960b57cec5SDimitry Andric 5975f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI size_t __hash_code() const _NOEXCEPT { return 0; } 5980b57cec5SDimitry Andric}; 5990b57cec5SDimitry Andric 600cb14a3feSDimitry Andricinline _LIBCPP_CONSTEXPR __bitset<0, 0>::__bitset() _NOEXCEPT {} 6010b57cec5SDimitry Andric 602cb14a3feSDimitry Andricinline _LIBCPP_CONSTEXPR __bitset<0, 0>::__bitset(unsigned long long) _NOEXCEPT {} 6030b57cec5SDimitry Andric 604cb14a3feSDimitry Andrictemplate <size_t _Size> 605cb14a3feSDimitry Andricclass _LIBCPP_TEMPLATE_VIS bitset; 606cb14a3feSDimitry Andrictemplate <size_t _Size> 607cb14a3feSDimitry Andricstruct hash<bitset<_Size> >; 6080b57cec5SDimitry Andric 6090b57cec5SDimitry Andrictemplate <size_t _Size> 6100b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS bitset 611cb14a3feSDimitry Andric : private __bitset<_Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1, _Size> { 6120b57cec5SDimitry Andricpublic: 6130b57cec5SDimitry Andric static const unsigned __n_words = _Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1; 6140b57cec5SDimitry Andric typedef __bitset<__n_words, _Size> base; 6150b57cec5SDimitry Andric 6160b57cec5SDimitry Andricpublic: 6170b57cec5SDimitry Andric typedef typename base::reference reference; 6180b57cec5SDimitry Andric typedef typename base::const_reference const_reference; 6190b57cec5SDimitry Andric 6200b57cec5SDimitry Andric // 23.3.5.1 constructors: 6215f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bitset() _NOEXCEPT {} 622cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bitset(unsigned long long __v) _NOEXCEPT : base(__v) {} 623*0fca6ea1SDimitry Andric template <class _CharT, __enable_if_t<_IsCharLikeType<_CharT>::value, int> = 0> 62406c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 explicit bitset( 62506c3fb27SDimitry Andric const _CharT* __str, 6265f757f3fSDimitry Andric#if _LIBCPP_STD_VER >= 26 6275f757f3fSDimitry Andric typename basic_string_view<_CharT>::size_type __n = basic_string_view<_CharT>::npos, 6285f757f3fSDimitry Andric#else 6290b57cec5SDimitry Andric typename basic_string<_CharT>::size_type __n = basic_string<_CharT>::npos, 6305f757f3fSDimitry Andric#endif 63106c3fb27SDimitry Andric _CharT __zero = _CharT('0'), 63206c3fb27SDimitry Andric _CharT __one = _CharT('1')) { 63306c3fb27SDimitry Andric 63406c3fb27SDimitry Andric size_t __rlen = std::min(__n, char_traits<_CharT>::length(__str)); 63506c3fb27SDimitry Andric __init_from_string_view(basic_string_view<_CharT>(__str, __rlen), __zero, __one); 63606c3fb27SDimitry Andric } 6375f757f3fSDimitry Andric#if _LIBCPP_STD_VER >= 26 6385f757f3fSDimitry Andric template <class _CharT, class _Traits> 6395f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr explicit bitset( 6405f757f3fSDimitry Andric basic_string_view<_CharT, _Traits> __str, 6415f757f3fSDimitry Andric typename basic_string_view<_CharT, _Traits>::size_type __pos = 0, 6425f757f3fSDimitry Andric typename basic_string_view<_CharT, _Traits>::size_type __n = basic_string_view<_CharT, _Traits>::npos, 6435f757f3fSDimitry Andric _CharT __zero = _CharT('0'), 6445f757f3fSDimitry Andric _CharT __one = _CharT('1')) { 6455f757f3fSDimitry Andric if (__pos > __str.size()) 6465f757f3fSDimitry Andric __throw_out_of_range("bitset string pos out of range"); 6475f757f3fSDimitry Andric 6485f757f3fSDimitry Andric size_t __rlen = std::min(__n, __str.size() - __pos); 6495f757f3fSDimitry Andric __init_from_string_view(basic_string_view<_CharT, _Traits>(__str.data() + __pos, __rlen), __zero, __one); 6505f757f3fSDimitry Andric } 6515f757f3fSDimitry Andric#endif 6520b57cec5SDimitry Andric template <class _CharT, class _Traits, class _Allocator> 65306c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 explicit bitset( 65406c3fb27SDimitry Andric const basic_string<_CharT, _Traits, _Allocator>& __str, 6550b57cec5SDimitry Andric typename basic_string<_CharT, _Traits, _Allocator>::size_type __pos = 0, 6560b57cec5SDimitry Andric typename basic_string<_CharT, _Traits, _Allocator>::size_type __n = 65706c3fb27SDimitry Andric basic_string<_CharT, _Traits, _Allocator>::npos, 65806c3fb27SDimitry Andric _CharT __zero = _CharT('0'), 65906c3fb27SDimitry Andric _CharT __one = _CharT('1')) { 66006c3fb27SDimitry Andric if (__pos > __str.size()) 66106c3fb27SDimitry Andric std::__throw_out_of_range("bitset string pos out of range"); 66206c3fb27SDimitry Andric 66306c3fb27SDimitry Andric size_t __rlen = std::min(__n, __str.size() - __pos); 66406c3fb27SDimitry Andric __init_from_string_view(basic_string_view<_CharT, _Traits>(__str.data() + __pos, __rlen), __zero, __one); 66506c3fb27SDimitry Andric } 6660b57cec5SDimitry Andric 6670b57cec5SDimitry Andric // 23.3.5.2 bitset operations: 668cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& operator&=(const bitset& __rhs) _NOEXCEPT; 669cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& operator|=(const bitset& __rhs) _NOEXCEPT; 670cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& operator^=(const bitset& __rhs) _NOEXCEPT; 671cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& operator<<=(size_t __pos) _NOEXCEPT; 672cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& operator>>=(size_t __pos) _NOEXCEPT; 673cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& set() _NOEXCEPT; 674cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& set(size_t __pos, bool __val = true); 675cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& reset() _NOEXCEPT; 676cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& reset(size_t __pos); 677cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset operator~() const _NOEXCEPT; 678cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& flip() _NOEXCEPT; 679cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& flip(size_t __pos); 6800b57cec5SDimitry Andric 6810b57cec5SDimitry Andric // element access: 68281ad6265SDimitry Andric#ifdef _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL 68381ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool operator[](size_t __p) const { return base::__make_ref(__p); } 68481ad6265SDimitry Andric#else 68581ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const_reference operator[](size_t __p) const { return base::__make_ref(__p); } 68681ad6265SDimitry Andric#endif 687bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 reference operator[](size_t __p) { return base::__make_ref(__p); } 688cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong() const; 689cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong() const; 6900b57cec5SDimitry Andric template <class _CharT, class _Traits, class _Allocator> 691cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, _Traits, _Allocator> 692cb14a3feSDimitry Andric to_string(_CharT __zero = _CharT('0'), _CharT __one = _CharT('1')) const; 6930b57cec5SDimitry Andric template <class _CharT, class _Traits> 694cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, _Traits, allocator<_CharT> > 695cb14a3feSDimitry Andric to_string(_CharT __zero = _CharT('0'), _CharT __one = _CharT('1')) const; 6960b57cec5SDimitry Andric template <class _CharT> 697cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > 698cb14a3feSDimitry Andric to_string(_CharT __zero = _CharT('0'), _CharT __one = _CharT('1')) const; 699cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<char, char_traits<char>, allocator<char> > 700cb14a3feSDimitry Andric to_string(char __zero = '0', char __one = '1') const; 701cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 size_t count() const _NOEXCEPT; 7025f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR size_t size() const _NOEXCEPT { return _Size; } 703cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool operator==(const bitset& __rhs) const _NOEXCEPT; 70406c3fb27SDimitry Andric#if _LIBCPP_STD_VER <= 17 705cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI bool operator!=(const bitset& __rhs) const _NOEXCEPT; 70606c3fb27SDimitry Andric#endif 707cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool test(size_t __pos) const; 708cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT; 709cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT; 7105f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool none() const _NOEXCEPT { return !any(); } 711cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset operator<<(size_t __pos) const _NOEXCEPT; 712cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset operator>>(size_t __pos) const _NOEXCEPT; 7130b57cec5SDimitry Andric 7140b57cec5SDimitry Andricprivate: 71506c3fb27SDimitry Andric template <class _CharT, class _Traits> 71606c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void 71706c3fb27SDimitry Andric __init_from_string_view(basic_string_view<_CharT, _Traits> __str, _CharT __zero, _CharT __one) { 71806c3fb27SDimitry Andric for (size_t __i = 0; __i < __str.size(); ++__i) 71906c3fb27SDimitry Andric if (!_Traits::eq(__str[__i], __zero) && !_Traits::eq(__str[__i], __one)) 72006c3fb27SDimitry Andric std::__throw_invalid_argument("bitset string ctor has invalid argument"); 72106c3fb27SDimitry Andric 72206c3fb27SDimitry Andric size_t __mp = std::min(__str.size(), _Size); 72306c3fb27SDimitry Andric size_t __i = 0; 72406c3fb27SDimitry Andric for (; __i < __mp; ++__i) { 72506c3fb27SDimitry Andric _CharT __c = __str[__mp - 1 - __i]; 72606c3fb27SDimitry Andric (*this)[__i] = _Traits::eq(__c, __one); 72706c3fb27SDimitry Andric } 72806c3fb27SDimitry Andric std::fill(base::__make_iter(__i), base::__make_iter(_Size), false); 72906c3fb27SDimitry Andric } 7300b57cec5SDimitry Andric 731cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI size_t __hash_code() const _NOEXCEPT { return base::__hash_code(); } 7320b57cec5SDimitry Andric 7330b57cec5SDimitry Andric friend struct hash<bitset>; 7340b57cec5SDimitry Andric}; 7350b57cec5SDimitry Andric 7360b57cec5SDimitry Andrictemplate <size_t _Size> 737cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& 738cb14a3feSDimitry Andricbitset<_Size>::operator&=(const bitset& __rhs) _NOEXCEPT { 7390b57cec5SDimitry Andric base::operator&=(__rhs); 7400b57cec5SDimitry Andric return *this; 7410b57cec5SDimitry Andric} 7420b57cec5SDimitry Andric 7430b57cec5SDimitry Andrictemplate <size_t _Size> 744cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& 745cb14a3feSDimitry Andricbitset<_Size>::operator|=(const bitset& __rhs) _NOEXCEPT { 7460b57cec5SDimitry Andric base::operator|=(__rhs); 7470b57cec5SDimitry Andric return *this; 7480b57cec5SDimitry Andric} 7490b57cec5SDimitry Andric 7500b57cec5SDimitry Andrictemplate <size_t _Size> 751cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& 752cb14a3feSDimitry Andricbitset<_Size>::operator^=(const bitset& __rhs) _NOEXCEPT { 7530b57cec5SDimitry Andric base::operator^=(__rhs); 7540b57cec5SDimitry Andric return *this; 7550b57cec5SDimitry Andric} 7560b57cec5SDimitry Andric 7570b57cec5SDimitry Andrictemplate <size_t _Size> 758cb14a3feSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::operator<<=(size_t __pos) _NOEXCEPT { 7595f757f3fSDimitry Andric __pos = std::min(__pos, _Size); 7605f757f3fSDimitry Andric std::copy_backward(base::__make_iter(0), base::__make_iter(_Size - __pos), base::__make_iter(_Size)); 7615f757f3fSDimitry Andric std::fill_n(base::__make_iter(0), __pos, false); 7620b57cec5SDimitry Andric return *this; 7630b57cec5SDimitry Andric} 7640b57cec5SDimitry Andric 7650b57cec5SDimitry Andrictemplate <size_t _Size> 766cb14a3feSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::operator>>=(size_t __pos) _NOEXCEPT { 7675f757f3fSDimitry Andric __pos = std::min(__pos, _Size); 7685f757f3fSDimitry Andric std::copy(base::__make_iter(__pos), base::__make_iter(_Size), base::__make_iter(0)); 7695f757f3fSDimitry Andric std::fill_n(base::__make_iter(_Size - __pos), __pos, false); 7700b57cec5SDimitry Andric return *this; 7710b57cec5SDimitry Andric} 7720b57cec5SDimitry Andric 7730b57cec5SDimitry Andrictemplate <size_t _Size> 774cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::set() _NOEXCEPT { 7755f757f3fSDimitry Andric std::fill_n(base::__make_iter(0), _Size, true); 7760b57cec5SDimitry Andric return *this; 7770b57cec5SDimitry Andric} 7780b57cec5SDimitry Andric 7790b57cec5SDimitry Andrictemplate <size_t _Size> 780cb14a3feSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::set(size_t __pos, bool __val) { 7810b57cec5SDimitry Andric if (__pos >= _Size) 7820b57cec5SDimitry Andric __throw_out_of_range("bitset set argument out of range"); 7830b57cec5SDimitry Andric 7840b57cec5SDimitry Andric (*this)[__pos] = __val; 7850b57cec5SDimitry Andric return *this; 7860b57cec5SDimitry Andric} 7870b57cec5SDimitry Andric 7880b57cec5SDimitry Andrictemplate <size_t _Size> 789cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::reset() _NOEXCEPT { 7905f757f3fSDimitry Andric std::fill_n(base::__make_iter(0), _Size, false); 7910b57cec5SDimitry Andric return *this; 7920b57cec5SDimitry Andric} 7930b57cec5SDimitry Andric 7940b57cec5SDimitry Andrictemplate <size_t _Size> 795cb14a3feSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::reset(size_t __pos) { 7960b57cec5SDimitry Andric if (__pos >= _Size) 7970b57cec5SDimitry Andric __throw_out_of_range("bitset reset argument out of range"); 7980b57cec5SDimitry Andric 7990b57cec5SDimitry Andric (*this)[__pos] = false; 8000b57cec5SDimitry Andric return *this; 8010b57cec5SDimitry Andric} 8020b57cec5SDimitry Andric 8030b57cec5SDimitry Andrictemplate <size_t _Size> 804cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size> bitset<_Size>::operator~() const _NOEXCEPT { 8050b57cec5SDimitry Andric bitset __x(*this); 8060b57cec5SDimitry Andric __x.flip(); 8070b57cec5SDimitry Andric return __x; 8080b57cec5SDimitry Andric} 8090b57cec5SDimitry Andric 8100b57cec5SDimitry Andrictemplate <size_t _Size> 811cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::flip() _NOEXCEPT { 8120b57cec5SDimitry Andric base::flip(); 8130b57cec5SDimitry Andric return *this; 8140b57cec5SDimitry Andric} 8150b57cec5SDimitry Andric 8160b57cec5SDimitry Andrictemplate <size_t _Size> 817cb14a3feSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::flip(size_t __pos) { 8180b57cec5SDimitry Andric if (__pos >= _Size) 8190b57cec5SDimitry Andric __throw_out_of_range("bitset flip argument out of range"); 8200b57cec5SDimitry Andric 82106c3fb27SDimitry Andric reference __r = base::__make_ref(__pos); 82206c3fb27SDimitry Andric __r = ~__r; 8230b57cec5SDimitry Andric return *this; 8240b57cec5SDimitry Andric} 8250b57cec5SDimitry Andric 8260b57cec5SDimitry Andrictemplate <size_t _Size> 827cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long bitset<_Size>::to_ulong() const { 8280b57cec5SDimitry Andric return base::to_ulong(); 8290b57cec5SDimitry Andric} 8300b57cec5SDimitry Andric 8310b57cec5SDimitry Andrictemplate <size_t _Size> 832cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long bitset<_Size>::to_ullong() const { 8330b57cec5SDimitry Andric return base::to_ullong(); 8340b57cec5SDimitry Andric} 8350b57cec5SDimitry Andric 8360b57cec5SDimitry Andrictemplate <size_t _Size> 8370b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 838cb14a3feSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, _Traits, _Allocator> 839cb14a3feSDimitry Andricbitset<_Size>::to_string(_CharT __zero, _CharT __one) const { 8400b57cec5SDimitry Andric basic_string<_CharT, _Traits, _Allocator> __r(_Size, __zero); 841cb14a3feSDimitry Andric for (size_t __i = 0; __i != _Size; ++__i) { 8420b57cec5SDimitry Andric if ((*this)[__i]) 8430b57cec5SDimitry Andric __r[_Size - 1 - __i] = __one; 8440b57cec5SDimitry Andric } 8450b57cec5SDimitry Andric return __r; 8460b57cec5SDimitry Andric} 8470b57cec5SDimitry Andric 8480b57cec5SDimitry Andrictemplate <size_t _Size> 8490b57cec5SDimitry Andrictemplate <class _CharT, class _Traits> 850cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, _Traits, allocator<_CharT> > 851cb14a3feSDimitry Andricbitset<_Size>::to_string(_CharT __zero, _CharT __one) const { 8520b57cec5SDimitry Andric return to_string<_CharT, _Traits, allocator<_CharT> >(__zero, __one); 8530b57cec5SDimitry Andric} 8540b57cec5SDimitry Andric 8550b57cec5SDimitry Andrictemplate <size_t _Size> 8560b57cec5SDimitry Andrictemplate <class _CharT> 857cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > 858cb14a3feSDimitry Andricbitset<_Size>::to_string(_CharT __zero, _CharT __one) const { 8590b57cec5SDimitry Andric return to_string<_CharT, char_traits<_CharT>, allocator<_CharT> >(__zero, __one); 8600b57cec5SDimitry Andric} 8610b57cec5SDimitry Andric 8620b57cec5SDimitry Andrictemplate <size_t _Size> 863cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<char, char_traits<char>, allocator<char> > 864cb14a3feSDimitry Andricbitset<_Size>::to_string(char __zero, char __one) const { 8650b57cec5SDimitry Andric return to_string<char, char_traits<char>, allocator<char> >(__zero, __one); 8660b57cec5SDimitry Andric} 8670b57cec5SDimitry Andric 8680b57cec5SDimitry Andrictemplate <size_t _Size> 869cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 size_t bitset<_Size>::count() const _NOEXCEPT { 8705f757f3fSDimitry Andric return static_cast<size_t>(std::count(base::__make_iter(0), base::__make_iter(_Size), true)); 8710b57cec5SDimitry Andric} 8720b57cec5SDimitry Andric 8730b57cec5SDimitry Andrictemplate <size_t _Size> 874cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool 875cb14a3feSDimitry Andricbitset<_Size>::operator==(const bitset& __rhs) const _NOEXCEPT { 8765f757f3fSDimitry Andric return std::equal(base::__make_iter(0), base::__make_iter(_Size), __rhs.__make_iter(0)); 8770b57cec5SDimitry Andric} 8780b57cec5SDimitry Andric 87906c3fb27SDimitry Andric#if _LIBCPP_STD_VER <= 17 88006c3fb27SDimitry Andric 8810b57cec5SDimitry Andrictemplate <size_t _Size> 882cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool bitset<_Size>::operator!=(const bitset& __rhs) const _NOEXCEPT { 8830b57cec5SDimitry Andric return !(*this == __rhs); 8840b57cec5SDimitry Andric} 8850b57cec5SDimitry Andric 88606c3fb27SDimitry Andric#endif 88706c3fb27SDimitry Andric 8880b57cec5SDimitry Andrictemplate <size_t _Size> 889cb14a3feSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool bitset<_Size>::test(size_t __pos) const { 8900b57cec5SDimitry Andric if (__pos >= _Size) 8910b57cec5SDimitry Andric __throw_out_of_range("bitset test argument out of range"); 8920b57cec5SDimitry Andric 8930b57cec5SDimitry Andric return (*this)[__pos]; 8940b57cec5SDimitry Andric} 8950b57cec5SDimitry Andric 8960b57cec5SDimitry Andrictemplate <size_t _Size> 897cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool bitset<_Size>::all() const _NOEXCEPT { 8980b57cec5SDimitry Andric return base::all(); 8990b57cec5SDimitry Andric} 9000b57cec5SDimitry Andric 9010b57cec5SDimitry Andrictemplate <size_t _Size> 902cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool bitset<_Size>::any() const _NOEXCEPT { 9030b57cec5SDimitry Andric return base::any(); 9040b57cec5SDimitry Andric} 9050b57cec5SDimitry Andric 9060b57cec5SDimitry Andrictemplate <size_t _Size> 907cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size> 908cb14a3feSDimitry Andricbitset<_Size>::operator<<(size_t __pos) const _NOEXCEPT { 9090b57cec5SDimitry Andric bitset __r = *this; 9100b57cec5SDimitry Andric __r <<= __pos; 9110b57cec5SDimitry Andric return __r; 9120b57cec5SDimitry Andric} 9130b57cec5SDimitry Andric 9140b57cec5SDimitry Andrictemplate <size_t _Size> 915cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size> 916cb14a3feSDimitry Andricbitset<_Size>::operator>>(size_t __pos) const _NOEXCEPT { 9170b57cec5SDimitry Andric bitset __r = *this; 9180b57cec5SDimitry Andric __r >>= __pos; 9190b57cec5SDimitry Andric return __r; 9200b57cec5SDimitry Andric} 9210b57cec5SDimitry Andric 9220b57cec5SDimitry Andrictemplate <size_t _Size> 923cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size> 924cb14a3feSDimitry Andricoperator&(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT { 9250b57cec5SDimitry Andric bitset<_Size> __r = __x; 9260b57cec5SDimitry Andric __r &= __y; 9270b57cec5SDimitry Andric return __r; 9280b57cec5SDimitry Andric} 9290b57cec5SDimitry Andric 9300b57cec5SDimitry Andrictemplate <size_t _Size> 931cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size> 932cb14a3feSDimitry Andricoperator|(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT { 9330b57cec5SDimitry Andric bitset<_Size> __r = __x; 9340b57cec5SDimitry Andric __r |= __y; 9350b57cec5SDimitry Andric return __r; 9360b57cec5SDimitry Andric} 9370b57cec5SDimitry Andric 9380b57cec5SDimitry Andrictemplate <size_t _Size> 939cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size> 940cb14a3feSDimitry Andricoperator^(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT { 9410b57cec5SDimitry Andric bitset<_Size> __r = __x; 9420b57cec5SDimitry Andric __r ^= __y; 9430b57cec5SDimitry Andric return __r; 9440b57cec5SDimitry Andric} 9450b57cec5SDimitry Andric 9460b57cec5SDimitry Andrictemplate <size_t _Size> 947cb14a3feSDimitry Andricstruct _LIBCPP_TEMPLATE_VIS hash<bitset<_Size> > : public __unary_function<bitset<_Size>, size_t> { 948cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI size_t operator()(const bitset<_Size>& __bs) const _NOEXCEPT { return __bs.__hash_code(); } 9490b57cec5SDimitry Andric}; 9500b57cec5SDimitry Andric 9510b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, size_t _Size> 952bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>& 9530b57cec5SDimitry Andricoperator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x); 9540b57cec5SDimitry Andric 9550b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, size_t _Size> 956bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& 9570b57cec5SDimitry Andricoperator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x); 9580b57cec5SDimitry Andric 9590b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD 9600b57cec5SDimitry Andric 9610b57cec5SDimitry Andric_LIBCPP_POP_MACROS 9620b57cec5SDimitry Andric 963bdd1243dSDimitry Andric#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 964bdd1243dSDimitry Andric# include <concepts> 96506c3fb27SDimitry Andric# include <cstdlib> 96606c3fb27SDimitry Andric# include <type_traits> 967bdd1243dSDimitry Andric#endif 968bdd1243dSDimitry Andric 9690b57cec5SDimitry Andric#endif // _LIBCPP_BITSET 970