blob: 809fadf6d228ac4b5ee6310482afb2465fdaee05 [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
Louis Dionne9bd93882021-11-17 16:25:01 -05002//===----------------------------------------------------------------------===//
Howard Hinnantc51e1022010-05-11 19:42:16 +00003//
Chandler Carruthd2012102019-01-19 10:56:40 +00004// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Howard Hinnantc51e1022010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_BITSET
11#define _LIBCPP_BITSET
12
13/*
14 bitset synopsis
15
16namespace std
17{
18
19namespace std {
20
21template <size_t N>
22class bitset
23{
24public:
25 // bit reference:
26 class reference
27 {
28 friend class bitset;
Howard Hinnant42b84842011-05-27 20:52:28 +000029 reference() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000030 public:
Howard Hinnant42b84842011-05-27 20:52:28 +000031 ~reference() noexcept;
32 reference& operator=(bool x) noexcept; // for b[i] = x;
33 reference& operator=(const reference&) noexcept; // for b[i] = b[j];
34 bool operator~() const noexcept; // flips the bit
35 operator bool() const noexcept; // for x = b[i];
36 reference& flip() noexcept; // for b[i].flip();
Howard Hinnantc51e1022010-05-11 19:42:16 +000037 };
38
39 // 23.3.5.1 constructors:
Howard Hinnant42b84842011-05-27 20:52:28 +000040 constexpr bitset() noexcept;
41 constexpr bitset(unsigned long long val) noexcept;
Howard Hinnant3a217732010-11-17 21:53:14 +000042 template <class charT>
43 explicit bitset(const charT* str,
44 typename basic_string<charT>::size_type n = basic_string<charT>::npos,
45 charT zero = charT('0'), charT one = charT('1'));
Howard Hinnantc51e1022010-05-11 19:42:16 +000046 template<class charT, class traits, class Allocator>
47 explicit bitset(const basic_string<charT,traits,Allocator>& str,
48 typename basic_string<charT,traits,Allocator>::size_type pos = 0,
49 typename basic_string<charT,traits,Allocator>::size_type n =
50 basic_string<charT,traits,Allocator>::npos,
51 charT zero = charT('0'), charT one = charT('1'));
52
53 // 23.3.5.2 bitset operations:
Howard Hinnant42b84842011-05-27 20:52:28 +000054 bitset& operator&=(const bitset& rhs) noexcept;
55 bitset& operator|=(const bitset& rhs) noexcept;
56 bitset& operator^=(const bitset& rhs) noexcept;
57 bitset& operator<<=(size_t pos) noexcept;
58 bitset& operator>>=(size_t pos) noexcept;
59 bitset& set() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000060 bitset& set(size_t pos, bool val = true);
Howard Hinnant42b84842011-05-27 20:52:28 +000061 bitset& reset() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000062 bitset& reset(size_t pos);
Howard Hinnant42b84842011-05-27 20:52:28 +000063 bitset operator~() const noexcept;
64 bitset& flip() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000065 bitset& flip(size_t pos);
66
67 // element access:
68 constexpr bool operator[](size_t pos) const; // for b[i];
69 reference operator[](size_t pos); // for b[i];
70 unsigned long to_ulong() const;
71 unsigned long long to_ullong() const;
72 template <class charT, class traits, class Allocator>
73 basic_string<charT, traits, Allocator> to_string(charT zero = charT('0'), charT one = charT('1')) const;
74 template <class charT, class traits>
75 basic_string<charT, traits, allocator<charT> > to_string(charT zero = charT('0'), charT one = charT('1')) const;
76 template <class charT>
77 basic_string<charT, char_traits<charT>, allocator<charT> > to_string(charT zero = charT('0'), charT one = charT('1')) const;
78 basic_string<char, char_traits<char>, allocator<char> > to_string(char zero = '0', char one = '1') const;
Howard Hinnant42b84842011-05-27 20:52:28 +000079 size_t count() const noexcept;
80 constexpr size_t size() const noexcept;
81 bool operator==(const bitset& rhs) const noexcept;
82 bool operator!=(const bitset& rhs) const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000083 bool test(size_t pos) const;
Howard Hinnant42b84842011-05-27 20:52:28 +000084 bool all() const noexcept;
85 bool any() const noexcept;
86 bool none() const noexcept;
87 bitset operator<<(size_t pos) const noexcept;
88 bitset operator>>(size_t pos) const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000089};
90
91// 23.3.5.3 bitset operators:
92template <size_t N>
Howard Hinnant42b84842011-05-27 20:52:28 +000093bitset<N> operator&(const bitset<N>&, const bitset<N>&) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000094
95template <size_t N>
Howard Hinnant42b84842011-05-27 20:52:28 +000096bitset<N> operator|(const bitset<N>&, const bitset<N>&) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000097
98template <size_t N>
Howard Hinnant42b84842011-05-27 20:52:28 +000099bitset<N> operator^(const bitset<N>&, const bitset<N>&) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000100
101template <class charT, class traits, size_t N>
102basic_istream<charT, traits>&
103operator>>(basic_istream<charT, traits>& is, bitset<N>& x);
104
105template <class charT, class traits, size_t N>
106basic_ostream<charT, traits>&
107operator<<(basic_ostream<charT, traits>& os, const bitset<N>& x);
108
109template <size_t N> struct hash<std::bitset<N>>;
110
111} // std
112
113*/
114
Howard Hinnantc51e1022010-05-11 19:42:16 +0000115#include <__config>
116#include <__bit_reference>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000117#include <__functional_base>
Arthur O'Dwyeref181602021-05-19 11:57:04 -0400118#include <climits>
119#include <cstddef>
120#include <iosfwd>
121#include <stdexcept>
122#include <string>
Mark de Weverce8f12c2021-12-22 18:14:14 +0100123#include <version>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000124
Eric Fiselierf4433a32017-05-31 22:07:49 +0000125#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
126#pragma GCC system_header
127#endif
128
129_LIBCPP_PUSH_MACROS
130#include <__undef_macros>
131
Howard Hinnantc5a5fbd2011-11-29 16:45:27 +0000132
Howard Hinnantc51e1022010-05-11 19:42:16 +0000133_LIBCPP_BEGIN_NAMESPACE_STD
134
135template <size_t _N_words, size_t _Size>
Howard Hinnantb4ef6482011-07-02 20:33:23 +0000136class __bitset;
137
138template <size_t _N_words, size_t _Size>
139struct __has_storage_type<__bitset<_N_words, _Size> >
140{
141 static const bool value = true;
142};
143
144template <size_t _N_words, size_t _Size>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000145class __bitset
146{
147public:
148 typedef ptrdiff_t difference_type;
149 typedef size_t size_type;
Howard Hinnant896b7622012-05-07 16:50:38 +0000150 typedef size_type __storage_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000151protected:
152 typedef __bitset __self;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000153 typedef __storage_type* __storage_pointer;
154 typedef const __storage_type* __const_storage_pointer;
155 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
156
157 friend class __bit_reference<__bitset>;
158 friend class __bit_const_reference<__bitset>;
159 friend class __bit_iterator<__bitset, false>;
160 friend class __bit_iterator<__bitset, true>;
Howard Hinnant4210a0f2012-08-17 17:10:18 +0000161 friend struct __bit_array<__bitset>;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000162
163 __storage_type __first_[_N_words];
164
165 typedef __bit_reference<__bitset> reference;
166 typedef __bit_const_reference<__bitset> const_reference;
167 typedef __bit_iterator<__bitset, false> iterator;
168 typedef __bit_iterator<__bitset, true> const_iterator;
169
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000170 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant49e96a62012-07-07 17:04:52 +0000171 _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000172 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant49e96a62012-07-07 17:04:52 +0000173 explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000174
Howard Hinnant42b84842011-05-27 20:52:28 +0000175 _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t __pos) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000176 {return reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
Howard Hinnant49e96a62012-07-07 17:04:52 +0000177 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000178 {return const_reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
Howard Hinnant42b84842011-05-27 20:52:28 +0000179 _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t __pos) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000180 {return iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
Howard Hinnant42b84842011-05-27 20:52:28 +0000181 _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000182 {return const_iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
183
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000184 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000185 void operator&=(const __bitset& __v) _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000186 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000187 void operator|=(const __bitset& __v) _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000188 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000189 void operator^=(const __bitset& __v) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000190
Howard Hinnant42b84842011-05-27 20:52:28 +0000191 void flip() _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000192 _LIBCPP_INLINE_VISIBILITY unsigned long to_ulong() const
193 {return to_ulong(integral_constant<bool, _Size < sizeof(unsigned long) * CHAR_BIT>());}
194 _LIBCPP_INLINE_VISIBILITY unsigned long long to_ullong() const
195 {return to_ullong(integral_constant<bool, _Size < sizeof(unsigned long long) * CHAR_BIT>());}
196
Howard Hinnant42b84842011-05-27 20:52:28 +0000197 bool all() const _NOEXCEPT;
198 bool any() const _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000199 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000200 size_t __hash_code() const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000201private:
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000202#ifdef _LIBCPP_CXX03_LANG
Howard Hinnant42b84842011-05-27 20:52:28 +0000203 void __init(unsigned long long __v, false_type) _NOEXCEPT;
Evgeniy Stepanov03192872015-12-09 22:32:36 +0000204 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000205 void __init(unsigned long long __v, true_type) _NOEXCEPT;
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400206#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000207 unsigned long to_ulong(false_type) const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000208 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000209 unsigned long to_ulong(true_type) const;
210 unsigned long long to_ullong(false_type) const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000211 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000212 unsigned long long to_ullong(true_type) const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000213 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000214 unsigned long long to_ullong(true_type, false_type) const;
215 unsigned long long to_ullong(true_type, true_type) const;
216};
217
218template <size_t _N_words, size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000219inline
Howard Hinnant49e96a62012-07-07 17:04:52 +0000220_LIBCPP_CONSTEXPR
Howard Hinnant42b84842011-05-27 20:52:28 +0000221__bitset<_N_words, _Size>::__bitset() _NOEXCEPT
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000222#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant49e96a62012-07-07 17:04:52 +0000223 : __first_{0}
224#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000225{
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000226#ifdef _LIBCPP_CXX03_LANG
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000227 _VSTD::fill_n(__first_, _N_words, __storage_type(0));
Howard Hinnant49e96a62012-07-07 17:04:52 +0000228#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000229}
230
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000231#ifdef _LIBCPP_CXX03_LANG
Howard Hinnant49e96a62012-07-07 17:04:52 +0000232
Howard Hinnantc51e1022010-05-11 19:42:16 +0000233template <size_t _N_words, size_t _Size>
234void
Howard Hinnant28b24882011-12-01 20:21:04 +0000235__bitset<_N_words, _Size>::__init(unsigned long long __v, false_type) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000236{
237 __storage_type __t[sizeof(unsigned long long) / sizeof(__storage_type)];
Marshall Clow10cfbcb2017-11-27 22:27:22 +0000238 size_t __sz = _Size;
239 for (size_t __i = 0; __i < sizeof(__t)/sizeof(__t[0]); ++__i, __v >>= __bits_per_word, __sz -= __bits_per_word )
240 if ( __sz < __bits_per_word)
Louis Dionne44bcff92018-08-03 22:36:53 +0000241 __t[__i] = static_cast<__storage_type>(__v) & ( 1ULL << __sz ) - 1;
Marshall Clow10cfbcb2017-11-27 22:27:22 +0000242 else
Louis Dionne44bcff92018-08-03 22:36:53 +0000243 __t[__i] = static_cast<__storage_type>(__v);
Marshall Clow10cfbcb2017-11-27 22:27:22 +0000244
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000245 _VSTD::copy(__t, __t + sizeof(__t)/sizeof(__t[0]), __first_);
246 _VSTD::fill(__first_ + sizeof(__t)/sizeof(__t[0]), __first_ + sizeof(__first_)/sizeof(__first_[0]),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000247 __storage_type(0));
248}
249
250template <size_t _N_words, size_t _Size>
251inline _LIBCPP_INLINE_VISIBILITY
252void
Howard Hinnant28b24882011-12-01 20:21:04 +0000253__bitset<_N_words, _Size>::__init(unsigned long long __v, true_type) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000254{
255 __first_[0] = __v;
Marshall Clow10cfbcb2017-11-27 22:27:22 +0000256 if (_Size < __bits_per_word)
Louis Dionne44bcff92018-08-03 22:36:53 +0000257 __first_[0] &= ( 1ULL << _Size ) - 1;
Marshall Clow10cfbcb2017-11-27 22:27:22 +0000258
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000259 _VSTD::fill(__first_ + 1, __first_ + sizeof(__first_)/sizeof(__first_[0]), __storage_type(0));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000260}
261
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400262#endif // _LIBCPP_CXX03_LANG
Howard Hinnant49e96a62012-07-07 17:04:52 +0000263
Howard Hinnantc51e1022010-05-11 19:42:16 +0000264template <size_t _N_words, size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000265inline
Howard Hinnant49e96a62012-07-07 17:04:52 +0000266_LIBCPP_CONSTEXPR
Howard Hinnant42b84842011-05-27 20:52:28 +0000267__bitset<_N_words, _Size>::__bitset(unsigned long long __v) _NOEXCEPT
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000268#ifndef _LIBCPP_CXX03_LANG
Nico Weberd04e4752014-06-04 15:46:56 +0000269#if __SIZEOF_SIZE_T__ == 8
Howard Hinnant49e96a62012-07-07 17:04:52 +0000270 : __first_{__v}
Nico Weberd04e4752014-06-04 15:46:56 +0000271#elif __SIZEOF_SIZE_T__ == 4
Louis Dionne44bcff92018-08-03 22:36:53 +0000272 : __first_{static_cast<__storage_type>(__v),
273 _Size >= 2 * __bits_per_word ? static_cast<__storage_type>(__v >> __bits_per_word)
274 : static_cast<__storage_type>((__v >> __bits_per_word) & (__storage_type(1) << (_Size - __bits_per_word)) - 1)}
Howard Hinnant96362822013-03-06 18:16:12 +0000275#else
Howard Hinnant55afb722013-03-06 17:30:26 +0000276#error This constructor has not been ported to this platform
277#endif
Howard Hinnant49e96a62012-07-07 17:04:52 +0000278#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000279{
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000280#ifdef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000281 __init(__v, integral_constant<bool, sizeof(unsigned long long) == sizeof(__storage_type)>());
Howard Hinnant49e96a62012-07-07 17:04:52 +0000282#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000283}
284
285template <size_t _N_words, size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000286inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000287void
Howard Hinnant42b84842011-05-27 20:52:28 +0000288__bitset<_N_words, _Size>::operator&=(const __bitset& __v) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000289{
290 for (size_type __i = 0; __i < _N_words; ++__i)
291 __first_[__i] &= __v.__first_[__i];
292}
293
294template <size_t _N_words, size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000295inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000296void
Howard Hinnant42b84842011-05-27 20:52:28 +0000297__bitset<_N_words, _Size>::operator|=(const __bitset& __v) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000298{
299 for (size_type __i = 0; __i < _N_words; ++__i)
300 __first_[__i] |= __v.__first_[__i];
301}
302
303template <size_t _N_words, size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000304inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000305void
Howard Hinnant42b84842011-05-27 20:52:28 +0000306__bitset<_N_words, _Size>::operator^=(const __bitset& __v) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000307{
308 for (size_type __i = 0; __i < _N_words; ++__i)
309 __first_[__i] ^= __v.__first_[__i];
310}
311
312template <size_t _N_words, size_t _Size>
313void
Howard Hinnant42b84842011-05-27 20:52:28 +0000314__bitset<_N_words, _Size>::flip() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000315{
316 // do middle whole words
317 size_type __n = _Size;
318 __storage_pointer __p = __first_;
319 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
320 *__p = ~*__p;
321 // do last partial word
322 if (__n > 0)
323 {
324 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
325 __storage_type __b = *__p & __m;
326 *__p &= ~__m;
327 *__p |= ~__b & __m;
328 }
329}
330
331template <size_t _N_words, size_t _Size>
332unsigned long
333__bitset<_N_words, _Size>::to_ulong(false_type) const
334{
335 const_iterator __e = __make_iter(_Size);
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000336 const_iterator __i = _VSTD::find(__make_iter(sizeof(unsigned long) * CHAR_BIT), __e, true);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000337 if (__i != __e)
Marshall Clow8fea1612016-08-25 15:09:01 +0000338 __throw_overflow_error("bitset to_ulong overflow error");
339
Howard Hinnantc51e1022010-05-11 19:42:16 +0000340 return __first_[0];
341}
342
343template <size_t _N_words, size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000344inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000345unsigned long
346__bitset<_N_words, _Size>::to_ulong(true_type) const
347{
348 return __first_[0];
349}
350
351template <size_t _N_words, size_t _Size>
352unsigned long long
353__bitset<_N_words, _Size>::to_ullong(false_type) const
354{
355 const_iterator __e = __make_iter(_Size);
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000356 const_iterator __i = _VSTD::find(__make_iter(sizeof(unsigned long long) * CHAR_BIT), __e, true);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000357 if (__i != __e)
Marshall Clow8fea1612016-08-25 15:09:01 +0000358 __throw_overflow_error("bitset to_ullong overflow error");
359
Howard Hinnantc51e1022010-05-11 19:42:16 +0000360 return to_ullong(true_type());
361}
362
363template <size_t _N_words, size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000364inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000365unsigned long long
366__bitset<_N_words, _Size>::to_ullong(true_type) const
367{
368 return to_ullong(true_type(), integral_constant<bool, sizeof(__storage_type) < sizeof(unsigned long long)>());
369}
370
371template <size_t _N_words, size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000372inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000373unsigned long long
374__bitset<_N_words, _Size>::to_ullong(true_type, false_type) const
375{
376 return __first_[0];
377}
378
379template <size_t _N_words, size_t _Size>
380unsigned long long
381__bitset<_N_words, _Size>::to_ullong(true_type, true_type) const
382{
383 unsigned long long __r = __first_[0];
Arthur O'Dwyer07b22492020-11-27 11:02:06 -0500384 for (size_t __i = 1; __i < sizeof(unsigned long long) / sizeof(__storage_type); ++__i)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000385 __r |= static_cast<unsigned long long>(__first_[__i]) << (sizeof(__storage_type) * CHAR_BIT);
386 return __r;
387}
388
389template <size_t _N_words, size_t _Size>
390bool
Howard Hinnant42b84842011-05-27 20:52:28 +0000391__bitset<_N_words, _Size>::all() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000392{
393 // do middle whole words
394 size_type __n = _Size;
395 __const_storage_pointer __p = __first_;
396 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
397 if (~*__p)
398 return false;
399 // do last partial word
400 if (__n > 0)
401 {
402 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
403 if (~*__p & __m)
404 return false;
405 }
406 return true;
407}
408
409template <size_t _N_words, size_t _Size>
410bool
Howard Hinnant42b84842011-05-27 20:52:28 +0000411__bitset<_N_words, _Size>::any() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000412{
413 // do middle whole words
414 size_type __n = _Size;
415 __const_storage_pointer __p = __first_;
416 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
417 if (*__p)
418 return true;
419 // do last partial word
420 if (__n > 0)
421 {
422 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
423 if (*__p & __m)
424 return true;
425 }
426 return false;
427}
428
429template <size_t _N_words, size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000430inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000431size_t
Howard Hinnant42b84842011-05-27 20:52:28 +0000432__bitset<_N_words, _Size>::__hash_code() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000433{
434 size_t __h = 0;
435 for (size_type __i = 0; __i < _N_words; ++__i)
436 __h ^= __first_[__i];
437 return __h;
438}
439
440template <size_t _Size>
441class __bitset<1, _Size>
442{
443public:
444 typedef ptrdiff_t difference_type;
445 typedef size_t size_type;
Howard Hinnant896b7622012-05-07 16:50:38 +0000446 typedef size_type __storage_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000447protected:
448 typedef __bitset __self;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000449 typedef __storage_type* __storage_pointer;
450 typedef const __storage_type* __const_storage_pointer;
451 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
452
453 friend class __bit_reference<__bitset>;
454 friend class __bit_const_reference<__bitset>;
455 friend class __bit_iterator<__bitset, false>;
456 friend class __bit_iterator<__bitset, true>;
Howard Hinnant4210a0f2012-08-17 17:10:18 +0000457 friend struct __bit_array<__bitset>;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000458
459 __storage_type __first_;
460
461 typedef __bit_reference<__bitset> reference;
462 typedef __bit_const_reference<__bitset> const_reference;
463 typedef __bit_iterator<__bitset, false> iterator;
464 typedef __bit_iterator<__bitset, true> const_iterator;
465
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000466 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant49e96a62012-07-07 17:04:52 +0000467 _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000468 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant49e96a62012-07-07 17:04:52 +0000469 explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000470
Howard Hinnant42b84842011-05-27 20:52:28 +0000471 _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t __pos) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000472 {return reference(&__first_, __storage_type(1) << __pos);}
Howard Hinnant49e96a62012-07-07 17:04:52 +0000473 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000474 {return const_reference(&__first_, __storage_type(1) << __pos);}
Howard Hinnant42b84842011-05-27 20:52:28 +0000475 _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t __pos) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000476 {return iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
Howard Hinnant42b84842011-05-27 20:52:28 +0000477 _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000478 {return const_iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
479
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000480 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000481 void operator&=(const __bitset& __v) _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000482 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000483 void operator|=(const __bitset& __v) _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000484 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000485 void operator^=(const __bitset& __v) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000486
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000487 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000488 void flip() _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000489
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000490 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000491 unsigned long to_ulong() const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000492 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000493 unsigned long long to_ullong() const;
494
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000495 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000496 bool all() const _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000497 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000498 bool any() const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000499
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000500 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000501 size_t __hash_code() const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000502};
503
504template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000505inline
Howard Hinnant49e96a62012-07-07 17:04:52 +0000506_LIBCPP_CONSTEXPR
Howard Hinnant42b84842011-05-27 20:52:28 +0000507__bitset<1, _Size>::__bitset() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000508 : __first_(0)
509{
510}
511
512template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000513inline
Howard Hinnant49e96a62012-07-07 17:04:52 +0000514_LIBCPP_CONSTEXPR
Howard Hinnant42b84842011-05-27 20:52:28 +0000515__bitset<1, _Size>::__bitset(unsigned long long __v) _NOEXCEPT
Marshall Clow7170bf62017-11-27 19:03:30 +0000516 : __first_(
517 _Size == __bits_per_word ? static_cast<__storage_type>(__v)
518 : static_cast<__storage_type>(__v) & ((__storage_type(1) << _Size) - 1)
519 )
Howard Hinnantc51e1022010-05-11 19:42:16 +0000520{
521}
522
523template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000524inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000525void
Howard Hinnant42b84842011-05-27 20:52:28 +0000526__bitset<1, _Size>::operator&=(const __bitset& __v) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000527{
528 __first_ &= __v.__first_;
529}
530
531template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000532inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000533void
Howard Hinnant42b84842011-05-27 20:52:28 +0000534__bitset<1, _Size>::operator|=(const __bitset& __v) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000535{
536 __first_ |= __v.__first_;
537}
538
539template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000540inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000541void
Howard Hinnant42b84842011-05-27 20:52:28 +0000542__bitset<1, _Size>::operator^=(const __bitset& __v) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000543{
544 __first_ ^= __v.__first_;
545}
546
547template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000548inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000549void
Howard Hinnant42b84842011-05-27 20:52:28 +0000550__bitset<1, _Size>::flip() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000551{
552 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
553 __first_ = ~__first_;
554 __first_ &= __m;
555}
556
557template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000558inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000559unsigned long
560__bitset<1, _Size>::to_ulong() const
561{
562 return __first_;
563}
564
565template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000566inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000567unsigned long long
568__bitset<1, _Size>::to_ullong() const
569{
570 return __first_;
571}
572
573template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000574inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000575bool
Howard Hinnant42b84842011-05-27 20:52:28 +0000576__bitset<1, _Size>::all() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000577{
578 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
579 return !(~__first_ & __m);
580}
581
582template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000583inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000584bool
Howard Hinnant42b84842011-05-27 20:52:28 +0000585__bitset<1, _Size>::any() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000586{
587 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
588 return __first_ & __m;
589}
590
591template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000592inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000593size_t
Howard Hinnant42b84842011-05-27 20:52:28 +0000594__bitset<1, _Size>::__hash_code() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000595{
596 return __first_;
597}
598
599template <>
600class __bitset<0, 0>
601{
602public:
603 typedef ptrdiff_t difference_type;
604 typedef size_t size_type;
Howard Hinnant896b7622012-05-07 16:50:38 +0000605 typedef size_type __storage_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000606protected:
607 typedef __bitset __self;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000608 typedef __storage_type* __storage_pointer;
609 typedef const __storage_type* __const_storage_pointer;
610 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
611
612 friend class __bit_reference<__bitset>;
613 friend class __bit_const_reference<__bitset>;
614 friend class __bit_iterator<__bitset, false>;
615 friend class __bit_iterator<__bitset, true>;
Howard Hinnant28b24882011-12-01 20:21:04 +0000616 friend struct __bit_array<__bitset>;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000617
618 typedef __bit_reference<__bitset> reference;
619 typedef __bit_const_reference<__bitset> const_reference;
620 typedef __bit_iterator<__bitset, false> iterator;
621 typedef __bit_iterator<__bitset, true> const_iterator;
622
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000623 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant49e96a62012-07-07 17:04:52 +0000624 _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000625 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant49e96a62012-07-07 17:04:52 +0000626 explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000627
Howard Hinnant42b84842011-05-27 20:52:28 +0000628 _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t) _NOEXCEPT
Bruce Mitchener170d8972020-11-24 12:53:53 -0500629 {return reference(nullptr, 1);}
Howard Hinnant49e96a62012-07-07 17:04:52 +0000630 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t) const _NOEXCEPT
Bruce Mitchener170d8972020-11-24 12:53:53 -0500631 {return const_reference(nullptr, 1);}
Howard Hinnant28b24882011-12-01 20:21:04 +0000632 _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t) _NOEXCEPT
Bruce Mitchener170d8972020-11-24 12:53:53 -0500633 {return iterator(nullptr, 0);}
Howard Hinnant28b24882011-12-01 20:21:04 +0000634 _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t) const _NOEXCEPT
Bruce Mitchener170d8972020-11-24 12:53:53 -0500635 {return const_iterator(nullptr, 0);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000636
Howard Hinnant42b84842011-05-27 20:52:28 +0000637 _LIBCPP_INLINE_VISIBILITY void operator&=(const __bitset&) _NOEXCEPT {}
638 _LIBCPP_INLINE_VISIBILITY void operator|=(const __bitset&) _NOEXCEPT {}
639 _LIBCPP_INLINE_VISIBILITY void operator^=(const __bitset&) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000640
Howard Hinnant42b84842011-05-27 20:52:28 +0000641 _LIBCPP_INLINE_VISIBILITY void flip() _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000642
643 _LIBCPP_INLINE_VISIBILITY unsigned long to_ulong() const {return 0;}
644 _LIBCPP_INLINE_VISIBILITY unsigned long long to_ullong() const {return 0;}
645
Howard Hinnant42b84842011-05-27 20:52:28 +0000646 _LIBCPP_INLINE_VISIBILITY bool all() const _NOEXCEPT {return true;}
647 _LIBCPP_INLINE_VISIBILITY bool any() const _NOEXCEPT {return false;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000648
Howard Hinnant42b84842011-05-27 20:52:28 +0000649 _LIBCPP_INLINE_VISIBILITY size_t __hash_code() const _NOEXCEPT {return 0;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000650};
651
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000652inline
Howard Hinnant49e96a62012-07-07 17:04:52 +0000653_LIBCPP_CONSTEXPR
Howard Hinnant42b84842011-05-27 20:52:28 +0000654__bitset<0, 0>::__bitset() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000655{
656}
657
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000658inline
Howard Hinnant49e96a62012-07-07 17:04:52 +0000659_LIBCPP_CONSTEXPR
Howard Hinnant42b84842011-05-27 20:52:28 +0000660__bitset<0, 0>::__bitset(unsigned long long) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000661{
662}
663
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000664template <size_t _Size> class _LIBCPP_TEMPLATE_VIS bitset;
Eric Fiselier6585c752016-04-21 22:54:21 +0000665template <size_t _Size> struct hash<bitset<_Size> >;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000666
667template <size_t _Size>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000668class _LIBCPP_TEMPLATE_VIS bitset
Howard Hinnantc51e1022010-05-11 19:42:16 +0000669 : private __bitset<_Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1, _Size>
670{
Howard Hinnant55afb722013-03-06 17:30:26 +0000671public:
Howard Hinnantc51e1022010-05-11 19:42:16 +0000672 static const unsigned __n_words = _Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1;
673 typedef __bitset<__n_words, _Size> base;
674
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000675public:
Howard Hinnantc51e1022010-05-11 19:42:16 +0000676 typedef typename base::reference reference;
677 typedef typename base::const_reference const_reference;
678
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000679 // 23.3.5.1 constructors:
Howard Hinnant49e96a62012-07-07 17:04:52 +0000680 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bitset() _NOEXCEPT {}
681 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
682 bitset(unsigned long long __v) _NOEXCEPT : base(__v) {}
Louis Dionne9ce598d2021-09-08 09:14:43 -0400683 template<class _CharT, class = __enable_if_t<_IsCharLikeType<_CharT>::value> >
Howard Hinnant3a217732010-11-17 21:53:14 +0000684 explicit bitset(const _CharT* __str,
685 typename basic_string<_CharT>::size_type __n = basic_string<_CharT>::npos,
686 _CharT __zero = _CharT('0'), _CharT __one = _CharT('1'));
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000687 template<class _CharT, class _Traits, class _Allocator>
688 explicit bitset(const basic_string<_CharT,_Traits,_Allocator>& __str,
689 typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos = 0,
690 typename basic_string<_CharT,_Traits,_Allocator>::size_type __n =
Howard Hinnantc51e1022010-05-11 19:42:16 +0000691 (basic_string<_CharT,_Traits,_Allocator>::npos),
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000692 _CharT __zero = _CharT('0'), _CharT __one = _CharT('1'));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000693
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000694 // 23.3.5.2 bitset operations:
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000695 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000696 bitset& operator&=(const bitset& __rhs) _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000697 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000698 bitset& operator|=(const bitset& __rhs) _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000699 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000700 bitset& operator^=(const bitset& __rhs) _NOEXCEPT;
701 bitset& operator<<=(size_t __pos) _NOEXCEPT;
702 bitset& operator>>=(size_t __pos) _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000703 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000704 bitset& set() _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000705 bitset& set(size_t __pos, bool __val = true);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000706 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000707 bitset& reset() _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000708 bitset& reset(size_t __pos);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000709 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000710 bitset operator~() const _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000711 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000712 bitset& flip() _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000713 bitset& flip(size_t __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000714
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000715 // element access:
Howard Hinnant49e96a62012-07-07 17:04:52 +0000716 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
717 const_reference operator[](size_t __p) const {return base::__make_ref(__p);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000718 _LIBCPP_INLINE_VISIBILITY reference operator[](size_t __p) {return base::__make_ref(__p);}
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000719 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000720 unsigned long to_ulong() const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000721 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000722 unsigned long long to_ullong() const;
723 template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000724 basic_string<_CharT, _Traits, _Allocator> to_string(_CharT __zero = _CharT('0'),
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000725 _CharT __one = _CharT('1')) const;
726 template <class _CharT, class _Traits>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000727 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000728 basic_string<_CharT, _Traits, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'),
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000729 _CharT __one = _CharT('1')) const;
730 template <class _CharT>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000731 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000732 basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'),
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000733 _CharT __one = _CharT('1')) const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000734 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000735 basic_string<char, char_traits<char>, allocator<char> > to_string(char __zero = '0',
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000736 char __one = '1') const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000737 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000738 size_t count() const _NOEXCEPT;
Howard Hinnant49e96a62012-07-07 17:04:52 +0000739 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR size_t size() const _NOEXCEPT {return _Size;}
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000740 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000741 bool operator==(const bitset& __rhs) const _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000742 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000743 bool operator!=(const bitset& __rhs) const _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000744 bool test(size_t __pos) const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000745 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000746 bool all() const _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000747 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000748 bool any() const _NOEXCEPT;
749 _LIBCPP_INLINE_VISIBILITY bool none() const _NOEXCEPT {return !any();}
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000750 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000751 bitset operator<<(size_t __pos) const _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000752 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000753 bitset operator>>(size_t __pos) const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000754
755private:
756
Howard Hinnant874ad9a2010-09-21 21:28:23 +0000757 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000758 size_t __hash_code() const _NOEXCEPT {return base::__hash_code();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000759
760 friend struct hash<bitset>;
761};
762
763template <size_t _Size>
Eric Fiselier7281d5e2019-07-01 19:59:34 +0000764template<class _CharT, class>
Howard Hinnant3a217732010-11-17 21:53:14 +0000765bitset<_Size>::bitset(const _CharT* __str,
766 typename basic_string<_CharT>::size_type __n,
767 _CharT __zero, _CharT __one)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000768{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000769 size_t __rlen = _VSTD::min(__n, char_traits<_CharT>::length(__str));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000770 for (size_t __i = 0; __i < __rlen; ++__i)
Howard Hinnant3a217732010-11-17 21:53:14 +0000771 if (__str[__i] != __zero && __str[__i] != __one)
Marshall Clow8fea1612016-08-25 15:09:01 +0000772 __throw_invalid_argument("bitset string ctor has invalid argument");
773
Howard Hinnantc834c512011-11-29 18:15:50 +0000774 size_t _Mp = _VSTD::min(__rlen, _Size);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000775 size_t __i = 0;
Howard Hinnantc834c512011-11-29 18:15:50 +0000776 for (; __i < _Mp; ++__i)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000777 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000778 _CharT __c = __str[_Mp - 1 - __i];
Shu Tian023b3482021-04-24 16:08:55 +0200779 (*this)[__i] = (__c == __one);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000780 }
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000781 _VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000782}
783
784template <size_t _Size>
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000785template<class _CharT, class _Traits, class _Allocator>
786bitset<_Size>::bitset(const basic_string<_CharT,_Traits,_Allocator>& __str,
787 typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000788 typename basic_string<_CharT,_Traits,_Allocator>::size_type __n,
789 _CharT __zero, _CharT __one)
790{
791 if (__pos > __str.size())
Marshall Clow8fea1612016-08-25 15:09:01 +0000792 __throw_out_of_range("bitset string pos out of range");
793
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000794 size_t __rlen = _VSTD::min(__n, __str.size() - __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000795 for (size_t __i = __pos; __i < __pos + __rlen; ++__i)
796 if (!_Traits::eq(__str[__i], __zero) && !_Traits::eq(__str[__i], __one))
Marshall Clow8fea1612016-08-25 15:09:01 +0000797 __throw_invalid_argument("bitset string ctor has invalid argument");
798
Howard Hinnantc834c512011-11-29 18:15:50 +0000799 size_t _Mp = _VSTD::min(__rlen, _Size);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000800 size_t __i = 0;
Howard Hinnantc834c512011-11-29 18:15:50 +0000801 for (; __i < _Mp; ++__i)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000802 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000803 _CharT __c = __str[__pos + _Mp - 1 - __i];
Shu Tian023b3482021-04-24 16:08:55 +0200804 (*this)[__i] = _Traits::eq(__c, __one);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000805 }
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000806 _VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000807}
808
809template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000810inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000811bitset<_Size>&
Howard Hinnant42b84842011-05-27 20:52:28 +0000812bitset<_Size>::operator&=(const bitset& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000813{
814 base::operator&=(__rhs);
815 return *this;
816}
817
818template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000819inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000820bitset<_Size>&
Howard Hinnant42b84842011-05-27 20:52:28 +0000821bitset<_Size>::operator|=(const bitset& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000822{
823 base::operator|=(__rhs);
824 return *this;
825}
826
827template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000828inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000829bitset<_Size>&
Howard Hinnant42b84842011-05-27 20:52:28 +0000830bitset<_Size>::operator^=(const bitset& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000831{
832 base::operator^=(__rhs);
833 return *this;
834}
835
836template <size_t _Size>
837bitset<_Size>&
Howard Hinnant42b84842011-05-27 20:52:28 +0000838bitset<_Size>::operator<<=(size_t __pos) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000839{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000840 __pos = _VSTD::min(__pos, _Size);
841 _VSTD::copy_backward(base::__make_iter(0), base::__make_iter(_Size - __pos), base::__make_iter(_Size));
842 _VSTD::fill_n(base::__make_iter(0), __pos, false);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000843 return *this;
844}
845
846template <size_t _Size>
847bitset<_Size>&
Howard Hinnant42b84842011-05-27 20:52:28 +0000848bitset<_Size>::operator>>=(size_t __pos) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000849{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000850 __pos = _VSTD::min(__pos, _Size);
851 _VSTD::copy(base::__make_iter(__pos), base::__make_iter(_Size), base::__make_iter(0));
852 _VSTD::fill_n(base::__make_iter(_Size - __pos), __pos, false);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000853 return *this;
854}
855
856template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000857inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000858bitset<_Size>&
Howard Hinnant42b84842011-05-27 20:52:28 +0000859bitset<_Size>::set() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000860{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000861 _VSTD::fill_n(base::__make_iter(0), _Size, true);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000862 return *this;
863}
864
865template <size_t _Size>
866bitset<_Size>&
867bitset<_Size>::set(size_t __pos, bool __val)
868{
869 if (__pos >= _Size)
Marshall Clow8fea1612016-08-25 15:09:01 +0000870 __throw_out_of_range("bitset set argument out of range");
871
Howard Hinnantc51e1022010-05-11 19:42:16 +0000872 (*this)[__pos] = __val;
873 return *this;
874}
875
876template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000877inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000878bitset<_Size>&
Howard Hinnant42b84842011-05-27 20:52:28 +0000879bitset<_Size>::reset() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000880{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000881 _VSTD::fill_n(base::__make_iter(0), _Size, false);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000882 return *this;
883}
884
885template <size_t _Size>
886bitset<_Size>&
887bitset<_Size>::reset(size_t __pos)
888{
889 if (__pos >= _Size)
Marshall Clow8fea1612016-08-25 15:09:01 +0000890 __throw_out_of_range("bitset reset argument out of range");
891
Howard Hinnantc51e1022010-05-11 19:42:16 +0000892 (*this)[__pos] = false;
893 return *this;
894}
895
896template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000897inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000898bitset<_Size>
Howard Hinnant42b84842011-05-27 20:52:28 +0000899bitset<_Size>::operator~() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000900{
901 bitset __x(*this);
902 __x.flip();
903 return __x;
904}
905
906template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000907inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000908bitset<_Size>&
Howard Hinnant42b84842011-05-27 20:52:28 +0000909bitset<_Size>::flip() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000910{
911 base::flip();
912 return *this;
913}
914
915template <size_t _Size>
916bitset<_Size>&
917bitset<_Size>::flip(size_t __pos)
918{
919 if (__pos >= _Size)
Marshall Clow8fea1612016-08-25 15:09:01 +0000920 __throw_out_of_range("bitset flip argument out of range");
921
Howard Hinnantc51e1022010-05-11 19:42:16 +0000922 reference r = base::__make_ref(__pos);
923 r = ~r;
924 return *this;
925}
926
927template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000928inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000929unsigned long
930bitset<_Size>::to_ulong() const
931{
932 return base::to_ulong();
933}
934
935template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000936inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000937unsigned long long
938bitset<_Size>::to_ullong() const
939{
940 return base::to_ullong();
941}
942
943template <size_t _Size>
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000944template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000945basic_string<_CharT, _Traits, _Allocator>
946bitset<_Size>::to_string(_CharT __zero, _CharT __one) const
947{
948 basic_string<_CharT, _Traits, _Allocator> __r(_Size, __zero);
949 for (size_t __i = 0; __i < _Size; ++__i)
950 {
951 if ((*this)[__i])
952 __r[_Size - 1 - __i] = __one;
953 }
954 return __r;
955}
956
957template <size_t _Size>
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000958template <class _CharT, class _Traits>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000959inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000960basic_string<_CharT, _Traits, allocator<_CharT> >
961bitset<_Size>::to_string(_CharT __zero, _CharT __one) const
962{
963 return to_string<_CharT, _Traits, allocator<_CharT> >(__zero, __one);
964}
965
966template <size_t _Size>
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000967template <class _CharT>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000968inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000969basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> >
970bitset<_Size>::to_string(_CharT __zero, _CharT __one) const
971{
972 return to_string<_CharT, char_traits<_CharT>, allocator<_CharT> >(__zero, __one);
973}
974
975template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000976inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000977basic_string<char, char_traits<char>, allocator<char> >
978bitset<_Size>::to_string(char __zero, char __one) const
979{
980 return to_string<char, char_traits<char>, allocator<char> >(__zero, __one);
981}
982
983template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000984inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000985size_t
Howard Hinnant42b84842011-05-27 20:52:28 +0000986bitset<_Size>::count() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000987{
Arthur O'Dwyer34465da2020-12-15 19:32:29 -0500988 return static_cast<size_t>(_VSTD::__count_bool_true(base::__make_iter(0), _Size));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000989}
990
991template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000992inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000993bool
Howard Hinnant42b84842011-05-27 20:52:28 +0000994bitset<_Size>::operator==(const bitset& __rhs) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000995{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000996 return _VSTD::equal(base::__make_iter(0), base::__make_iter(_Size), __rhs.__make_iter(0));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000997}
998
999template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001000inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001001bool
Howard Hinnant42b84842011-05-27 20:52:28 +00001002bitset<_Size>::operator!=(const bitset& __rhs) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001003{
1004 return !(*this == __rhs);
1005}
1006
1007template <size_t _Size>
1008bool
1009bitset<_Size>::test(size_t __pos) const
1010{
1011 if (__pos >= _Size)
Marshall Clow8fea1612016-08-25 15:09:01 +00001012 __throw_out_of_range("bitset test argument out of range");
1013
Howard Hinnantc51e1022010-05-11 19:42:16 +00001014 return (*this)[__pos];
1015}
1016
1017template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001018inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001019bool
Howard Hinnant42b84842011-05-27 20:52:28 +00001020bitset<_Size>::all() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001021{
1022 return base::all();
1023}
1024
1025template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001026inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001027bool
Howard Hinnant42b84842011-05-27 20:52:28 +00001028bitset<_Size>::any() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001029{
1030 return base::any();
1031}
1032
1033template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001034inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001035bitset<_Size>
Howard Hinnant42b84842011-05-27 20:52:28 +00001036bitset<_Size>::operator<<(size_t __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001037{
1038 bitset __r = *this;
1039 __r <<= __pos;
1040 return __r;
1041}
1042
1043template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001044inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001045bitset<_Size>
Howard Hinnant42b84842011-05-27 20:52:28 +00001046bitset<_Size>::operator>>(size_t __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001047{
1048 bitset __r = *this;
1049 __r >>= __pos;
1050 return __r;
1051}
1052
1053template <size_t _Size>
1054inline _LIBCPP_INLINE_VISIBILITY
1055bitset<_Size>
Howard Hinnant42b84842011-05-27 20:52:28 +00001056operator&(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001057{
1058 bitset<_Size> __r = __x;
1059 __r &= __y;
1060 return __r;
1061}
1062
1063template <size_t _Size>
1064inline _LIBCPP_INLINE_VISIBILITY
1065bitset<_Size>
Howard Hinnant42b84842011-05-27 20:52:28 +00001066operator|(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001067{
1068 bitset<_Size> __r = __x;
1069 __r |= __y;
1070 return __r;
1071}
1072
1073template <size_t _Size>
1074inline _LIBCPP_INLINE_VISIBILITY
1075bitset<_Size>
Howard Hinnant42b84842011-05-27 20:52:28 +00001076operator^(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001077{
1078 bitset<_Size> __r = __x;
1079 __r ^= __y;
1080 return __r;
1081}
1082
1083template <size_t _Size>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001084struct _LIBCPP_TEMPLATE_VIS hash<bitset<_Size> >
Howard Hinnantc51e1022010-05-11 19:42:16 +00001085 : public unary_function<bitset<_Size>, size_t>
1086{
Howard Hinnant874ad9a2010-09-21 21:28:23 +00001087 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +00001088 size_t operator()(const bitset<_Size>& __bs) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001089 {return __bs.__hash_code();}
1090};
1091
Howard Hinnantdc095972011-07-18 15:51:59 +00001092template <class _CharT, class _Traits, size_t _Size>
1093basic_istream<_CharT, _Traits>&
1094operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x);
1095
1096template <class _CharT, class _Traits, size_t _Size>
1097basic_ostream<_CharT, _Traits>&
1098operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x);
1099
Howard Hinnantc51e1022010-05-11 19:42:16 +00001100_LIBCPP_END_NAMESPACE_STD
1101
Eric Fiselierf4433a32017-05-31 22:07:49 +00001102_LIBCPP_POP_MACROS
1103
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001104#endif // _LIBCPP_BITSET