Warning, /include/c++/v1/__cxx03/bitset is written in an unsupported language. File is not indexed.
0001 // -*- C++ -*-
0002 //===----------------------------------------------------------------------===//
0003 //
0004 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0005 // See https://llvm.org/LICENSE.txt for license information.
0006 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0007 //
0008 //===----------------------------------------------------------------------===//
0009
0010 #ifndef _LIBCPP___CXX03_BITSET
0011 #define _LIBCPP___CXX03_BITSET
0012
0013 // clang-format off
0014
0015 /*
0016 bitset synopsis
0017
0018 namespace std
0019 {
0020
0021 namespace std {
0022
0023 template <size_t N>
0024 class bitset
0025 {
0026 public:
0027 // bit reference:
0028 class reference
0029 {
0030 friend class bitset;
0031 reference() noexcept;
0032 public:
0033 ~reference() noexcept;
0034 reference& operator=(bool x) noexcept; // for b[i] = x;
0035 reference& operator=(const reference&) noexcept; // for b[i] = b[j];
0036 bool operator~() const noexcept; // flips the bit
0037 operator bool() const noexcept; // for x = b[i];
0038 reference& flip() noexcept; // for b[i].flip();
0039 };
0040
0041 // 23.3.5.1 constructors:
0042 constexpr bitset() noexcept;
0043 constexpr bitset(unsigned long long val) noexcept;
0044 template <class charT>
0045 constexpr explicit bitset(const charT* str,
0046 typename basic_string<charT>::size_type n = basic_string<charT>::npos,
0047 charT zero = charT('0'), charT one = charT('1')); // until C++26, constexpr since C++23
0048 template <class charT>
0049 constexpr explicit bitset(const charT* str,
0050 typename basic_string_view<charT>::size_type n = basic_string_view<charT>::npos,
0051 charT zero = charT('0'), charT one = charT('1')); // since C++26
0052 template<class charT, class traits>
0053 explicit bitset(
0054 const basic_string_view<charT,traits>& str,
0055 typename basic_string_view<charT,traits>::size_type pos = 0,
0056 typename basic_string_view<charT,traits>::size_type n = basic_string_view<charT,traits>::npos,
0057 charT zero = charT('0'), charT one = charT('1')); // since C++26
0058 template<class charT, class traits, class Allocator>
0059 constexpr explicit bitset(
0060 const basic_string<charT,traits,Allocator>& str,
0061 typename basic_string<charT,traits,Allocator>::size_type pos = 0,
0062 typename basic_string<charT,traits,Allocator>::size_type n = basic_string<charT,traits,Allocator>::npos,
0063 charT zero = charT('0'), charT one = charT('1')); // constexpr since C++23
0064
0065 // 23.3.5.2 bitset operations:
0066 bitset& operator&=(const bitset& rhs) noexcept; // constexpr since C++23
0067 bitset& operator|=(const bitset& rhs) noexcept; // constexpr since C++23
0068 bitset& operator^=(const bitset& rhs) noexcept; // constexpr since C++23
0069 bitset& operator<<=(size_t pos) noexcept; // constexpr since C++23
0070 bitset& operator>>=(size_t pos) noexcept; // constexpr since C++23
0071 bitset& set() noexcept; // constexpr since C++23
0072 bitset& set(size_t pos, bool val = true); // constexpr since C++23
0073 bitset& reset() noexcept; // constexpr since C++23
0074 bitset& reset(size_t pos); // constexpr since C++23
0075 bitset operator~() const noexcept; // constexpr since C++23
0076 bitset& flip() noexcept; // constexpr since C++23
0077 bitset& flip(size_t pos); // constexpr since C++23
0078
0079 // element access:
0080 constexpr bool operator[](size_t pos) const;
0081 reference operator[](size_t pos); // constexpr since C++23
0082 unsigned long to_ulong() const; // constexpr since C++23
0083 unsigned long long to_ullong() const; // constexpr since C++23
0084 template <class charT, class traits, class Allocator> // constexpr since C++23
0085 basic_string<charT, traits, Allocator> to_string(charT zero = charT('0'), charT one = charT('1')) const;
0086 template <class charT, class traits> // constexpr since C++23
0087 basic_string<charT, traits, allocator<charT> > to_string(charT zero = charT('0'), charT one = charT('1')) const;
0088 template <class charT> // constexpr since C++23
0089 basic_string<charT, char_traits<charT>, allocator<charT> > to_string(charT zero = charT('0'), charT one = charT('1')) const;
0090 basic_string<char, char_traits<char>, allocator<char> > to_string(char zero = '0', char one = '1') const; // constexpr since C++23
0091 size_t count() const noexcept; // constexpr since C++23
0092 constexpr size_t size() const noexcept; // constexpr since C++23
0093 bool operator==(const bitset& rhs) const noexcept; // constexpr since C++23
0094 bool operator!=(const bitset& rhs) const noexcept; // removed in C++20
0095 bool test(size_t pos) const; // constexpr since C++23
0096 bool all() const noexcept; // constexpr since C++23
0097 bool any() const noexcept; // constexpr since C++23
0098 bool none() const noexcept; // constexpr since C++23
0099 bitset<N> operator<<(size_t pos) const noexcept; // constexpr since C++23
0100 bitset<N> operator>>(size_t pos) const noexcept; // constexpr since C++23
0101 };
0102
0103 // 23.3.5.3 bitset operators:
0104 template <size_t N>
0105 bitset<N> operator&(const bitset<N>&, const bitset<N>&) noexcept; // constexpr since C++23
0106
0107 template <size_t N>
0108 bitset<N> operator|(const bitset<N>&, const bitset<N>&) noexcept; // constexpr since C++23
0109
0110 template <size_t N>
0111 bitset<N> operator^(const bitset<N>&, const bitset<N>&) noexcept; // constexpr since C++23
0112
0113 template <class charT, class traits, size_t N>
0114 basic_istream<charT, traits>&
0115 operator>>(basic_istream<charT, traits>& is, bitset<N>& x);
0116
0117 template <class charT, class traits, size_t N>
0118 basic_ostream<charT, traits>&
0119 operator<<(basic_ostream<charT, traits>& os, const bitset<N>& x);
0120
0121 template <size_t N> struct hash<std::bitset<N>>;
0122
0123 } // std
0124
0125 */
0126
0127 // clang-format on
0128
0129 #include <__cxx03/__algorithm/count.h>
0130 #include <__cxx03/__algorithm/fill.h>
0131 #include <__cxx03/__algorithm/find.h>
0132 #include <__cxx03/__bit_reference>
0133 #include <__cxx03/__config>
0134 #include <__cxx03/__functional/hash.h>
0135 #include <__cxx03/__functional/unary_function.h>
0136 #include <__cxx03/__type_traits/is_char_like_type.h>
0137 #include <__cxx03/climits>
0138 #include <__cxx03/cstddef>
0139 #include <__cxx03/stdexcept>
0140 #include <__cxx03/string_view>
0141 #include <__cxx03/version>
0142
0143 // standard-mandated includes
0144
0145 // [bitset.syn]
0146 #include <__cxx03/iosfwd>
0147 #include <__cxx03/string>
0148
0149 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0150 # pragma GCC system_header
0151 #endif
0152
0153 _LIBCPP_PUSH_MACROS
0154 #include <__cxx03/__undef_macros>
0155
0156 _LIBCPP_BEGIN_NAMESPACE_STD
0157
0158 template <size_t _N_words, size_t _Size>
0159 class __bitset;
0160
0161 template <size_t _N_words, size_t _Size>
0162 struct __has_storage_type<__bitset<_N_words, _Size> > {
0163 static const bool value = true;
0164 };
0165
0166 template <size_t _N_words, size_t _Size>
0167 class __bitset {
0168 public:
0169 typedef ptrdiff_t difference_type;
0170 typedef size_t size_type;
0171 typedef size_type __storage_type;
0172
0173 protected:
0174 typedef __bitset __self;
0175 typedef __storage_type* __storage_pointer;
0176 typedef const __storage_type* __const_storage_pointer;
0177 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
0178
0179 friend class __bit_reference<__bitset>;
0180 friend class __bit_const_reference<__bitset>;
0181 friend class __bit_iterator<__bitset, false>;
0182 friend class __bit_iterator<__bitset, true>;
0183 friend struct __bit_array<__bitset>;
0184
0185 __storage_type __first_[_N_words];
0186
0187 typedef __bit_reference<__bitset> reference;
0188 typedef __bit_const_reference<__bitset> const_reference;
0189 typedef __bit_iterator<__bitset, false> iterator;
0190 typedef __bit_iterator<__bitset, true> const_iterator;
0191
0192 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
0193 _LIBCPP_HIDE_FROM_ABI explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT;
0194
0195 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 reference __make_ref(size_t __pos) _NOEXCEPT {
0196 return reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);
0197 }
0198 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT {
0199 return const_reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);
0200 }
0201 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 iterator __make_iter(size_t __pos) _NOEXCEPT {
0202 return iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);
0203 }
0204 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 const_iterator __make_iter(size_t __pos) const _NOEXCEPT {
0205 return const_iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);
0206 }
0207
0208 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator&=(const __bitset& __v) _NOEXCEPT;
0209 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator|=(const __bitset& __v) _NOEXCEPT;
0210 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator^=(const __bitset& __v) _NOEXCEPT;
0211
0212 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void flip() _NOEXCEPT;
0213 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong() const {
0214 return to_ulong(integral_constant < bool, _Size< sizeof(unsigned long) * CHAR_BIT>());
0215 }
0216 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong() const {
0217 return to_ullong(integral_constant < bool, _Size< sizeof(unsigned long long) * CHAR_BIT>());
0218 }
0219
0220 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT;
0221 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT;
0222 _LIBCPP_HIDE_FROM_ABI size_t __hash_code() const _NOEXCEPT;
0223
0224 private:
0225 #ifdef _LIBCPP_CXX03_LANG
0226 void __init(unsigned long long __v, false_type) _NOEXCEPT;
0227 _LIBCPP_HIDE_FROM_ABI void __init(unsigned long long __v, true_type) _NOEXCEPT;
0228 #endif // _LIBCPP_CXX03_LANG
0229 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong(false_type) const;
0230 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong(true_type) const;
0231 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong(false_type) const;
0232 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong(true_type) const;
0233 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong(true_type, false_type) const;
0234 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong(true_type, true_type) const;
0235 };
0236
0237 template <size_t _N_words, size_t _Size>
0238 inline _LIBCPP_CONSTEXPR __bitset<_N_words, _Size>::__bitset() _NOEXCEPT
0239 #ifndef _LIBCPP_CXX03_LANG
0240 : __first_{0}
0241 #endif
0242 {
0243 #ifdef _LIBCPP_CXX03_LANG
0244 std::fill_n(__first_, _N_words, __storage_type(0));
0245 #endif
0246 }
0247
0248 #ifdef _LIBCPP_CXX03_LANG
0249
0250 template <size_t _N_words, size_t _Size>
0251 void __bitset<_N_words, _Size>::__init(unsigned long long __v, false_type) _NOEXCEPT {
0252 __storage_type __t[sizeof(unsigned long long) / sizeof(__storage_type)];
0253 size_t __sz = _Size;
0254 for (size_t __i = 0; __i < sizeof(__t) / sizeof(__t[0]); ++__i, __v >>= __bits_per_word, __sz -= __bits_per_word)
0255 if (__sz < __bits_per_word)
0256 __t[__i] = static_cast<__storage_type>(__v) & (1ULL << __sz) - 1;
0257 else
0258 __t[__i] = static_cast<__storage_type>(__v);
0259
0260 std::copy(__t, __t + sizeof(__t) / sizeof(__t[0]), __first_);
0261 std::fill(
0262 __first_ + sizeof(__t) / sizeof(__t[0]), __first_ + sizeof(__first_) / sizeof(__first_[0]), __storage_type(0));
0263 }
0264
0265 template <size_t _N_words, size_t _Size>
0266 inline _LIBCPP_HIDE_FROM_ABI void __bitset<_N_words, _Size>::__init(unsigned long long __v, true_type) _NOEXCEPT {
0267 __first_[0] = __v;
0268 if (_Size < __bits_per_word)
0269 __first_[0] &= (1ULL << _Size) - 1;
0270
0271 std::fill(__first_ + 1, __first_ + sizeof(__first_) / sizeof(__first_[0]), __storage_type(0));
0272 }
0273
0274 #endif // _LIBCPP_CXX03_LANG
0275
0276 template <size_t _N_words, size_t _Size>
0277 inline _LIBCPP_CONSTEXPR __bitset<_N_words, _Size>::__bitset(unsigned long long __v) _NOEXCEPT
0278 #ifndef _LIBCPP_CXX03_LANG
0279 # if __SIZEOF_SIZE_T__ == 8
0280 : __first_{__v}
0281 # elif __SIZEOF_SIZE_T__ == 4
0282 : __first_{static_cast<__storage_type>(__v),
0283 _Size >= 2 * __bits_per_word
0284 ? static_cast<__storage_type>(__v >> __bits_per_word)
0285 : static_cast<__storage_type>((__v >> __bits_per_word) &
0286 (__storage_type(1) << (_Size - __bits_per_word)) - 1)}
0287 # else
0288 # error This constructor has not been ported to this platform
0289 # endif
0290 #endif
0291 {
0292 #ifdef _LIBCPP_CXX03_LANG
0293 __init(__v, integral_constant<bool, sizeof(unsigned long long) == sizeof(__storage_type)>());
0294 #endif
0295 }
0296
0297 template <size_t _N_words, size_t _Size>
0298 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void
0299 __bitset<_N_words, _Size>::operator&=(const __bitset& __v) _NOEXCEPT {
0300 for (size_type __i = 0; __i < _N_words; ++__i)
0301 __first_[__i] &= __v.__first_[__i];
0302 }
0303
0304 template <size_t _N_words, size_t _Size>
0305 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void
0306 __bitset<_N_words, _Size>::operator|=(const __bitset& __v) _NOEXCEPT {
0307 for (size_type __i = 0; __i < _N_words; ++__i)
0308 __first_[__i] |= __v.__first_[__i];
0309 }
0310
0311 template <size_t _N_words, size_t _Size>
0312 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void
0313 __bitset<_N_words, _Size>::operator^=(const __bitset& __v) _NOEXCEPT {
0314 for (size_type __i = 0; __i < _N_words; ++__i)
0315 __first_[__i] ^= __v.__first_[__i];
0316 }
0317
0318 template <size_t _N_words, size_t _Size>
0319 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void __bitset<_N_words, _Size>::flip() _NOEXCEPT {
0320 // do middle whole words
0321 size_type __n = _Size;
0322 __storage_pointer __p = __first_;
0323 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
0324 *__p = ~*__p;
0325 // do last partial word
0326 if (__n > 0) {
0327 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
0328 __storage_type __b = *__p & __m;
0329 *__p &= ~__m;
0330 *__p |= ~__b & __m;
0331 }
0332 }
0333
0334 template <size_t _N_words, size_t _Size>
0335 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long
0336 __bitset<_N_words, _Size>::to_ulong(false_type) const {
0337 const_iterator __e = __make_iter(_Size);
0338 const_iterator __i = std::find(__make_iter(sizeof(unsigned long) * CHAR_BIT), __e, true);
0339 if (__i != __e)
0340 __throw_overflow_error("bitset to_ulong overflow error");
0341
0342 return __first_[0];
0343 }
0344
0345 template <size_t _N_words, size_t _Size>
0346 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long
0347 __bitset<_N_words, _Size>::to_ulong(true_type) const {
0348 return __first_[0];
0349 }
0350
0351 template <size_t _N_words, size_t _Size>
0352 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long
0353 __bitset<_N_words, _Size>::to_ullong(false_type) const {
0354 const_iterator __e = __make_iter(_Size);
0355 const_iterator __i = std::find(__make_iter(sizeof(unsigned long long) * CHAR_BIT), __e, true);
0356 if (__i != __e)
0357 __throw_overflow_error("bitset to_ullong overflow error");
0358
0359 return to_ullong(true_type());
0360 }
0361
0362 template <size_t _N_words, size_t _Size>
0363 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long
0364 __bitset<_N_words, _Size>::to_ullong(true_type) const {
0365 return to_ullong(true_type(), integral_constant<bool, sizeof(__storage_type) < sizeof(unsigned long long)>());
0366 }
0367
0368 template <size_t _N_words, size_t _Size>
0369 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long
0370 __bitset<_N_words, _Size>::to_ullong(true_type, false_type) const {
0371 return __first_[0];
0372 }
0373
0374 template <size_t _N_words, size_t _Size>
0375 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long
0376 __bitset<_N_words, _Size>::to_ullong(true_type, true_type) const {
0377 unsigned long long __r = __first_[0];
0378 _LIBCPP_DIAGNOSTIC_PUSH
0379 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wshift-count-overflow")
0380 for (size_t __i = 1; __i < sizeof(unsigned long long) / sizeof(__storage_type); ++__i)
0381 __r |= static_cast<unsigned long long>(__first_[__i]) << (sizeof(__storage_type) * CHAR_BIT);
0382 _LIBCPP_DIAGNOSTIC_POP
0383 return __r;
0384 }
0385
0386 template <size_t _N_words, size_t _Size>
0387 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool __bitset<_N_words, _Size>::all() const _NOEXCEPT {
0388 // do middle whole words
0389 size_type __n = _Size;
0390 __const_storage_pointer __p = __first_;
0391 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
0392 if (~*__p)
0393 return false;
0394 // do last partial word
0395 if (__n > 0) {
0396 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
0397 if (~*__p & __m)
0398 return false;
0399 }
0400 return true;
0401 }
0402
0403 template <size_t _N_words, size_t _Size>
0404 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool __bitset<_N_words, _Size>::any() const _NOEXCEPT {
0405 // do middle whole words
0406 size_type __n = _Size;
0407 __const_storage_pointer __p = __first_;
0408 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
0409 if (*__p)
0410 return true;
0411 // do last partial word
0412 if (__n > 0) {
0413 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
0414 if (*__p & __m)
0415 return true;
0416 }
0417 return false;
0418 }
0419
0420 template <size_t _N_words, size_t _Size>
0421 inline size_t __bitset<_N_words, _Size>::__hash_code() const _NOEXCEPT {
0422 size_t __h = 0;
0423 for (size_type __i = 0; __i < _N_words; ++__i)
0424 __h ^= __first_[__i];
0425 return __h;
0426 }
0427
0428 template <size_t _Size>
0429 class __bitset<1, _Size> {
0430 public:
0431 typedef ptrdiff_t difference_type;
0432 typedef size_t size_type;
0433 typedef size_type __storage_type;
0434
0435 protected:
0436 typedef __bitset __self;
0437 typedef __storage_type* __storage_pointer;
0438 typedef const __storage_type* __const_storage_pointer;
0439 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
0440
0441 friend class __bit_reference<__bitset>;
0442 friend class __bit_const_reference<__bitset>;
0443 friend class __bit_iterator<__bitset, false>;
0444 friend class __bit_iterator<__bitset, true>;
0445 friend struct __bit_array<__bitset>;
0446
0447 __storage_type __first_;
0448
0449 typedef __bit_reference<__bitset> reference;
0450 typedef __bit_const_reference<__bitset> const_reference;
0451 typedef __bit_iterator<__bitset, false> iterator;
0452 typedef __bit_iterator<__bitset, true> const_iterator;
0453
0454 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
0455 _LIBCPP_HIDE_FROM_ABI explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT;
0456
0457 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 reference __make_ref(size_t __pos) _NOEXCEPT {
0458 return reference(&__first_, __storage_type(1) << __pos);
0459 }
0460 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT {
0461 return const_reference(&__first_, __storage_type(1) << __pos);
0462 }
0463 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 iterator __make_iter(size_t __pos) _NOEXCEPT {
0464 return iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);
0465 }
0466 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 const_iterator __make_iter(size_t __pos) const _NOEXCEPT {
0467 return const_iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);
0468 }
0469
0470 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator&=(const __bitset& __v) _NOEXCEPT;
0471 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator|=(const __bitset& __v) _NOEXCEPT;
0472 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator^=(const __bitset& __v) _NOEXCEPT;
0473
0474 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void flip() _NOEXCEPT;
0475
0476 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong() const;
0477 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong() const;
0478
0479 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT;
0480 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT;
0481
0482 _LIBCPP_HIDE_FROM_ABI size_t __hash_code() const _NOEXCEPT;
0483 };
0484
0485 template <size_t _Size>
0486 inline _LIBCPP_CONSTEXPR __bitset<1, _Size>::__bitset() _NOEXCEPT : __first_(0) {}
0487
0488 template <size_t _Size>
0489 inline _LIBCPP_CONSTEXPR __bitset<1, _Size>::__bitset(unsigned long long __v) _NOEXCEPT
0490 : __first_(_Size == __bits_per_word ? static_cast<__storage_type>(__v)
0491 : static_cast<__storage_type>(__v) & ((__storage_type(1) << _Size) - 1)) {}
0492
0493 template <size_t _Size>
0494 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void
0495 __bitset<1, _Size>::operator&=(const __bitset& __v) _NOEXCEPT {
0496 __first_ &= __v.__first_;
0497 }
0498
0499 template <size_t _Size>
0500 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void
0501 __bitset<1, _Size>::operator|=(const __bitset& __v) _NOEXCEPT {
0502 __first_ |= __v.__first_;
0503 }
0504
0505 template <size_t _Size>
0506 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void
0507 __bitset<1, _Size>::operator^=(const __bitset& __v) _NOEXCEPT {
0508 __first_ ^= __v.__first_;
0509 }
0510
0511 template <size_t _Size>
0512 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void __bitset<1, _Size>::flip() _NOEXCEPT {
0513 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
0514 __first_ = ~__first_;
0515 __first_ &= __m;
0516 }
0517
0518 template <size_t _Size>
0519 inline _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long __bitset<1, _Size>::to_ulong() const {
0520 return __first_;
0521 }
0522
0523 template <size_t _Size>
0524 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long __bitset<1, _Size>::to_ullong() const {
0525 return __first_;
0526 }
0527
0528 template <size_t _Size>
0529 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool __bitset<1, _Size>::all() const _NOEXCEPT {
0530 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
0531 return !(~__first_ & __m);
0532 }
0533
0534 template <size_t _Size>
0535 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool __bitset<1, _Size>::any() const _NOEXCEPT {
0536 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
0537 return __first_ & __m;
0538 }
0539
0540 template <size_t _Size>
0541 inline size_t __bitset<1, _Size>::__hash_code() const _NOEXCEPT {
0542 return __first_;
0543 }
0544
0545 template <>
0546 class __bitset<0, 0> {
0547 public:
0548 typedef ptrdiff_t difference_type;
0549 typedef size_t size_type;
0550 typedef size_type __storage_type;
0551
0552 protected:
0553 typedef __bitset __self;
0554 typedef __storage_type* __storage_pointer;
0555 typedef const __storage_type* __const_storage_pointer;
0556 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
0557
0558 friend class __bit_reference<__bitset>;
0559 friend class __bit_const_reference<__bitset>;
0560 friend class __bit_iterator<__bitset, false>;
0561 friend class __bit_iterator<__bitset, true>;
0562 friend struct __bit_array<__bitset>;
0563
0564 typedef __bit_reference<__bitset> reference;
0565 typedef __bit_const_reference<__bitset> const_reference;
0566 typedef __bit_iterator<__bitset, false> iterator;
0567 typedef __bit_iterator<__bitset, true> const_iterator;
0568
0569 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
0570 _LIBCPP_HIDE_FROM_ABI explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long) _NOEXCEPT;
0571
0572 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 reference __make_ref(size_t) _NOEXCEPT {
0573 return reference(nullptr, 1);
0574 }
0575 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const_reference __make_ref(size_t) const _NOEXCEPT {
0576 return const_reference(nullptr, 1);
0577 }
0578 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 iterator __make_iter(size_t) _NOEXCEPT {
0579 return iterator(nullptr, 0);
0580 }
0581 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 const_iterator __make_iter(size_t) const _NOEXCEPT {
0582 return const_iterator(nullptr, 0);
0583 }
0584
0585 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator&=(const __bitset&) _NOEXCEPT {}
0586 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator|=(const __bitset&) _NOEXCEPT {}
0587 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator^=(const __bitset&) _NOEXCEPT {}
0588
0589 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void flip() _NOEXCEPT {}
0590
0591 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong() const { return 0; }
0592 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong() const { return 0; }
0593
0594 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT { return true; }
0595 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT { return false; }
0596
0597 _LIBCPP_HIDE_FROM_ABI size_t __hash_code() const _NOEXCEPT { return 0; }
0598 };
0599
0600 inline _LIBCPP_CONSTEXPR __bitset<0, 0>::__bitset() _NOEXCEPT {}
0601
0602 inline _LIBCPP_CONSTEXPR __bitset<0, 0>::__bitset(unsigned long long) _NOEXCEPT {}
0603
0604 template <size_t _Size>
0605 class _LIBCPP_TEMPLATE_VIS bitset;
0606 template <size_t _Size>
0607 struct hash<bitset<_Size> >;
0608
0609 template <size_t _Size>
0610 class _LIBCPP_TEMPLATE_VIS bitset
0611 : private __bitset<_Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1, _Size> {
0612 public:
0613 static const unsigned __n_words = _Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1;
0614 typedef __bitset<__n_words, _Size> base;
0615
0616 public:
0617 typedef typename base::reference reference;
0618 typedef typename base::const_reference const_reference;
0619
0620 // 23.3.5.1 constructors:
0621 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bitset() _NOEXCEPT {}
0622 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bitset(unsigned long long __v) _NOEXCEPT : base(__v) {}
0623 template <class _CharT, __enable_if_t<_IsCharLikeType<_CharT>::value, int> = 0>
0624 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 explicit bitset(
0625 const _CharT* __str,
0626 #if _LIBCPP_STD_VER >= 26
0627 typename basic_string_view<_CharT>::size_type __n = basic_string_view<_CharT>::npos,
0628 #else
0629 typename basic_string<_CharT>::size_type __n = basic_string<_CharT>::npos,
0630 #endif
0631 _CharT __zero = _CharT('0'),
0632 _CharT __one = _CharT('1')) {
0633
0634 size_t __rlen = std::min(__n, char_traits<_CharT>::length(__str));
0635 __init_from_string_view(basic_string_view<_CharT>(__str, __rlen), __zero, __one);
0636 }
0637 #if _LIBCPP_STD_VER >= 26
0638 template <class _CharT, class _Traits>
0639 _LIBCPP_HIDE_FROM_ABI constexpr explicit bitset(
0640 basic_string_view<_CharT, _Traits> __str,
0641 typename basic_string_view<_CharT, _Traits>::size_type __pos = 0,
0642 typename basic_string_view<_CharT, _Traits>::size_type __n = basic_string_view<_CharT, _Traits>::npos,
0643 _CharT __zero = _CharT('0'),
0644 _CharT __one = _CharT('1')) {
0645 if (__pos > __str.size())
0646 __throw_out_of_range("bitset string pos out of range");
0647
0648 size_t __rlen = std::min(__n, __str.size() - __pos);
0649 __init_from_string_view(basic_string_view<_CharT, _Traits>(__str.data() + __pos, __rlen), __zero, __one);
0650 }
0651 #endif
0652 template <class _CharT, class _Traits, class _Allocator>
0653 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 explicit bitset(
0654 const basic_string<_CharT, _Traits, _Allocator>& __str,
0655 typename basic_string<_CharT, _Traits, _Allocator>::size_type __pos = 0,
0656 typename basic_string<_CharT, _Traits, _Allocator>::size_type __n =
0657 basic_string<_CharT, _Traits, _Allocator>::npos,
0658 _CharT __zero = _CharT('0'),
0659 _CharT __one = _CharT('1')) {
0660 if (__pos > __str.size())
0661 std::__throw_out_of_range("bitset string pos out of range");
0662
0663 size_t __rlen = std::min(__n, __str.size() - __pos);
0664 __init_from_string_view(basic_string_view<_CharT, _Traits>(__str.data() + __pos, __rlen), __zero, __one);
0665 }
0666
0667 // 23.3.5.2 bitset operations:
0668 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& operator&=(const bitset& __rhs) _NOEXCEPT;
0669 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& operator|=(const bitset& __rhs) _NOEXCEPT;
0670 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& operator^=(const bitset& __rhs) _NOEXCEPT;
0671 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& operator<<=(size_t __pos) _NOEXCEPT;
0672 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& operator>>=(size_t __pos) _NOEXCEPT;
0673 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& set() _NOEXCEPT;
0674 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& set(size_t __pos, bool __val = true);
0675 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& reset() _NOEXCEPT;
0676 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& reset(size_t __pos);
0677 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset operator~() const _NOEXCEPT;
0678 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& flip() _NOEXCEPT;
0679 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& flip(size_t __pos);
0680
0681 // element access:
0682 #ifdef _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL
0683 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool operator[](size_t __p) const { return base::__make_ref(__p); }
0684 #else
0685 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const_reference operator[](size_t __p) const { return base::__make_ref(__p); }
0686 #endif
0687 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 reference operator[](size_t __p) { return base::__make_ref(__p); }
0688 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong() const;
0689 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong() const;
0690 template <class _CharT, class _Traits, class _Allocator>
0691 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, _Traits, _Allocator>
0692 to_string(_CharT __zero = _CharT('0'), _CharT __one = _CharT('1')) const;
0693 template <class _CharT, class _Traits>
0694 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, _Traits, allocator<_CharT> >
0695 to_string(_CharT __zero = _CharT('0'), _CharT __one = _CharT('1')) const;
0696 template <class _CharT>
0697 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> >
0698 to_string(_CharT __zero = _CharT('0'), _CharT __one = _CharT('1')) const;
0699 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<char, char_traits<char>, allocator<char> >
0700 to_string(char __zero = '0', char __one = '1') const;
0701 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 size_t count() const _NOEXCEPT;
0702 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR size_t size() const _NOEXCEPT { return _Size; }
0703 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool operator==(const bitset& __rhs) const _NOEXCEPT;
0704 #if _LIBCPP_STD_VER <= 17
0705 _LIBCPP_HIDE_FROM_ABI bool operator!=(const bitset& __rhs) const _NOEXCEPT;
0706 #endif
0707 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool test(size_t __pos) const;
0708 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT;
0709 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT;
0710 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool none() const _NOEXCEPT { return !any(); }
0711 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset operator<<(size_t __pos) const _NOEXCEPT;
0712 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset operator>>(size_t __pos) const _NOEXCEPT;
0713
0714 private:
0715 template <class _CharT, class _Traits>
0716 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void
0717 __init_from_string_view(basic_string_view<_CharT, _Traits> __str, _CharT __zero, _CharT __one) {
0718 for (size_t __i = 0; __i < __str.size(); ++__i)
0719 if (!_Traits::eq(__str[__i], __zero) && !_Traits::eq(__str[__i], __one))
0720 std::__throw_invalid_argument("bitset string ctor has invalid argument");
0721
0722 size_t __mp = std::min(__str.size(), _Size);
0723 size_t __i = 0;
0724 for (; __i < __mp; ++__i) {
0725 _CharT __c = __str[__mp - 1 - __i];
0726 (*this)[__i] = _Traits::eq(__c, __one);
0727 }
0728 std::fill(base::__make_iter(__i), base::__make_iter(_Size), false);
0729 }
0730
0731 _LIBCPP_HIDE_FROM_ABI size_t __hash_code() const _NOEXCEPT { return base::__hash_code(); }
0732
0733 friend struct hash<bitset>;
0734 };
0735
0736 template <size_t _Size>
0737 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>&
0738 bitset<_Size>::operator&=(const bitset& __rhs) _NOEXCEPT {
0739 base::operator&=(__rhs);
0740 return *this;
0741 }
0742
0743 template <size_t _Size>
0744 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>&
0745 bitset<_Size>::operator|=(const bitset& __rhs) _NOEXCEPT {
0746 base::operator|=(__rhs);
0747 return *this;
0748 }
0749
0750 template <size_t _Size>
0751 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>&
0752 bitset<_Size>::operator^=(const bitset& __rhs) _NOEXCEPT {
0753 base::operator^=(__rhs);
0754 return *this;
0755 }
0756
0757 template <size_t _Size>
0758 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::operator<<=(size_t __pos) _NOEXCEPT {
0759 __pos = std::min(__pos, _Size);
0760 std::copy_backward(base::__make_iter(0), base::__make_iter(_Size - __pos), base::__make_iter(_Size));
0761 std::fill_n(base::__make_iter(0), __pos, false);
0762 return *this;
0763 }
0764
0765 template <size_t _Size>
0766 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::operator>>=(size_t __pos) _NOEXCEPT {
0767 __pos = std::min(__pos, _Size);
0768 std::copy(base::__make_iter(__pos), base::__make_iter(_Size), base::__make_iter(0));
0769 std::fill_n(base::__make_iter(_Size - __pos), __pos, false);
0770 return *this;
0771 }
0772
0773 template <size_t _Size>
0774 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::set() _NOEXCEPT {
0775 std::fill_n(base::__make_iter(0), _Size, true);
0776 return *this;
0777 }
0778
0779 template <size_t _Size>
0780 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::set(size_t __pos, bool __val) {
0781 if (__pos >= _Size)
0782 __throw_out_of_range("bitset set argument out of range");
0783
0784 (*this)[__pos] = __val;
0785 return *this;
0786 }
0787
0788 template <size_t _Size>
0789 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::reset() _NOEXCEPT {
0790 std::fill_n(base::__make_iter(0), _Size, false);
0791 return *this;
0792 }
0793
0794 template <size_t _Size>
0795 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::reset(size_t __pos) {
0796 if (__pos >= _Size)
0797 __throw_out_of_range("bitset reset argument out of range");
0798
0799 (*this)[__pos] = false;
0800 return *this;
0801 }
0802
0803 template <size_t _Size>
0804 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size> bitset<_Size>::operator~() const _NOEXCEPT {
0805 bitset __x(*this);
0806 __x.flip();
0807 return __x;
0808 }
0809
0810 template <size_t _Size>
0811 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::flip() _NOEXCEPT {
0812 base::flip();
0813 return *this;
0814 }
0815
0816 template <size_t _Size>
0817 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::flip(size_t __pos) {
0818 if (__pos >= _Size)
0819 __throw_out_of_range("bitset flip argument out of range");
0820
0821 reference __r = base::__make_ref(__pos);
0822 __r = ~__r;
0823 return *this;
0824 }
0825
0826 template <size_t _Size>
0827 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long bitset<_Size>::to_ulong() const {
0828 return base::to_ulong();
0829 }
0830
0831 template <size_t _Size>
0832 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long bitset<_Size>::to_ullong() const {
0833 return base::to_ullong();
0834 }
0835
0836 template <size_t _Size>
0837 template <class _CharT, class _Traits, class _Allocator>
0838 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, _Traits, _Allocator>
0839 bitset<_Size>::to_string(_CharT __zero, _CharT __one) const {
0840 basic_string<_CharT, _Traits, _Allocator> __r(_Size, __zero);
0841 for (size_t __i = 0; __i != _Size; ++__i) {
0842 if ((*this)[__i])
0843 __r[_Size - 1 - __i] = __one;
0844 }
0845 return __r;
0846 }
0847
0848 template <size_t _Size>
0849 template <class _CharT, class _Traits>
0850 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, _Traits, allocator<_CharT> >
0851 bitset<_Size>::to_string(_CharT __zero, _CharT __one) const {
0852 return to_string<_CharT, _Traits, allocator<_CharT> >(__zero, __one);
0853 }
0854
0855 template <size_t _Size>
0856 template <class _CharT>
0857 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> >
0858 bitset<_Size>::to_string(_CharT __zero, _CharT __one) const {
0859 return to_string<_CharT, char_traits<_CharT>, allocator<_CharT> >(__zero, __one);
0860 }
0861
0862 template <size_t _Size>
0863 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<char, char_traits<char>, allocator<char> >
0864 bitset<_Size>::to_string(char __zero, char __one) const {
0865 return to_string<char, char_traits<char>, allocator<char> >(__zero, __one);
0866 }
0867
0868 template <size_t _Size>
0869 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 size_t bitset<_Size>::count() const _NOEXCEPT {
0870 return static_cast<size_t>(std::count(base::__make_iter(0), base::__make_iter(_Size), true));
0871 }
0872
0873 template <size_t _Size>
0874 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool
0875 bitset<_Size>::operator==(const bitset& __rhs) const _NOEXCEPT {
0876 return std::equal(base::__make_iter(0), base::__make_iter(_Size), __rhs.__make_iter(0));
0877 }
0878
0879 #if _LIBCPP_STD_VER <= 17
0880
0881 template <size_t _Size>
0882 inline _LIBCPP_HIDE_FROM_ABI bool bitset<_Size>::operator!=(const bitset& __rhs) const _NOEXCEPT {
0883 return !(*this == __rhs);
0884 }
0885
0886 #endif
0887
0888 template <size_t _Size>
0889 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool bitset<_Size>::test(size_t __pos) const {
0890 if (__pos >= _Size)
0891 __throw_out_of_range("bitset test argument out of range");
0892
0893 return (*this)[__pos];
0894 }
0895
0896 template <size_t _Size>
0897 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool bitset<_Size>::all() const _NOEXCEPT {
0898 return base::all();
0899 }
0900
0901 template <size_t _Size>
0902 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool bitset<_Size>::any() const _NOEXCEPT {
0903 return base::any();
0904 }
0905
0906 template <size_t _Size>
0907 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>
0908 bitset<_Size>::operator<<(size_t __pos) const _NOEXCEPT {
0909 bitset __r = *this;
0910 __r <<= __pos;
0911 return __r;
0912 }
0913
0914 template <size_t _Size>
0915 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>
0916 bitset<_Size>::operator>>(size_t __pos) const _NOEXCEPT {
0917 bitset __r = *this;
0918 __r >>= __pos;
0919 return __r;
0920 }
0921
0922 template <size_t _Size>
0923 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>
0924 operator&(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT {
0925 bitset<_Size> __r = __x;
0926 __r &= __y;
0927 return __r;
0928 }
0929
0930 template <size_t _Size>
0931 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>
0932 operator|(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT {
0933 bitset<_Size> __r = __x;
0934 __r |= __y;
0935 return __r;
0936 }
0937
0938 template <size_t _Size>
0939 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>
0940 operator^(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT {
0941 bitset<_Size> __r = __x;
0942 __r ^= __y;
0943 return __r;
0944 }
0945
0946 template <size_t _Size>
0947 struct _LIBCPP_TEMPLATE_VIS hash<bitset<_Size> > : public __unary_function<bitset<_Size>, size_t> {
0948 _LIBCPP_HIDE_FROM_ABI size_t operator()(const bitset<_Size>& __bs) const _NOEXCEPT { return __bs.__hash_code(); }
0949 };
0950
0951 template <class _CharT, class _Traits, size_t _Size>
0952 _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
0953 operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x);
0954
0955 template <class _CharT, class _Traits, size_t _Size>
0956 _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
0957 operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x);
0958
0959 _LIBCPP_END_NAMESPACE_STD
0960
0961 _LIBCPP_POP_MACROS
0962
0963 #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
0964 # include <__cxx03/concepts>
0965 # include <__cxx03/cstdlib>
0966 # include <__cxx03/type_traits>
0967 #endif
0968
0969 #endif // _LIBCPP___CXX03_BITSET