xref: /freebsd/contrib/llvm-project/libcxx/include/bitset (revision 9bc300465e48e19d794d88d0c158a2adb92c7197)
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>
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_LIBCPP_BEGIN_NAMESPACE_STD
1580b57cec5SDimitry Andric
1590b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size>
1600b57cec5SDimitry Andricclass __bitset;
1610b57cec5SDimitry Andric
1620b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size>
163cb14a3feSDimitry Andricstruct __has_storage_type<__bitset<_N_words, _Size> > {
1640b57cec5SDimitry Andric  static const bool value = true;
1650b57cec5SDimitry Andric};
1660b57cec5SDimitry Andric
1670b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size>
168cb14a3feSDimitry Andricclass __bitset {
1690b57cec5SDimitry Andricpublic:
1700b57cec5SDimitry Andric  typedef ptrdiff_t difference_type;
1710b57cec5SDimitry Andric  typedef size_t size_type;
1720b57cec5SDimitry Andric  typedef size_type __storage_type;
173cb14a3feSDimitry Andric
1740b57cec5SDimitry Andricprotected:
1750b57cec5SDimitry Andric  typedef __bitset __self;
1760b57cec5SDimitry Andric  typedef __storage_type* __storage_pointer;
1770b57cec5SDimitry Andric  typedef const __storage_type* __const_storage_pointer;
1780b57cec5SDimitry Andric  static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
1790b57cec5SDimitry Andric
1800b57cec5SDimitry Andric  friend class __bit_reference<__bitset>;
1810b57cec5SDimitry Andric  friend class __bit_const_reference<__bitset>;
1820b57cec5SDimitry Andric  friend class __bit_iterator<__bitset, false>;
1830b57cec5SDimitry Andric  friend class __bit_iterator<__bitset, true>;
1840b57cec5SDimitry Andric  friend struct __bit_array<__bitset>;
1850b57cec5SDimitry Andric
1860b57cec5SDimitry Andric  __storage_type __first_[_N_words];
1870b57cec5SDimitry Andric
1880b57cec5SDimitry Andric  typedef __bit_reference<__bitset> reference;
1890b57cec5SDimitry Andric  typedef __bit_const_reference<__bitset> const_reference;
1900b57cec5SDimitry Andric  typedef __bit_iterator<__bitset, false> iterator;
1910b57cec5SDimitry Andric  typedef __bit_iterator<__bitset, true> const_iterator;
1920b57cec5SDimitry Andric
193cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
194cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT;
1950b57cec5SDimitry Andric
196cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 reference __make_ref(size_t __pos) _NOEXCEPT {
197cb14a3feSDimitry Andric    return reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);
198cb14a3feSDimitry Andric  }
199cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT {
200cb14a3feSDimitry Andric    return const_reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);
201cb14a3feSDimitry Andric  }
202cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 iterator __make_iter(size_t __pos) _NOEXCEPT {
203cb14a3feSDimitry Andric    return iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);
204cb14a3feSDimitry Andric  }
205cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 const_iterator __make_iter(size_t __pos) const _NOEXCEPT {
206cb14a3feSDimitry Andric    return const_iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);
207cb14a3feSDimitry Andric  }
2080b57cec5SDimitry Andric
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;
211cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator^=(const __bitset& __v) _NOEXCEPT;
2120b57cec5SDimitry Andric
213bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void flip() _NOEXCEPT;
214cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong() const {
215cb14a3feSDimitry Andric    return to_ulong(integral_constant < bool, _Size< sizeof(unsigned long) * CHAR_BIT>());
216cb14a3feSDimitry Andric  }
217cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong() const {
218cb14a3feSDimitry Andric    return to_ullong(integral_constant < bool, _Size< sizeof(unsigned long long) * CHAR_BIT>());
219cb14a3feSDimitry Andric  }
2200b57cec5SDimitry Andric
221bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT;
222bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT;
223cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_t __hash_code() const _NOEXCEPT;
224cb14a3feSDimitry Andric
2250b57cec5SDimitry Andricprivate:
2260b57cec5SDimitry Andric#ifdef _LIBCPP_CXX03_LANG
2270b57cec5SDimitry Andric  void __init(unsigned long long __v, false_type) _NOEXCEPT;
228cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __init(unsigned long long __v, true_type) _NOEXCEPT;
2290b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
230cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong(false_type) const;
231cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong(true_type) const;
232cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong(false_type) const;
233cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong(true_type) const;
234cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong(true_type, false_type) const;
235cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong(true_type, true_type) const;
2360b57cec5SDimitry Andric};
2370b57cec5SDimitry Andric
2380b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size>
239cb14a3feSDimitry Andricinline _LIBCPP_CONSTEXPR __bitset<_N_words, _Size>::__bitset() _NOEXCEPT
2400b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
2410b57cec5SDimitry Andric    : __first_{0}
2420b57cec5SDimitry Andric#endif
2430b57cec5SDimitry Andric{
2440b57cec5SDimitry Andric#ifdef _LIBCPP_CXX03_LANG
2455f757f3fSDimitry Andric  std::fill_n(__first_, _N_words, __storage_type(0));
2460b57cec5SDimitry Andric#endif
2470b57cec5SDimitry Andric}
2480b57cec5SDimitry Andric
2490b57cec5SDimitry Andric#ifdef _LIBCPP_CXX03_LANG
2500b57cec5SDimitry Andric
2510b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size>
252cb14a3feSDimitry Andricvoid __bitset<_N_words, _Size>::__init(unsigned long long __v, false_type) _NOEXCEPT {
2530b57cec5SDimitry Andric  __storage_type __t[sizeof(unsigned long long) / sizeof(__storage_type)];
2540b57cec5SDimitry Andric  size_t __sz = _Size;
2550b57cec5SDimitry Andric  for (size_t __i = 0; __i < sizeof(__t) / sizeof(__t[0]); ++__i, __v >>= __bits_per_word, __sz -= __bits_per_word)
2560b57cec5SDimitry Andric    if (__sz < __bits_per_word)
2570b57cec5SDimitry Andric      __t[__i] = static_cast<__storage_type>(__v) & (1ULL << __sz) - 1;
2580b57cec5SDimitry Andric    else
2590b57cec5SDimitry Andric      __t[__i] = static_cast<__storage_type>(__v);
2600b57cec5SDimitry Andric
2615f757f3fSDimitry Andric  std::copy(__t, __t + sizeof(__t) / sizeof(__t[0]), __first_);
262cb14a3feSDimitry Andric  std::fill(
263cb14a3feSDimitry Andric      __first_ + sizeof(__t) / sizeof(__t[0]), __first_ + sizeof(__first_) / sizeof(__first_[0]), __storage_type(0));
2640b57cec5SDimitry Andric}
2650b57cec5SDimitry Andric
2660b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size>
267cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI void __bitset<_N_words, _Size>::__init(unsigned long long __v, true_type) _NOEXCEPT {
2680b57cec5SDimitry Andric  __first_[0] = __v;
2690b57cec5SDimitry Andric  if (_Size < __bits_per_word)
2700b57cec5SDimitry Andric    __first_[0] &= (1ULL << _Size) - 1;
2710b57cec5SDimitry Andric
2725f757f3fSDimitry Andric  std::fill(__first_ + 1, __first_ + sizeof(__first_) / sizeof(__first_[0]), __storage_type(0));
2730b57cec5SDimitry Andric}
2740b57cec5SDimitry Andric
2750b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
2760b57cec5SDimitry Andric
2770b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size>
278cb14a3feSDimitry Andricinline _LIBCPP_CONSTEXPR __bitset<_N_words, _Size>::__bitset(unsigned long long __v) _NOEXCEPT
2790b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
2800b57cec5SDimitry Andric#  if __SIZEOF_SIZE_T__ == 8
2810b57cec5SDimitry Andric    : __first_{__v}
2820b57cec5SDimitry Andric#  elif __SIZEOF_SIZE_T__ == 4
2830b57cec5SDimitry Andric    : __first_{static_cast<__storage_type>(__v),
284cb14a3feSDimitry Andric               _Size >= 2 * __bits_per_word
285cb14a3feSDimitry Andric                   ? static_cast<__storage_type>(__v >> __bits_per_word)
286cb14a3feSDimitry Andric                   : static_cast<__storage_type>((__v >> __bits_per_word) &
287cb14a3feSDimitry Andric                                                 (__storage_type(1) << (_Size - __bits_per_word)) - 1)}
2880b57cec5SDimitry Andric#  else
2890b57cec5SDimitry Andric#    error This constructor has not been ported to this platform
2900b57cec5SDimitry Andric#  endif
2910b57cec5SDimitry Andric#endif
2920b57cec5SDimitry Andric{
2930b57cec5SDimitry Andric#ifdef _LIBCPP_CXX03_LANG
2940b57cec5SDimitry Andric  __init(__v, integral_constant<bool, sizeof(unsigned long long) == sizeof(__storage_type)>());
2950b57cec5SDimitry Andric#endif
2960b57cec5SDimitry Andric}
2970b57cec5SDimitry Andric
2980b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size>
299cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void
300cb14a3feSDimitry Andric__bitset<_N_words, _Size>::operator&=(const __bitset& __v) _NOEXCEPT {
3010b57cec5SDimitry Andric  for (size_type __i = 0; __i < _N_words; ++__i)
3020b57cec5SDimitry Andric    __first_[__i] &= __v.__first_[__i];
3030b57cec5SDimitry Andric}
3040b57cec5SDimitry Andric
3050b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size>
306cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void
307cb14a3feSDimitry Andric__bitset<_N_words, _Size>::operator|=(const __bitset& __v) _NOEXCEPT {
3080b57cec5SDimitry Andric  for (size_type __i = 0; __i < _N_words; ++__i)
3090b57cec5SDimitry Andric    __first_[__i] |= __v.__first_[__i];
3100b57cec5SDimitry Andric}
3110b57cec5SDimitry Andric
3120b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size>
313cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void
314cb14a3feSDimitry Andric__bitset<_N_words, _Size>::operator^=(const __bitset& __v) _NOEXCEPT {
3150b57cec5SDimitry Andric  for (size_type __i = 0; __i < _N_words; ++__i)
3160b57cec5SDimitry Andric    __first_[__i] ^= __v.__first_[__i];
3170b57cec5SDimitry Andric}
3180b57cec5SDimitry Andric
3190b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size>
320cb14a3feSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void __bitset<_N_words, _Size>::flip() _NOEXCEPT {
3210b57cec5SDimitry Andric  // do middle whole words
3220b57cec5SDimitry Andric  size_type __n         = _Size;
3230b57cec5SDimitry Andric  __storage_pointer __p = __first_;
3240b57cec5SDimitry Andric  for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
3250b57cec5SDimitry Andric    *__p = ~*__p;
3260b57cec5SDimitry Andric  // do last partial word
327cb14a3feSDimitry Andric  if (__n > 0) {
3280b57cec5SDimitry Andric    __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
3290b57cec5SDimitry Andric    __storage_type __b = *__p & __m;
3300b57cec5SDimitry Andric    *__p &= ~__m;
3310b57cec5SDimitry Andric    *__p |= ~__b & __m;
3320b57cec5SDimitry Andric  }
3330b57cec5SDimitry Andric}
3340b57cec5SDimitry Andric
3350b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size>
336bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long
337cb14a3feSDimitry Andric__bitset<_N_words, _Size>::to_ulong(false_type) const {
3380b57cec5SDimitry Andric  const_iterator __e = __make_iter(_Size);
3395f757f3fSDimitry Andric  const_iterator __i = std::find(__make_iter(sizeof(unsigned long) * CHAR_BIT), __e, true);
3400b57cec5SDimitry Andric  if (__i != __e)
3410b57cec5SDimitry Andric    __throw_overflow_error("bitset to_ulong overflow error");
3420b57cec5SDimitry Andric
3430b57cec5SDimitry Andric  return __first_[0];
3440b57cec5SDimitry Andric}
3450b57cec5SDimitry Andric
3460b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size>
347cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long
348cb14a3feSDimitry Andric__bitset<_N_words, _Size>::to_ulong(true_type) const {
3490b57cec5SDimitry Andric  return __first_[0];
3500b57cec5SDimitry Andric}
3510b57cec5SDimitry Andric
3520b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size>
353bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long
354cb14a3feSDimitry Andric__bitset<_N_words, _Size>::to_ullong(false_type) const {
3550b57cec5SDimitry Andric  const_iterator __e = __make_iter(_Size);
3565f757f3fSDimitry Andric  const_iterator __i = std::find(__make_iter(sizeof(unsigned long long) * CHAR_BIT), __e, true);
3570b57cec5SDimitry Andric  if (__i != __e)
3580b57cec5SDimitry Andric    __throw_overflow_error("bitset to_ullong overflow error");
3590b57cec5SDimitry Andric
3600b57cec5SDimitry Andric  return to_ullong(true_type());
3610b57cec5SDimitry Andric}
3620b57cec5SDimitry Andric
3630b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size>
364cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long
365cb14a3feSDimitry Andric__bitset<_N_words, _Size>::to_ullong(true_type) const {
3660b57cec5SDimitry Andric  return to_ullong(true_type(), integral_constant<bool, sizeof(__storage_type) < sizeof(unsigned long long)>());
3670b57cec5SDimitry Andric}
3680b57cec5SDimitry Andric
3690b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size>
370cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long
371cb14a3feSDimitry Andric__bitset<_N_words, _Size>::to_ullong(true_type, false_type) const {
3720b57cec5SDimitry Andric  return __first_[0];
3730b57cec5SDimitry Andric}
3740b57cec5SDimitry Andric
3750b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size>
376bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long
377cb14a3feSDimitry Andric__bitset<_N_words, _Size>::to_ullong(true_type, true_type) const {
3780b57cec5SDimitry Andric  unsigned long long __r = __first_[0];
379*9bc30046SJohn Baldwin  _LIBCPP_DIAGNOSTIC_PUSH
380*9bc30046SJohn Baldwin  _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wshift-count-overflow")
381e8d8bef9SDimitry Andric  for (size_t __i = 1; __i < sizeof(unsigned long long) / sizeof(__storage_type); ++__i)
3820b57cec5SDimitry Andric    __r |= static_cast<unsigned long long>(__first_[__i]) << (sizeof(__storage_type) * CHAR_BIT);
383*9bc30046SJohn Baldwin  _LIBCPP_DIAGNOSTIC_POP
3840b57cec5SDimitry Andric  return __r;
3850b57cec5SDimitry Andric}
3860b57cec5SDimitry Andric
3870b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size>
388cb14a3feSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool __bitset<_N_words, _Size>::all() const _NOEXCEPT {
3890b57cec5SDimitry Andric  // do middle whole words
3900b57cec5SDimitry Andric  size_type __n               = _Size;
3910b57cec5SDimitry Andric  __const_storage_pointer __p = __first_;
3920b57cec5SDimitry Andric  for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
3930b57cec5SDimitry Andric    if (~*__p)
3940b57cec5SDimitry Andric      return false;
3950b57cec5SDimitry Andric  // do last partial word
396cb14a3feSDimitry Andric  if (__n > 0) {
3970b57cec5SDimitry Andric    __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
3980b57cec5SDimitry Andric    if (~*__p & __m)
3990b57cec5SDimitry Andric      return false;
4000b57cec5SDimitry Andric  }
4010b57cec5SDimitry Andric  return true;
4020b57cec5SDimitry Andric}
4030b57cec5SDimitry Andric
4040b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size>
405cb14a3feSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool __bitset<_N_words, _Size>::any() const _NOEXCEPT {
4060b57cec5SDimitry Andric  // do middle whole words
4070b57cec5SDimitry Andric  size_type __n               = _Size;
4080b57cec5SDimitry Andric  __const_storage_pointer __p = __first_;
4090b57cec5SDimitry Andric  for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
4100b57cec5SDimitry Andric    if (*__p)
4110b57cec5SDimitry Andric      return true;
4120b57cec5SDimitry Andric  // do last partial word
413cb14a3feSDimitry Andric  if (__n > 0) {
4140b57cec5SDimitry Andric    __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
4150b57cec5SDimitry Andric    if (*__p & __m)
4160b57cec5SDimitry Andric      return true;
4170b57cec5SDimitry Andric  }
4180b57cec5SDimitry Andric  return false;
4190b57cec5SDimitry Andric}
4200b57cec5SDimitry Andric
4210b57cec5SDimitry Andrictemplate <size_t _N_words, size_t _Size>
422cb14a3feSDimitry Andricinline size_t __bitset<_N_words, _Size>::__hash_code() const _NOEXCEPT {
4230b57cec5SDimitry Andric  size_t __h = 0;
4240b57cec5SDimitry Andric  for (size_type __i = 0; __i < _N_words; ++__i)
4250b57cec5SDimitry Andric    __h ^= __first_[__i];
4260b57cec5SDimitry Andric  return __h;
4270b57cec5SDimitry Andric}
4280b57cec5SDimitry Andric
4290b57cec5SDimitry Andrictemplate <size_t _Size>
430cb14a3feSDimitry Andricclass __bitset<1, _Size> {
4310b57cec5SDimitry Andricpublic:
4320b57cec5SDimitry Andric  typedef ptrdiff_t difference_type;
4330b57cec5SDimitry Andric  typedef size_t size_type;
4340b57cec5SDimitry Andric  typedef size_type __storage_type;
435cb14a3feSDimitry Andric
4360b57cec5SDimitry Andricprotected:
4370b57cec5SDimitry Andric  typedef __bitset __self;
4380b57cec5SDimitry Andric  typedef __storage_type* __storage_pointer;
4390b57cec5SDimitry Andric  typedef const __storage_type* __const_storage_pointer;
4400b57cec5SDimitry Andric  static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
4410b57cec5SDimitry Andric
4420b57cec5SDimitry Andric  friend class __bit_reference<__bitset>;
4430b57cec5SDimitry Andric  friend class __bit_const_reference<__bitset>;
4440b57cec5SDimitry Andric  friend class __bit_iterator<__bitset, false>;
4450b57cec5SDimitry Andric  friend class __bit_iterator<__bitset, true>;
4460b57cec5SDimitry Andric  friend struct __bit_array<__bitset>;
4470b57cec5SDimitry Andric
4480b57cec5SDimitry Andric  __storage_type __first_;
4490b57cec5SDimitry Andric
4500b57cec5SDimitry Andric  typedef __bit_reference<__bitset> reference;
4510b57cec5SDimitry Andric  typedef __bit_const_reference<__bitset> const_reference;
4520b57cec5SDimitry Andric  typedef __bit_iterator<__bitset, false> iterator;
4530b57cec5SDimitry Andric  typedef __bit_iterator<__bitset, true> const_iterator;
4540b57cec5SDimitry Andric
455cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
456cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT;
4570b57cec5SDimitry Andric
458cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 reference __make_ref(size_t __pos) _NOEXCEPT {
459cb14a3feSDimitry Andric    return reference(&__first_, __storage_type(1) << __pos);
460cb14a3feSDimitry Andric  }
461cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT {
462cb14a3feSDimitry Andric    return const_reference(&__first_, __storage_type(1) << __pos);
463cb14a3feSDimitry Andric  }
464cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 iterator __make_iter(size_t __pos) _NOEXCEPT {
465cb14a3feSDimitry Andric    return iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);
466cb14a3feSDimitry Andric  }
467cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 const_iterator __make_iter(size_t __pos) const _NOEXCEPT {
468cb14a3feSDimitry Andric    return const_iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);
469cb14a3feSDimitry Andric  }
4700b57cec5SDimitry Andric
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;
473cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator^=(const __bitset& __v) _NOEXCEPT;
4740b57cec5SDimitry Andric
475cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void flip() _NOEXCEPT;
4760b57cec5SDimitry Andric
477cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong() const;
478cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong() const;
4790b57cec5SDimitry Andric
480cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT;
481cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT;
4820b57cec5SDimitry Andric
483cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_t __hash_code() const _NOEXCEPT;
4840b57cec5SDimitry Andric};
4850b57cec5SDimitry Andric
4860b57cec5SDimitry Andrictemplate <size_t _Size>
487cb14a3feSDimitry Andricinline _LIBCPP_CONSTEXPR __bitset<1, _Size>::__bitset() _NOEXCEPT : __first_(0) {}
4880b57cec5SDimitry Andric
4890b57cec5SDimitry Andrictemplate <size_t _Size>
490cb14a3feSDimitry Andricinline _LIBCPP_CONSTEXPR __bitset<1, _Size>::__bitset(unsigned long long __v) _NOEXCEPT
491cb14a3feSDimitry Andric    : __first_(_Size == __bits_per_word ? static_cast<__storage_type>(__v)
492cb14a3feSDimitry Andric                                        : static_cast<__storage_type>(__v) & ((__storage_type(1) << _Size) - 1)) {}
4930b57cec5SDimitry Andric
4940b57cec5SDimitry Andrictemplate <size_t _Size>
495cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void
496cb14a3feSDimitry Andric__bitset<1, _Size>::operator&=(const __bitset& __v) _NOEXCEPT {
4970b57cec5SDimitry Andric  __first_ &= __v.__first_;
4980b57cec5SDimitry Andric}
4990b57cec5SDimitry Andric
5000b57cec5SDimitry Andrictemplate <size_t _Size>
501cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void
502cb14a3feSDimitry Andric__bitset<1, _Size>::operator|=(const __bitset& __v) _NOEXCEPT {
5030b57cec5SDimitry Andric  __first_ |= __v.__first_;
5040b57cec5SDimitry Andric}
5050b57cec5SDimitry Andric
5060b57cec5SDimitry Andrictemplate <size_t _Size>
507cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void
508cb14a3feSDimitry Andric__bitset<1, _Size>::operator^=(const __bitset& __v) _NOEXCEPT {
5090b57cec5SDimitry Andric  __first_ ^= __v.__first_;
5100b57cec5SDimitry Andric}
5110b57cec5SDimitry Andric
5120b57cec5SDimitry Andrictemplate <size_t _Size>
513cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void __bitset<1, _Size>::flip() _NOEXCEPT {
5140b57cec5SDimitry Andric  __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
5150b57cec5SDimitry Andric  __first_           = ~__first_;
5160b57cec5SDimitry Andric  __first_ &= __m;
5170b57cec5SDimitry Andric}
5180b57cec5SDimitry Andric
5190b57cec5SDimitry Andrictemplate <size_t _Size>
520cb14a3feSDimitry Andricinline _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long __bitset<1, _Size>::to_ulong() const {
5210b57cec5SDimitry Andric  return __first_;
5220b57cec5SDimitry Andric}
5230b57cec5SDimitry Andric
5240b57cec5SDimitry Andrictemplate <size_t _Size>
525cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long __bitset<1, _Size>::to_ullong() const {
5260b57cec5SDimitry Andric  return __first_;
5270b57cec5SDimitry Andric}
5280b57cec5SDimitry Andric
5290b57cec5SDimitry Andrictemplate <size_t _Size>
530cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool __bitset<1, _Size>::all() const _NOEXCEPT {
5310b57cec5SDimitry Andric  __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
5320b57cec5SDimitry Andric  return !(~__first_ & __m);
5330b57cec5SDimitry Andric}
5340b57cec5SDimitry Andric
5350b57cec5SDimitry Andrictemplate <size_t _Size>
536cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool __bitset<1, _Size>::any() const _NOEXCEPT {
5370b57cec5SDimitry Andric  __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
5380b57cec5SDimitry Andric  return __first_ & __m;
5390b57cec5SDimitry Andric}
5400b57cec5SDimitry Andric
5410b57cec5SDimitry Andrictemplate <size_t _Size>
542cb14a3feSDimitry Andricinline size_t __bitset<1, _Size>::__hash_code() const _NOEXCEPT {
5430b57cec5SDimitry Andric  return __first_;
5440b57cec5SDimitry Andric}
5450b57cec5SDimitry Andric
5460b57cec5SDimitry Andrictemplate <>
547cb14a3feSDimitry Andricclass __bitset<0, 0> {
5480b57cec5SDimitry Andricpublic:
5490b57cec5SDimitry Andric  typedef ptrdiff_t difference_type;
5500b57cec5SDimitry Andric  typedef size_t size_type;
5510b57cec5SDimitry Andric  typedef size_type __storage_type;
552cb14a3feSDimitry Andric
5530b57cec5SDimitry Andricprotected:
5540b57cec5SDimitry Andric  typedef __bitset __self;
5550b57cec5SDimitry Andric  typedef __storage_type* __storage_pointer;
5560b57cec5SDimitry Andric  typedef const __storage_type* __const_storage_pointer;
5570b57cec5SDimitry Andric  static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
5580b57cec5SDimitry Andric
5590b57cec5SDimitry Andric  friend class __bit_reference<__bitset>;
5600b57cec5SDimitry Andric  friend class __bit_const_reference<__bitset>;
5610b57cec5SDimitry Andric  friend class __bit_iterator<__bitset, false>;
5620b57cec5SDimitry Andric  friend class __bit_iterator<__bitset, true>;
5630b57cec5SDimitry Andric  friend struct __bit_array<__bitset>;
5640b57cec5SDimitry Andric
5650b57cec5SDimitry Andric  typedef __bit_reference<__bitset> reference;
5660b57cec5SDimitry Andric  typedef __bit_const_reference<__bitset> const_reference;
5670b57cec5SDimitry Andric  typedef __bit_iterator<__bitset, false> iterator;
5680b57cec5SDimitry Andric  typedef __bit_iterator<__bitset, true> const_iterator;
5690b57cec5SDimitry Andric
570cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
571cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long) _NOEXCEPT;
5720b57cec5SDimitry Andric
573cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 reference __make_ref(size_t) _NOEXCEPT {
574cb14a3feSDimitry Andric    return reference(nullptr, 1);
575cb14a3feSDimitry Andric  }
576cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const_reference __make_ref(size_t) const _NOEXCEPT {
577cb14a3feSDimitry Andric    return const_reference(nullptr, 1);
578cb14a3feSDimitry Andric  }
579cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 iterator __make_iter(size_t) _NOEXCEPT {
580cb14a3feSDimitry Andric    return iterator(nullptr, 0);
581cb14a3feSDimitry Andric  }
582cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 const_iterator __make_iter(size_t) const _NOEXCEPT {
583cb14a3feSDimitry Andric    return const_iterator(nullptr, 0);
584cb14a3feSDimitry Andric  }
5850b57cec5SDimitry Andric
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 {}
5885f757f3fSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator^=(const __bitset&) _NOEXCEPT {}
5890b57cec5SDimitry Andric
5905f757f3fSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void flip() _NOEXCEPT {}
5910b57cec5SDimitry Andric
5925f757f3fSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong() const { return 0; }
5935f757f3fSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong() const { return 0; }
5940b57cec5SDimitry Andric
5955f757f3fSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT { return true; }
5965f757f3fSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT { return false; }
5970b57cec5SDimitry Andric
5985f757f3fSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_t __hash_code() const _NOEXCEPT { return 0; }
5990b57cec5SDimitry Andric};
6000b57cec5SDimitry Andric
601cb14a3feSDimitry Andricinline _LIBCPP_CONSTEXPR __bitset<0, 0>::__bitset() _NOEXCEPT {}
6020b57cec5SDimitry Andric
603cb14a3feSDimitry Andricinline _LIBCPP_CONSTEXPR __bitset<0, 0>::__bitset(unsigned long long) _NOEXCEPT {}
6040b57cec5SDimitry Andric
605cb14a3feSDimitry Andrictemplate <size_t _Size>
606cb14a3feSDimitry Andricclass _LIBCPP_TEMPLATE_VIS bitset;
607cb14a3feSDimitry Andrictemplate <size_t _Size>
608cb14a3feSDimitry Andricstruct hash<bitset<_Size> >;
6090b57cec5SDimitry Andric
6100b57cec5SDimitry Andrictemplate <size_t _Size>
6110b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS bitset
612cb14a3feSDimitry Andric    : private __bitset<_Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1, _Size> {
6130b57cec5SDimitry Andricpublic:
6140b57cec5SDimitry Andric  static const unsigned __n_words = _Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1;
6150b57cec5SDimitry Andric  typedef __bitset<__n_words, _Size> base;
6160b57cec5SDimitry Andric
6170b57cec5SDimitry Andricpublic:
6180b57cec5SDimitry Andric  typedef typename base::reference reference;
6190b57cec5SDimitry Andric  typedef typename base::const_reference const_reference;
6200b57cec5SDimitry Andric
6210b57cec5SDimitry Andric  // 23.3.5.1 constructors:
6225f757f3fSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bitset() _NOEXCEPT {}
623cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bitset(unsigned long long __v) _NOEXCEPT : base(__v) {}
624349cc55cSDimitry Andric  template <class _CharT, class = __enable_if_t<_IsCharLikeType<_CharT>::value> >
62506c3fb27SDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 explicit bitset(
62606c3fb27SDimitry Andric      const _CharT* __str,
6275f757f3fSDimitry Andric#if _LIBCPP_STD_VER >= 26
6285f757f3fSDimitry Andric      typename basic_string_view<_CharT>::size_type __n = basic_string_view<_CharT>::npos,
6295f757f3fSDimitry Andric#else
6300b57cec5SDimitry Andric      typename basic_string<_CharT>::size_type __n = basic_string<_CharT>::npos,
6315f757f3fSDimitry Andric#endif
63206c3fb27SDimitry Andric      _CharT __zero = _CharT('0'),
63306c3fb27SDimitry Andric      _CharT __one  = _CharT('1')) {
63406c3fb27SDimitry Andric
63506c3fb27SDimitry Andric    size_t __rlen = std::min(__n, char_traits<_CharT>::length(__str));
63606c3fb27SDimitry Andric    __init_from_string_view(basic_string_view<_CharT>(__str, __rlen), __zero, __one);
63706c3fb27SDimitry Andric  }
6385f757f3fSDimitry Andric#if _LIBCPP_STD_VER >= 26
6395f757f3fSDimitry Andric  template <class _CharT, class _Traits>
6405f757f3fSDimitry Andric  _LIBCPP_HIDE_FROM_ABI constexpr explicit bitset(
6415f757f3fSDimitry Andric      basic_string_view<_CharT, _Traits> __str,
6425f757f3fSDimitry Andric      typename basic_string_view<_CharT, _Traits>::size_type __pos = 0,
6435f757f3fSDimitry Andric      typename basic_string_view<_CharT, _Traits>::size_type __n   = basic_string_view<_CharT, _Traits>::npos,
6445f757f3fSDimitry Andric      _CharT __zero                                                = _CharT('0'),
6455f757f3fSDimitry Andric      _CharT __one                                                 = _CharT('1')) {
6465f757f3fSDimitry Andric    if (__pos > __str.size())
6475f757f3fSDimitry Andric      __throw_out_of_range("bitset string pos out of range");
6485f757f3fSDimitry Andric
6495f757f3fSDimitry Andric    size_t __rlen = std::min(__n, __str.size() - __pos);
6505f757f3fSDimitry Andric    __init_from_string_view(basic_string_view<_CharT, _Traits>(__str.data() + __pos, __rlen), __zero, __one);
6515f757f3fSDimitry Andric  }
6525f757f3fSDimitry Andric#endif
6530b57cec5SDimitry Andric  template <class _CharT, class _Traits, class _Allocator>
65406c3fb27SDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 explicit bitset(
65506c3fb27SDimitry Andric      const basic_string<_CharT, _Traits, _Allocator>& __str,
6560b57cec5SDimitry Andric      typename basic_string<_CharT, _Traits, _Allocator>::size_type __pos = 0,
6570b57cec5SDimitry Andric      typename basic_string<_CharT, _Traits, _Allocator>::size_type __n =
65806c3fb27SDimitry Andric          basic_string<_CharT, _Traits, _Allocator>::npos,
65906c3fb27SDimitry Andric      _CharT __zero = _CharT('0'),
66006c3fb27SDimitry Andric      _CharT __one  = _CharT('1')) {
66106c3fb27SDimitry Andric    if (__pos > __str.size())
66206c3fb27SDimitry Andric      std::__throw_out_of_range("bitset string pos out of range");
66306c3fb27SDimitry Andric
66406c3fb27SDimitry Andric    size_t __rlen = std::min(__n, __str.size() - __pos);
66506c3fb27SDimitry Andric    __init_from_string_view(basic_string_view<_CharT, _Traits>(__str.data() + __pos, __rlen), __zero, __one);
66606c3fb27SDimitry Andric  }
6670b57cec5SDimitry Andric
6680b57cec5SDimitry Andric  // 23.3.5.2 bitset operations:
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^=(const bitset& __rhs) _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& operator>>=(size_t __pos) _NOEXCEPT;
674cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& set() _NOEXCEPT;
675cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& set(size_t __pos, bool __val = true);
676cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& reset() _NOEXCEPT;
677cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& reset(size_t __pos);
678cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset operator~() const _NOEXCEPT;
679cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& flip() _NOEXCEPT;
680cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& flip(size_t __pos);
6810b57cec5SDimitry Andric
6820b57cec5SDimitry Andric  // element access:
68381ad6265SDimitry Andric#ifdef _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL
68481ad6265SDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool operator[](size_t __p) const { return base::__make_ref(__p); }
68581ad6265SDimitry Andric#else
68681ad6265SDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const_reference operator[](size_t __p) const { return base::__make_ref(__p); }
68781ad6265SDimitry Andric#endif
688bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 reference operator[](size_t __p) { return base::__make_ref(__p); }
689cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong() const;
690cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong() const;
6910b57cec5SDimitry Andric  template <class _CharT, class _Traits, class _Allocator>
692cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, _Traits, _Allocator>
693cb14a3feSDimitry Andric  to_string(_CharT __zero = _CharT('0'), _CharT __one = _CharT('1')) const;
6940b57cec5SDimitry Andric  template <class _CharT, class _Traits>
695cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, _Traits, allocator<_CharT> >
696cb14a3feSDimitry Andric  to_string(_CharT __zero = _CharT('0'), _CharT __one = _CharT('1')) const;
6970b57cec5SDimitry Andric  template <class _CharT>
698cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> >
699cb14a3feSDimitry Andric  to_string(_CharT __zero = _CharT('0'), _CharT __one = _CharT('1')) const;
700cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<char, char_traits<char>, allocator<char> >
701cb14a3feSDimitry Andric  to_string(char __zero = '0', char __one = '1') const;
702cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 size_t count() const _NOEXCEPT;
7035f757f3fSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR size_t size() const _NOEXCEPT { return _Size; }
704cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool operator==(const bitset& __rhs) const _NOEXCEPT;
70506c3fb27SDimitry Andric#if _LIBCPP_STD_VER <= 17
706cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bool operator!=(const bitset& __rhs) const _NOEXCEPT;
70706c3fb27SDimitry Andric#endif
708cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool test(size_t __pos) const;
709cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT;
710cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT;
7115f757f3fSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool none() const _NOEXCEPT { return !any(); }
712cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset operator<<(size_t __pos) const _NOEXCEPT;
713cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset operator>>(size_t __pos) const _NOEXCEPT;
7140b57cec5SDimitry Andric
7150b57cec5SDimitry Andricprivate:
71606c3fb27SDimitry Andric  template <class _CharT, class _Traits>
71706c3fb27SDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void
71806c3fb27SDimitry Andric  __init_from_string_view(basic_string_view<_CharT, _Traits> __str, _CharT __zero, _CharT __one) {
71906c3fb27SDimitry Andric    for (size_t __i = 0; __i < __str.size(); ++__i)
72006c3fb27SDimitry Andric      if (!_Traits::eq(__str[__i], __zero) && !_Traits::eq(__str[__i], __one))
72106c3fb27SDimitry Andric        std::__throw_invalid_argument("bitset string ctor has invalid argument");
72206c3fb27SDimitry Andric
72306c3fb27SDimitry Andric    size_t __mp = std::min(__str.size(), _Size);
72406c3fb27SDimitry Andric    size_t __i  = 0;
72506c3fb27SDimitry Andric    for (; __i < __mp; ++__i) {
72606c3fb27SDimitry Andric      _CharT __c   = __str[__mp - 1 - __i];
72706c3fb27SDimitry Andric      (*this)[__i] = _Traits::eq(__c, __one);
72806c3fb27SDimitry Andric    }
72906c3fb27SDimitry Andric    std::fill(base::__make_iter(__i), base::__make_iter(_Size), false);
73006c3fb27SDimitry Andric  }
7310b57cec5SDimitry Andric
732cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_t __hash_code() const _NOEXCEPT { return base::__hash_code(); }
7330b57cec5SDimitry Andric
7340b57cec5SDimitry Andric  friend struct hash<bitset>;
7350b57cec5SDimitry Andric};
7360b57cec5SDimitry Andric
7370b57cec5SDimitry Andrictemplate <size_t _Size>
738cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>&
739cb14a3feSDimitry Andricbitset<_Size>::operator&=(const bitset& __rhs) _NOEXCEPT {
7400b57cec5SDimitry Andric  base::operator&=(__rhs);
7410b57cec5SDimitry Andric  return *this;
7420b57cec5SDimitry Andric}
7430b57cec5SDimitry Andric
7440b57cec5SDimitry Andrictemplate <size_t _Size>
745cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>&
746cb14a3feSDimitry Andricbitset<_Size>::operator|=(const bitset& __rhs) _NOEXCEPT {
7470b57cec5SDimitry Andric  base::operator|=(__rhs);
7480b57cec5SDimitry Andric  return *this;
7490b57cec5SDimitry Andric}
7500b57cec5SDimitry Andric
7510b57cec5SDimitry Andrictemplate <size_t _Size>
752cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>&
753cb14a3feSDimitry Andricbitset<_Size>::operator^=(const bitset& __rhs) _NOEXCEPT {
7540b57cec5SDimitry Andric  base::operator^=(__rhs);
7550b57cec5SDimitry Andric  return *this;
7560b57cec5SDimitry Andric}
7570b57cec5SDimitry Andric
7580b57cec5SDimitry Andrictemplate <size_t _Size>
759cb14a3feSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::operator<<=(size_t __pos) _NOEXCEPT {
7605f757f3fSDimitry Andric  __pos = std::min(__pos, _Size);
7615f757f3fSDimitry Andric  std::copy_backward(base::__make_iter(0), base::__make_iter(_Size - __pos), base::__make_iter(_Size));
7625f757f3fSDimitry Andric  std::fill_n(base::__make_iter(0), __pos, false);
7630b57cec5SDimitry Andric  return *this;
7640b57cec5SDimitry Andric}
7650b57cec5SDimitry Andric
7660b57cec5SDimitry Andrictemplate <size_t _Size>
767cb14a3feSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::operator>>=(size_t __pos) _NOEXCEPT {
7685f757f3fSDimitry Andric  __pos = std::min(__pos, _Size);
7695f757f3fSDimitry Andric  std::copy(base::__make_iter(__pos), base::__make_iter(_Size), base::__make_iter(0));
7705f757f3fSDimitry Andric  std::fill_n(base::__make_iter(_Size - __pos), __pos, false);
7710b57cec5SDimitry Andric  return *this;
7720b57cec5SDimitry Andric}
7730b57cec5SDimitry Andric
7740b57cec5SDimitry Andrictemplate <size_t _Size>
775cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::set() _NOEXCEPT {
7765f757f3fSDimitry Andric  std::fill_n(base::__make_iter(0), _Size, true);
7770b57cec5SDimitry Andric  return *this;
7780b57cec5SDimitry Andric}
7790b57cec5SDimitry Andric
7800b57cec5SDimitry Andrictemplate <size_t _Size>
781cb14a3feSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::set(size_t __pos, bool __val) {
7820b57cec5SDimitry Andric  if (__pos >= _Size)
7830b57cec5SDimitry Andric    __throw_out_of_range("bitset set argument out of range");
7840b57cec5SDimitry Andric
7850b57cec5SDimitry Andric  (*this)[__pos] = __val;
7860b57cec5SDimitry Andric  return *this;
7870b57cec5SDimitry Andric}
7880b57cec5SDimitry Andric
7890b57cec5SDimitry Andrictemplate <size_t _Size>
790cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::reset() _NOEXCEPT {
7915f757f3fSDimitry Andric  std::fill_n(base::__make_iter(0), _Size, false);
7920b57cec5SDimitry Andric  return *this;
7930b57cec5SDimitry Andric}
7940b57cec5SDimitry Andric
7950b57cec5SDimitry Andrictemplate <size_t _Size>
796cb14a3feSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::reset(size_t __pos) {
7970b57cec5SDimitry Andric  if (__pos >= _Size)
7980b57cec5SDimitry Andric    __throw_out_of_range("bitset reset argument out of range");
7990b57cec5SDimitry Andric
8000b57cec5SDimitry Andric  (*this)[__pos] = false;
8010b57cec5SDimitry Andric  return *this;
8020b57cec5SDimitry Andric}
8030b57cec5SDimitry Andric
8040b57cec5SDimitry Andrictemplate <size_t _Size>
805cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size> bitset<_Size>::operator~() const _NOEXCEPT {
8060b57cec5SDimitry Andric  bitset __x(*this);
8070b57cec5SDimitry Andric  __x.flip();
8080b57cec5SDimitry Andric  return __x;
8090b57cec5SDimitry Andric}
8100b57cec5SDimitry Andric
8110b57cec5SDimitry Andrictemplate <size_t _Size>
812cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::flip() _NOEXCEPT {
8130b57cec5SDimitry Andric  base::flip();
8140b57cec5SDimitry Andric  return *this;
8150b57cec5SDimitry Andric}
8160b57cec5SDimitry Andric
8170b57cec5SDimitry Andrictemplate <size_t _Size>
818cb14a3feSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::flip(size_t __pos) {
8190b57cec5SDimitry Andric  if (__pos >= _Size)
8200b57cec5SDimitry Andric    __throw_out_of_range("bitset flip argument out of range");
8210b57cec5SDimitry Andric
82206c3fb27SDimitry Andric  reference __r = base::__make_ref(__pos);
82306c3fb27SDimitry Andric  __r           = ~__r;
8240b57cec5SDimitry Andric  return *this;
8250b57cec5SDimitry Andric}
8260b57cec5SDimitry Andric
8270b57cec5SDimitry Andrictemplate <size_t _Size>
828cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long bitset<_Size>::to_ulong() const {
8290b57cec5SDimitry Andric  return base::to_ulong();
8300b57cec5SDimitry Andric}
8310b57cec5SDimitry Andric
8320b57cec5SDimitry Andrictemplate <size_t _Size>
833cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long bitset<_Size>::to_ullong() const {
8340b57cec5SDimitry Andric  return base::to_ullong();
8350b57cec5SDimitry Andric}
8360b57cec5SDimitry Andric
8370b57cec5SDimitry Andrictemplate <size_t _Size>
8380b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
839cb14a3feSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, _Traits, _Allocator>
840cb14a3feSDimitry Andricbitset<_Size>::to_string(_CharT __zero, _CharT __one) const {
8410b57cec5SDimitry Andric  basic_string<_CharT, _Traits, _Allocator> __r(_Size, __zero);
842cb14a3feSDimitry Andric  for (size_t __i = 0; __i != _Size; ++__i) {
8430b57cec5SDimitry Andric    if ((*this)[__i])
8440b57cec5SDimitry Andric      __r[_Size - 1 - __i] = __one;
8450b57cec5SDimitry Andric  }
8460b57cec5SDimitry Andric  return __r;
8470b57cec5SDimitry Andric}
8480b57cec5SDimitry Andric
8490b57cec5SDimitry Andrictemplate <size_t _Size>
8500b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
851cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, _Traits, allocator<_CharT> >
852cb14a3feSDimitry Andricbitset<_Size>::to_string(_CharT __zero, _CharT __one) const {
8530b57cec5SDimitry Andric  return to_string<_CharT, _Traits, allocator<_CharT> >(__zero, __one);
8540b57cec5SDimitry Andric}
8550b57cec5SDimitry Andric
8560b57cec5SDimitry Andrictemplate <size_t _Size>
8570b57cec5SDimitry Andrictemplate <class _CharT>
858cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> >
859cb14a3feSDimitry Andricbitset<_Size>::to_string(_CharT __zero, _CharT __one) const {
8600b57cec5SDimitry Andric  return to_string<_CharT, char_traits<_CharT>, allocator<_CharT> >(__zero, __one);
8610b57cec5SDimitry Andric}
8620b57cec5SDimitry Andric
8630b57cec5SDimitry Andrictemplate <size_t _Size>
864cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<char, char_traits<char>, allocator<char> >
865cb14a3feSDimitry Andricbitset<_Size>::to_string(char __zero, char __one) const {
8660b57cec5SDimitry Andric  return to_string<char, char_traits<char>, allocator<char> >(__zero, __one);
8670b57cec5SDimitry Andric}
8680b57cec5SDimitry Andric
8690b57cec5SDimitry Andrictemplate <size_t _Size>
870cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 size_t bitset<_Size>::count() const _NOEXCEPT {
8715f757f3fSDimitry Andric  return static_cast<size_t>(std::count(base::__make_iter(0), base::__make_iter(_Size), true));
8720b57cec5SDimitry Andric}
8730b57cec5SDimitry Andric
8740b57cec5SDimitry Andrictemplate <size_t _Size>
875cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool
876cb14a3feSDimitry Andricbitset<_Size>::operator==(const bitset& __rhs) const _NOEXCEPT {
8775f757f3fSDimitry Andric  return std::equal(base::__make_iter(0), base::__make_iter(_Size), __rhs.__make_iter(0));
8780b57cec5SDimitry Andric}
8790b57cec5SDimitry Andric
88006c3fb27SDimitry Andric#if _LIBCPP_STD_VER <= 17
88106c3fb27SDimitry Andric
8820b57cec5SDimitry Andrictemplate <size_t _Size>
883cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool bitset<_Size>::operator!=(const bitset& __rhs) const _NOEXCEPT {
8840b57cec5SDimitry Andric  return !(*this == __rhs);
8850b57cec5SDimitry Andric}
8860b57cec5SDimitry Andric
88706c3fb27SDimitry Andric#endif
88806c3fb27SDimitry Andric
8890b57cec5SDimitry Andrictemplate <size_t _Size>
890cb14a3feSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool bitset<_Size>::test(size_t __pos) const {
8910b57cec5SDimitry Andric  if (__pos >= _Size)
8920b57cec5SDimitry Andric    __throw_out_of_range("bitset test argument out of range");
8930b57cec5SDimitry Andric
8940b57cec5SDimitry Andric  return (*this)[__pos];
8950b57cec5SDimitry Andric}
8960b57cec5SDimitry Andric
8970b57cec5SDimitry Andrictemplate <size_t _Size>
898cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool bitset<_Size>::all() const _NOEXCEPT {
8990b57cec5SDimitry Andric  return base::all();
9000b57cec5SDimitry Andric}
9010b57cec5SDimitry Andric
9020b57cec5SDimitry Andrictemplate <size_t _Size>
903cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool bitset<_Size>::any() const _NOEXCEPT {
9040b57cec5SDimitry Andric  return base::any();
9050b57cec5SDimitry Andric}
9060b57cec5SDimitry Andric
9070b57cec5SDimitry Andrictemplate <size_t _Size>
908cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>
909cb14a3feSDimitry Andricbitset<_Size>::operator<<(size_t __pos) const _NOEXCEPT {
9100b57cec5SDimitry Andric  bitset __r = *this;
9110b57cec5SDimitry Andric  __r <<= __pos;
9120b57cec5SDimitry Andric  return __r;
9130b57cec5SDimitry Andric}
9140b57cec5SDimitry Andric
9150b57cec5SDimitry Andrictemplate <size_t _Size>
916cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>
917cb14a3feSDimitry Andricbitset<_Size>::operator>>(size_t __pos) const _NOEXCEPT {
9180b57cec5SDimitry Andric  bitset __r = *this;
9190b57cec5SDimitry Andric  __r >>= __pos;
9200b57cec5SDimitry Andric  return __r;
9210b57cec5SDimitry Andric}
9220b57cec5SDimitry Andric
9230b57cec5SDimitry Andrictemplate <size_t _Size>
924cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>
925cb14a3feSDimitry Andricoperator&(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT {
9260b57cec5SDimitry Andric  bitset<_Size> __r = __x;
9270b57cec5SDimitry Andric  __r &= __y;
9280b57cec5SDimitry Andric  return __r;
9290b57cec5SDimitry Andric}
9300b57cec5SDimitry Andric
9310b57cec5SDimitry Andrictemplate <size_t _Size>
932cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>
933cb14a3feSDimitry Andricoperator|(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT {
9340b57cec5SDimitry Andric  bitset<_Size> __r = __x;
9350b57cec5SDimitry Andric  __r |= __y;
9360b57cec5SDimitry Andric  return __r;
9370b57cec5SDimitry Andric}
9380b57cec5SDimitry Andric
9390b57cec5SDimitry Andrictemplate <size_t _Size>
940cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>
941cb14a3feSDimitry Andricoperator^(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT {
9420b57cec5SDimitry Andric  bitset<_Size> __r = __x;
9430b57cec5SDimitry Andric  __r ^= __y;
9440b57cec5SDimitry Andric  return __r;
9450b57cec5SDimitry Andric}
9460b57cec5SDimitry Andric
9470b57cec5SDimitry Andrictemplate <size_t _Size>
948cb14a3feSDimitry Andricstruct _LIBCPP_TEMPLATE_VIS hash<bitset<_Size> > : public __unary_function<bitset<_Size>, size_t> {
949cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_t operator()(const bitset<_Size>& __bs) const _NOEXCEPT { return __bs.__hash_code(); }
9500b57cec5SDimitry Andric};
9510b57cec5SDimitry Andric
9520b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, size_t _Size>
953bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
9540b57cec5SDimitry Andricoperator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x);
9550b57cec5SDimitry Andric
9560b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, size_t _Size>
957bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
9580b57cec5SDimitry Andricoperator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x);
9590b57cec5SDimitry Andric
9600b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD
9610b57cec5SDimitry Andric
9620b57cec5SDimitry Andric_LIBCPP_POP_MACROS
9630b57cec5SDimitry Andric
964bdd1243dSDimitry Andric#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
965bdd1243dSDimitry Andric#  include <concepts>
96606c3fb27SDimitry Andric#  include <cstdlib>
96706c3fb27SDimitry Andric#  include <type_traits>
968bdd1243dSDimitry Andric#endif
969bdd1243dSDimitry Andric
9700b57cec5SDimitry Andric#endif // _LIBCPP_BITSET
971