blob: 4b8827e774a34d633c185d78f8499d40905ddacf [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===---------------------------- bitset ----------------------------------===//
3//
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>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000123
Eric Fiselierf4433a32017-05-31 22:07:49 +0000124#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
125#pragma GCC system_header
126#endif
127
128_LIBCPP_PUSH_MACROS
129#include <__undef_macros>
130
Howard Hinnantc5a5fbd2011-11-29 16:45:27 +0000131
Howard Hinnantc51e1022010-05-11 19:42:16 +0000132_LIBCPP_BEGIN_NAMESPACE_STD
133
134template <size_t _N_words, size_t _Size>
Howard Hinnantb4ef6482011-07-02 20:33:23 +0000135class __bitset;
136
137template <size_t _N_words, size_t _Size>
138struct __has_storage_type<__bitset<_N_words, _Size> >
139{
140 static const bool value = true;
141};
142
143template <size_t _N_words, size_t _Size>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000144class __bitset
145{
146public:
147 typedef ptrdiff_t difference_type;
148 typedef size_t size_type;
Howard Hinnant896b7622012-05-07 16:50:38 +0000149 typedef size_type __storage_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000150protected:
151 typedef __bitset __self;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000152 typedef __storage_type* __storage_pointer;
153 typedef const __storage_type* __const_storage_pointer;
154 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
155
156 friend class __bit_reference<__bitset>;
157 friend class __bit_const_reference<__bitset>;
158 friend class __bit_iterator<__bitset, false>;
159 friend class __bit_iterator<__bitset, true>;
Howard Hinnant4210a0f2012-08-17 17:10:18 +0000160 friend struct __bit_array<__bitset>;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000161
162 __storage_type __first_[_N_words];
163
164 typedef __bit_reference<__bitset> reference;
165 typedef __bit_const_reference<__bitset> const_reference;
166 typedef __bit_iterator<__bitset, false> iterator;
167 typedef __bit_iterator<__bitset, true> const_iterator;
168
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000169 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant49e96a62012-07-07 17:04:52 +0000170 _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000171 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant49e96a62012-07-07 17:04:52 +0000172 explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000173
Howard Hinnant42b84842011-05-27 20:52:28 +0000174 _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t __pos) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000175 {return reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
Howard Hinnant49e96a62012-07-07 17:04:52 +0000176 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000177 {return const_reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
Howard Hinnant42b84842011-05-27 20:52:28 +0000178 _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t __pos) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000179 {return iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
Howard Hinnant42b84842011-05-27 20:52:28 +0000180 _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000181 {return const_iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
182
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000183 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000184 void operator&=(const __bitset& __v) _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000185 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000186 void operator|=(const __bitset& __v) _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000187 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000188 void operator^=(const __bitset& __v) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000189
Howard Hinnant42b84842011-05-27 20:52:28 +0000190 void flip() _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000191 _LIBCPP_INLINE_VISIBILITY unsigned long to_ulong() const
192 {return to_ulong(integral_constant<bool, _Size < sizeof(unsigned long) * CHAR_BIT>());}
193 _LIBCPP_INLINE_VISIBILITY unsigned long long to_ullong() const
194 {return to_ullong(integral_constant<bool, _Size < sizeof(unsigned long long) * CHAR_BIT>());}
195
Howard Hinnant42b84842011-05-27 20:52:28 +0000196 bool all() const _NOEXCEPT;
197 bool any() const _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000198 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000199 size_t __hash_code() const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000200private:
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000201#ifdef _LIBCPP_CXX03_LANG
Howard Hinnant42b84842011-05-27 20:52:28 +0000202 void __init(unsigned long long __v, false_type) _NOEXCEPT;
Evgeniy Stepanov03192872015-12-09 22:32:36 +0000203 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000204 void __init(unsigned long long __v, true_type) _NOEXCEPT;
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400205#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000206 unsigned long to_ulong(false_type) const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000207 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000208 unsigned long to_ulong(true_type) const;
209 unsigned long long to_ullong(false_type) const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000210 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000211 unsigned long long to_ullong(true_type) const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000212 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000213 unsigned long long to_ullong(true_type, false_type) const;
214 unsigned long long to_ullong(true_type, true_type) const;
215};
216
217template <size_t _N_words, size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000218inline
Howard Hinnant49e96a62012-07-07 17:04:52 +0000219_LIBCPP_CONSTEXPR
Howard Hinnant42b84842011-05-27 20:52:28 +0000220__bitset<_N_words, _Size>::__bitset() _NOEXCEPT
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000221#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant49e96a62012-07-07 17:04:52 +0000222 : __first_{0}
223#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000224{
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000225#ifdef _LIBCPP_CXX03_LANG
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000226 _VSTD::fill_n(__first_, _N_words, __storage_type(0));
Howard Hinnant49e96a62012-07-07 17:04:52 +0000227#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000228}
229
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000230#ifdef _LIBCPP_CXX03_LANG
Howard Hinnant49e96a62012-07-07 17:04:52 +0000231
Howard Hinnantc51e1022010-05-11 19:42:16 +0000232template <size_t _N_words, size_t _Size>
233void
Howard Hinnant28b24882011-12-01 20:21:04 +0000234__bitset<_N_words, _Size>::__init(unsigned long long __v, false_type) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000235{
236 __storage_type __t[sizeof(unsigned long long) / sizeof(__storage_type)];
Marshall Clow10cfbcb2017-11-27 22:27:22 +0000237 size_t __sz = _Size;
238 for (size_t __i = 0; __i < sizeof(__t)/sizeof(__t[0]); ++__i, __v >>= __bits_per_word, __sz -= __bits_per_word )
239 if ( __sz < __bits_per_word)
Louis Dionne44bcff92018-08-03 22:36:53 +0000240 __t[__i] = static_cast<__storage_type>(__v) & ( 1ULL << __sz ) - 1;
Marshall Clow10cfbcb2017-11-27 22:27:22 +0000241 else
Louis Dionne44bcff92018-08-03 22:36:53 +0000242 __t[__i] = static_cast<__storage_type>(__v);
Marshall Clow10cfbcb2017-11-27 22:27:22 +0000243
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000244 _VSTD::copy(__t, __t + sizeof(__t)/sizeof(__t[0]), __first_);
245 _VSTD::fill(__first_ + sizeof(__t)/sizeof(__t[0]), __first_ + sizeof(__first_)/sizeof(__first_[0]),
Howard Hinnantc51e1022010-05-11 19:42:16 +0000246 __storage_type(0));
247}
248
249template <size_t _N_words, size_t _Size>
250inline _LIBCPP_INLINE_VISIBILITY
251void
Howard Hinnant28b24882011-12-01 20:21:04 +0000252__bitset<_N_words, _Size>::__init(unsigned long long __v, true_type) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000253{
254 __first_[0] = __v;
Marshall Clow10cfbcb2017-11-27 22:27:22 +0000255 if (_Size < __bits_per_word)
Louis Dionne44bcff92018-08-03 22:36:53 +0000256 __first_[0] &= ( 1ULL << _Size ) - 1;
Marshall Clow10cfbcb2017-11-27 22:27:22 +0000257
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000258 _VSTD::fill(__first_ + 1, __first_ + sizeof(__first_)/sizeof(__first_[0]), __storage_type(0));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000259}
260
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400261#endif // _LIBCPP_CXX03_LANG
Howard Hinnant49e96a62012-07-07 17:04:52 +0000262
Howard Hinnantc51e1022010-05-11 19:42:16 +0000263template <size_t _N_words, size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000264inline
Howard Hinnant49e96a62012-07-07 17:04:52 +0000265_LIBCPP_CONSTEXPR
Howard Hinnant42b84842011-05-27 20:52:28 +0000266__bitset<_N_words, _Size>::__bitset(unsigned long long __v) _NOEXCEPT
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000267#ifndef _LIBCPP_CXX03_LANG
Nico Weberd04e4752014-06-04 15:46:56 +0000268#if __SIZEOF_SIZE_T__ == 8
Howard Hinnant49e96a62012-07-07 17:04:52 +0000269 : __first_{__v}
Nico Weberd04e4752014-06-04 15:46:56 +0000270#elif __SIZEOF_SIZE_T__ == 4
Louis Dionne44bcff92018-08-03 22:36:53 +0000271 : __first_{static_cast<__storage_type>(__v),
272 _Size >= 2 * __bits_per_word ? static_cast<__storage_type>(__v >> __bits_per_word)
273 : static_cast<__storage_type>((__v >> __bits_per_word) & (__storage_type(1) << (_Size - __bits_per_word)) - 1)}
Howard Hinnant96362822013-03-06 18:16:12 +0000274#else
Howard Hinnant55afb722013-03-06 17:30:26 +0000275#error This constructor has not been ported to this platform
276#endif
Howard Hinnant49e96a62012-07-07 17:04:52 +0000277#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000278{
Eric Fiselierf07d88c2017-04-19 01:34:08 +0000279#ifdef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000280 __init(__v, integral_constant<bool, sizeof(unsigned long long) == sizeof(__storage_type)>());
Howard Hinnant49e96a62012-07-07 17:04:52 +0000281#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000282}
283
284template <size_t _N_words, size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000285inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000286void
Howard Hinnant42b84842011-05-27 20:52:28 +0000287__bitset<_N_words, _Size>::operator&=(const __bitset& __v) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000288{
289 for (size_type __i = 0; __i < _N_words; ++__i)
290 __first_[__i] &= __v.__first_[__i];
291}
292
293template <size_t _N_words, size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000294inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000295void
Howard Hinnant42b84842011-05-27 20:52:28 +0000296__bitset<_N_words, _Size>::operator|=(const __bitset& __v) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000297{
298 for (size_type __i = 0; __i < _N_words; ++__i)
299 __first_[__i] |= __v.__first_[__i];
300}
301
302template <size_t _N_words, size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000303inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000304void
Howard Hinnant42b84842011-05-27 20:52:28 +0000305__bitset<_N_words, _Size>::operator^=(const __bitset& __v) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000306{
307 for (size_type __i = 0; __i < _N_words; ++__i)
308 __first_[__i] ^= __v.__first_[__i];
309}
310
311template <size_t _N_words, size_t _Size>
312void
Howard Hinnant42b84842011-05-27 20:52:28 +0000313__bitset<_N_words, _Size>::flip() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000314{
315 // do middle whole words
316 size_type __n = _Size;
317 __storage_pointer __p = __first_;
318 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
319 *__p = ~*__p;
320 // do last partial word
321 if (__n > 0)
322 {
323 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
324 __storage_type __b = *__p & __m;
325 *__p &= ~__m;
326 *__p |= ~__b & __m;
327 }
328}
329
330template <size_t _N_words, size_t _Size>
331unsigned long
332__bitset<_N_words, _Size>::to_ulong(false_type) const
333{
334 const_iterator __e = __make_iter(_Size);
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000335 const_iterator __i = _VSTD::find(__make_iter(sizeof(unsigned long) * CHAR_BIT), __e, true);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000336 if (__i != __e)
Marshall Clow8fea1612016-08-25 15:09:01 +0000337 __throw_overflow_error("bitset to_ulong overflow error");
338
Howard Hinnantc51e1022010-05-11 19:42:16 +0000339 return __first_[0];
340}
341
342template <size_t _N_words, size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000343inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000344unsigned long
345__bitset<_N_words, _Size>::to_ulong(true_type) const
346{
347 return __first_[0];
348}
349
350template <size_t _N_words, size_t _Size>
351unsigned long long
352__bitset<_N_words, _Size>::to_ullong(false_type) const
353{
354 const_iterator __e = __make_iter(_Size);
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000355 const_iterator __i = _VSTD::find(__make_iter(sizeof(unsigned long long) * CHAR_BIT), __e, true);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000356 if (__i != __e)
Marshall Clow8fea1612016-08-25 15:09:01 +0000357 __throw_overflow_error("bitset to_ullong overflow error");
358
Howard Hinnantc51e1022010-05-11 19:42:16 +0000359 return to_ullong(true_type());
360}
361
362template <size_t _N_words, size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000363inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000364unsigned long long
365__bitset<_N_words, _Size>::to_ullong(true_type) const
366{
367 return to_ullong(true_type(), integral_constant<bool, sizeof(__storage_type) < sizeof(unsigned long long)>());
368}
369
370template <size_t _N_words, size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000371inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000372unsigned long long
373__bitset<_N_words, _Size>::to_ullong(true_type, false_type) const
374{
375 return __first_[0];
376}
377
378template <size_t _N_words, size_t _Size>
379unsigned long long
380__bitset<_N_words, _Size>::to_ullong(true_type, true_type) const
381{
382 unsigned long long __r = __first_[0];
Arthur O'Dwyer07b22492020-11-27 11:02:06 -0500383 for (size_t __i = 1; __i < sizeof(unsigned long long) / sizeof(__storage_type); ++__i)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000384 __r |= static_cast<unsigned long long>(__first_[__i]) << (sizeof(__storage_type) * CHAR_BIT);
385 return __r;
386}
387
388template <size_t _N_words, size_t _Size>
389bool
Howard Hinnant42b84842011-05-27 20:52:28 +0000390__bitset<_N_words, _Size>::all() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000391{
392 // do middle whole words
393 size_type __n = _Size;
394 __const_storage_pointer __p = __first_;
395 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
396 if (~*__p)
397 return false;
398 // do last partial word
399 if (__n > 0)
400 {
401 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
402 if (~*__p & __m)
403 return false;
404 }
405 return true;
406}
407
408template <size_t _N_words, size_t _Size>
409bool
Howard Hinnant42b84842011-05-27 20:52:28 +0000410__bitset<_N_words, _Size>::any() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000411{
412 // do middle whole words
413 size_type __n = _Size;
414 __const_storage_pointer __p = __first_;
415 for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
416 if (*__p)
417 return true;
418 // do last partial word
419 if (__n > 0)
420 {
421 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
422 if (*__p & __m)
423 return true;
424 }
425 return false;
426}
427
428template <size_t _N_words, size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000429inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000430size_t
Howard Hinnant42b84842011-05-27 20:52:28 +0000431__bitset<_N_words, _Size>::__hash_code() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000432{
433 size_t __h = 0;
434 for (size_type __i = 0; __i < _N_words; ++__i)
435 __h ^= __first_[__i];
436 return __h;
437}
438
439template <size_t _Size>
440class __bitset<1, _Size>
441{
442public:
443 typedef ptrdiff_t difference_type;
444 typedef size_t size_type;
Howard Hinnant896b7622012-05-07 16:50:38 +0000445 typedef size_type __storage_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000446protected:
447 typedef __bitset __self;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000448 typedef __storage_type* __storage_pointer;
449 typedef const __storage_type* __const_storage_pointer;
450 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
451
452 friend class __bit_reference<__bitset>;
453 friend class __bit_const_reference<__bitset>;
454 friend class __bit_iterator<__bitset, false>;
455 friend class __bit_iterator<__bitset, true>;
Howard Hinnant4210a0f2012-08-17 17:10:18 +0000456 friend struct __bit_array<__bitset>;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000457
458 __storage_type __first_;
459
460 typedef __bit_reference<__bitset> reference;
461 typedef __bit_const_reference<__bitset> const_reference;
462 typedef __bit_iterator<__bitset, false> iterator;
463 typedef __bit_iterator<__bitset, true> const_iterator;
464
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000465 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant49e96a62012-07-07 17:04:52 +0000466 _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000467 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant49e96a62012-07-07 17:04:52 +0000468 explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000469
Howard Hinnant42b84842011-05-27 20:52:28 +0000470 _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t __pos) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000471 {return reference(&__first_, __storage_type(1) << __pos);}
Howard Hinnant49e96a62012-07-07 17:04:52 +0000472 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000473 {return const_reference(&__first_, __storage_type(1) << __pos);}
Howard Hinnant42b84842011-05-27 20:52:28 +0000474 _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t __pos) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000475 {return iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
Howard Hinnant42b84842011-05-27 20:52:28 +0000476 _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000477 {return const_iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
478
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000479 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000480 void operator&=(const __bitset& __v) _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000481 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000482 void operator|=(const __bitset& __v) _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000483 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000484 void operator^=(const __bitset& __v) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000485
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000486 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000487 void flip() _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000488
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000489 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000490 unsigned long to_ulong() const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000491 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000492 unsigned long long to_ullong() const;
493
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000494 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000495 bool all() const _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000496 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000497 bool any() const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000498
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000499 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000500 size_t __hash_code() const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000501};
502
503template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000504inline
Howard Hinnant49e96a62012-07-07 17:04:52 +0000505_LIBCPP_CONSTEXPR
Howard Hinnant42b84842011-05-27 20:52:28 +0000506__bitset<1, _Size>::__bitset() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000507 : __first_(0)
508{
509}
510
511template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000512inline
Howard Hinnant49e96a62012-07-07 17:04:52 +0000513_LIBCPP_CONSTEXPR
Howard Hinnant42b84842011-05-27 20:52:28 +0000514__bitset<1, _Size>::__bitset(unsigned long long __v) _NOEXCEPT
Marshall Clow7170bf62017-11-27 19:03:30 +0000515 : __first_(
516 _Size == __bits_per_word ? static_cast<__storage_type>(__v)
517 : static_cast<__storage_type>(__v) & ((__storage_type(1) << _Size) - 1)
518 )
Howard Hinnantc51e1022010-05-11 19:42:16 +0000519{
520}
521
522template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000523inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000524void
Howard Hinnant42b84842011-05-27 20:52:28 +0000525__bitset<1, _Size>::operator&=(const __bitset& __v) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000526{
527 __first_ &= __v.__first_;
528}
529
530template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000531inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000532void
Howard Hinnant42b84842011-05-27 20:52:28 +0000533__bitset<1, _Size>::operator|=(const __bitset& __v) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000534{
535 __first_ |= __v.__first_;
536}
537
538template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000539inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000540void
Howard Hinnant42b84842011-05-27 20:52:28 +0000541__bitset<1, _Size>::operator^=(const __bitset& __v) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000542{
543 __first_ ^= __v.__first_;
544}
545
546template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000547inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000548void
Howard Hinnant42b84842011-05-27 20:52:28 +0000549__bitset<1, _Size>::flip() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000550{
551 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
552 __first_ = ~__first_;
553 __first_ &= __m;
554}
555
556template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000557inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000558unsigned long
559__bitset<1, _Size>::to_ulong() const
560{
561 return __first_;
562}
563
564template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000565inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000566unsigned long long
567__bitset<1, _Size>::to_ullong() const
568{
569 return __first_;
570}
571
572template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000573inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000574bool
Howard Hinnant42b84842011-05-27 20:52:28 +0000575__bitset<1, _Size>::all() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000576{
577 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
578 return !(~__first_ & __m);
579}
580
581template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000582inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000583bool
Howard Hinnant42b84842011-05-27 20:52:28 +0000584__bitset<1, _Size>::any() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000585{
586 __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
587 return __first_ & __m;
588}
589
590template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000591inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000592size_t
Howard Hinnant42b84842011-05-27 20:52:28 +0000593__bitset<1, _Size>::__hash_code() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000594{
595 return __first_;
596}
597
598template <>
599class __bitset<0, 0>
600{
601public:
602 typedef ptrdiff_t difference_type;
603 typedef size_t size_type;
Howard Hinnant896b7622012-05-07 16:50:38 +0000604 typedef size_type __storage_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000605protected:
606 typedef __bitset __self;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000607 typedef __storage_type* __storage_pointer;
608 typedef const __storage_type* __const_storage_pointer;
609 static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
610
611 friend class __bit_reference<__bitset>;
612 friend class __bit_const_reference<__bitset>;
613 friend class __bit_iterator<__bitset, false>;
614 friend class __bit_iterator<__bitset, true>;
Howard Hinnant28b24882011-12-01 20:21:04 +0000615 friend struct __bit_array<__bitset>;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000616
617 typedef __bit_reference<__bitset> reference;
618 typedef __bit_const_reference<__bitset> const_reference;
619 typedef __bit_iterator<__bitset, false> iterator;
620 typedef __bit_iterator<__bitset, true> const_iterator;
621
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000622 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant49e96a62012-07-07 17:04:52 +0000623 _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000624 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant49e96a62012-07-07 17:04:52 +0000625 explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000626
Howard Hinnant42b84842011-05-27 20:52:28 +0000627 _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t) _NOEXCEPT
Bruce Mitchener170d8972020-11-24 12:53:53 -0500628 {return reference(nullptr, 1);}
Howard Hinnant49e96a62012-07-07 17:04:52 +0000629 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t) const _NOEXCEPT
Bruce Mitchener170d8972020-11-24 12:53:53 -0500630 {return const_reference(nullptr, 1);}
Howard Hinnant28b24882011-12-01 20:21:04 +0000631 _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t) _NOEXCEPT
Bruce Mitchener170d8972020-11-24 12:53:53 -0500632 {return iterator(nullptr, 0);}
Howard Hinnant28b24882011-12-01 20:21:04 +0000633 _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t) const _NOEXCEPT
Bruce Mitchener170d8972020-11-24 12:53:53 -0500634 {return const_iterator(nullptr, 0);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000635
Howard Hinnant42b84842011-05-27 20:52:28 +0000636 _LIBCPP_INLINE_VISIBILITY void operator&=(const __bitset&) _NOEXCEPT {}
637 _LIBCPP_INLINE_VISIBILITY void operator|=(const __bitset&) _NOEXCEPT {}
638 _LIBCPP_INLINE_VISIBILITY void operator^=(const __bitset&) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000639
Howard Hinnant42b84842011-05-27 20:52:28 +0000640 _LIBCPP_INLINE_VISIBILITY void flip() _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000641
642 _LIBCPP_INLINE_VISIBILITY unsigned long to_ulong() const {return 0;}
643 _LIBCPP_INLINE_VISIBILITY unsigned long long to_ullong() const {return 0;}
644
Howard Hinnant42b84842011-05-27 20:52:28 +0000645 _LIBCPP_INLINE_VISIBILITY bool all() const _NOEXCEPT {return true;}
646 _LIBCPP_INLINE_VISIBILITY bool any() const _NOEXCEPT {return false;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000647
Howard Hinnant42b84842011-05-27 20:52:28 +0000648 _LIBCPP_INLINE_VISIBILITY size_t __hash_code() const _NOEXCEPT {return 0;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000649};
650
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000651inline
Howard Hinnant49e96a62012-07-07 17:04:52 +0000652_LIBCPP_CONSTEXPR
Howard Hinnant42b84842011-05-27 20:52:28 +0000653__bitset<0, 0>::__bitset() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000654{
655}
656
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000657inline
Howard Hinnant49e96a62012-07-07 17:04:52 +0000658_LIBCPP_CONSTEXPR
Howard Hinnant42b84842011-05-27 20:52:28 +0000659__bitset<0, 0>::__bitset(unsigned long long) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000660{
661}
662
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000663template <size_t _Size> class _LIBCPP_TEMPLATE_VIS bitset;
Eric Fiselier6585c752016-04-21 22:54:21 +0000664template <size_t _Size> struct hash<bitset<_Size> >;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000665
666template <size_t _Size>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000667class _LIBCPP_TEMPLATE_VIS bitset
Howard Hinnantc51e1022010-05-11 19:42:16 +0000668 : private __bitset<_Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1, _Size>
669{
Howard Hinnant55afb722013-03-06 17:30:26 +0000670public:
Howard Hinnantc51e1022010-05-11 19:42:16 +0000671 static const unsigned __n_words = _Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1;
672 typedef __bitset<__n_words, _Size> base;
673
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000674public:
Howard Hinnantc51e1022010-05-11 19:42:16 +0000675 typedef typename base::reference reference;
676 typedef typename base::const_reference const_reference;
677
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000678 // 23.3.5.1 constructors:
Howard Hinnant49e96a62012-07-07 17:04:52 +0000679 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bitset() _NOEXCEPT {}
680 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
681 bitset(unsigned long long __v) _NOEXCEPT : base(__v) {}
Eric Fiselier7281d5e2019-07-01 19:59:34 +0000682 template<class _CharT, class = _EnableIf<_IsCharLikeType<_CharT>::value> >
Howard Hinnant3a217732010-11-17 21:53:14 +0000683 explicit bitset(const _CharT* __str,
684 typename basic_string<_CharT>::size_type __n = basic_string<_CharT>::npos,
685 _CharT __zero = _CharT('0'), _CharT __one = _CharT('1'));
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000686 template<class _CharT, class _Traits, class _Allocator>
687 explicit bitset(const basic_string<_CharT,_Traits,_Allocator>& __str,
688 typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos = 0,
689 typename basic_string<_CharT,_Traits,_Allocator>::size_type __n =
Howard Hinnantc51e1022010-05-11 19:42:16 +0000690 (basic_string<_CharT,_Traits,_Allocator>::npos),
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000691 _CharT __zero = _CharT('0'), _CharT __one = _CharT('1'));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000692
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000693 // 23.3.5.2 bitset operations:
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000694 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000695 bitset& operator&=(const bitset& __rhs) _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000696 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000697 bitset& operator|=(const bitset& __rhs) _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000698 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000699 bitset& operator^=(const bitset& __rhs) _NOEXCEPT;
700 bitset& operator<<=(size_t __pos) _NOEXCEPT;
701 bitset& operator>>=(size_t __pos) _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000702 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000703 bitset& set() _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000704 bitset& set(size_t __pos, bool __val = true);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000705 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000706 bitset& reset() _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000707 bitset& reset(size_t __pos);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000708 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000709 bitset operator~() const _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000710 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000711 bitset& flip() _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000712 bitset& flip(size_t __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000713
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000714 // element access:
Howard Hinnant49e96a62012-07-07 17:04:52 +0000715 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
716 const_reference operator[](size_t __p) const {return base::__make_ref(__p);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000717 _LIBCPP_INLINE_VISIBILITY reference operator[](size_t __p) {return base::__make_ref(__p);}
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000718 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000719 unsigned long to_ulong() const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000720 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000721 unsigned long long to_ullong() const;
722 template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000723 basic_string<_CharT, _Traits, _Allocator> to_string(_CharT __zero = _CharT('0'),
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000724 _CharT __one = _CharT('1')) const;
725 template <class _CharT, class _Traits>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000726 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000727 basic_string<_CharT, _Traits, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'),
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000728 _CharT __one = _CharT('1')) const;
729 template <class _CharT>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000730 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000731 basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'),
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000732 _CharT __one = _CharT('1')) const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000733 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000734 basic_string<char, char_traits<char>, allocator<char> > to_string(char __zero = '0',
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000735 char __one = '1') const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000736 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000737 size_t count() const _NOEXCEPT;
Howard Hinnant49e96a62012-07-07 17:04:52 +0000738 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR size_t size() const _NOEXCEPT {return _Size;}
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000739 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000740 bool operator==(const bitset& __rhs) const _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000741 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000742 bool operator!=(const bitset& __rhs) const _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000743 bool test(size_t __pos) const;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000744 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000745 bool all() const _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000746 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000747 bool any() const _NOEXCEPT;
748 _LIBCPP_INLINE_VISIBILITY bool none() const _NOEXCEPT {return !any();}
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000749 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000750 bitset operator<<(size_t __pos) const _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000751 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000752 bitset operator>>(size_t __pos) const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000753
754private:
755
Howard Hinnant874ad9a2010-09-21 21:28:23 +0000756 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +0000757 size_t __hash_code() const _NOEXCEPT {return base::__hash_code();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000758
759 friend struct hash<bitset>;
760};
761
762template <size_t _Size>
Eric Fiselier7281d5e2019-07-01 19:59:34 +0000763template<class _CharT, class>
Howard Hinnant3a217732010-11-17 21:53:14 +0000764bitset<_Size>::bitset(const _CharT* __str,
765 typename basic_string<_CharT>::size_type __n,
766 _CharT __zero, _CharT __one)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000767{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000768 size_t __rlen = _VSTD::min(__n, char_traits<_CharT>::length(__str));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000769 for (size_t __i = 0; __i < __rlen; ++__i)
Howard Hinnant3a217732010-11-17 21:53:14 +0000770 if (__str[__i] != __zero && __str[__i] != __one)
Marshall Clow8fea1612016-08-25 15:09:01 +0000771 __throw_invalid_argument("bitset string ctor has invalid argument");
772
Howard Hinnantc834c512011-11-29 18:15:50 +0000773 size_t _Mp = _VSTD::min(__rlen, _Size);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000774 size_t __i = 0;
Howard Hinnantc834c512011-11-29 18:15:50 +0000775 for (; __i < _Mp; ++__i)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000776 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000777 _CharT __c = __str[_Mp - 1 - __i];
Shu Tian023b3482021-04-24 16:08:55 +0200778 (*this)[__i] = (__c == __one);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000779 }
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000780 _VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000781}
782
783template <size_t _Size>
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000784template<class _CharT, class _Traits, class _Allocator>
785bitset<_Size>::bitset(const basic_string<_CharT,_Traits,_Allocator>& __str,
786 typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos,
Howard Hinnantc51e1022010-05-11 19:42:16 +0000787 typename basic_string<_CharT,_Traits,_Allocator>::size_type __n,
788 _CharT __zero, _CharT __one)
789{
790 if (__pos > __str.size())
Marshall Clow8fea1612016-08-25 15:09:01 +0000791 __throw_out_of_range("bitset string pos out of range");
792
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000793 size_t __rlen = _VSTD::min(__n, __str.size() - __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000794 for (size_t __i = __pos; __i < __pos + __rlen; ++__i)
795 if (!_Traits::eq(__str[__i], __zero) && !_Traits::eq(__str[__i], __one))
Marshall Clow8fea1612016-08-25 15:09:01 +0000796 __throw_invalid_argument("bitset string ctor has invalid argument");
797
Howard Hinnantc834c512011-11-29 18:15:50 +0000798 size_t _Mp = _VSTD::min(__rlen, _Size);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000799 size_t __i = 0;
Howard Hinnantc834c512011-11-29 18:15:50 +0000800 for (; __i < _Mp; ++__i)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000801 {
Howard Hinnantc834c512011-11-29 18:15:50 +0000802 _CharT __c = __str[__pos + _Mp - 1 - __i];
Shu Tian023b3482021-04-24 16:08:55 +0200803 (*this)[__i] = _Traits::eq(__c, __one);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000804 }
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000805 _VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000806}
807
808template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000809inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000810bitset<_Size>&
Howard Hinnant42b84842011-05-27 20:52:28 +0000811bitset<_Size>::operator&=(const bitset& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000812{
813 base::operator&=(__rhs);
814 return *this;
815}
816
817template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000818inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000819bitset<_Size>&
Howard Hinnant42b84842011-05-27 20:52:28 +0000820bitset<_Size>::operator|=(const bitset& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000821{
822 base::operator|=(__rhs);
823 return *this;
824}
825
826template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000827inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000828bitset<_Size>&
Howard Hinnant42b84842011-05-27 20:52:28 +0000829bitset<_Size>::operator^=(const bitset& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000830{
831 base::operator^=(__rhs);
832 return *this;
833}
834
835template <size_t _Size>
836bitset<_Size>&
Howard Hinnant42b84842011-05-27 20:52:28 +0000837bitset<_Size>::operator<<=(size_t __pos) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000838{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000839 __pos = _VSTD::min(__pos, _Size);
840 _VSTD::copy_backward(base::__make_iter(0), base::__make_iter(_Size - __pos), base::__make_iter(_Size));
841 _VSTD::fill_n(base::__make_iter(0), __pos, false);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000842 return *this;
843}
844
845template <size_t _Size>
846bitset<_Size>&
Howard Hinnant42b84842011-05-27 20:52:28 +0000847bitset<_Size>::operator>>=(size_t __pos) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000848{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000849 __pos = _VSTD::min(__pos, _Size);
850 _VSTD::copy(base::__make_iter(__pos), base::__make_iter(_Size), base::__make_iter(0));
851 _VSTD::fill_n(base::__make_iter(_Size - __pos), __pos, false);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000852 return *this;
853}
854
855template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000856inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000857bitset<_Size>&
Howard Hinnant42b84842011-05-27 20:52:28 +0000858bitset<_Size>::set() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000859{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000860 _VSTD::fill_n(base::__make_iter(0), _Size, true);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000861 return *this;
862}
863
864template <size_t _Size>
865bitset<_Size>&
866bitset<_Size>::set(size_t __pos, bool __val)
867{
868 if (__pos >= _Size)
Marshall Clow8fea1612016-08-25 15:09:01 +0000869 __throw_out_of_range("bitset set argument out of range");
870
Howard Hinnantc51e1022010-05-11 19:42:16 +0000871 (*this)[__pos] = __val;
872 return *this;
873}
874
875template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000876inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000877bitset<_Size>&
Howard Hinnant42b84842011-05-27 20:52:28 +0000878bitset<_Size>::reset() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000879{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000880 _VSTD::fill_n(base::__make_iter(0), _Size, false);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000881 return *this;
882}
883
884template <size_t _Size>
885bitset<_Size>&
886bitset<_Size>::reset(size_t __pos)
887{
888 if (__pos >= _Size)
Marshall Clow8fea1612016-08-25 15:09:01 +0000889 __throw_out_of_range("bitset reset argument out of range");
890
Howard Hinnantc51e1022010-05-11 19:42:16 +0000891 (*this)[__pos] = false;
892 return *this;
893}
894
895template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000896inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000897bitset<_Size>
Howard Hinnant42b84842011-05-27 20:52:28 +0000898bitset<_Size>::operator~() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000899{
900 bitset __x(*this);
901 __x.flip();
902 return __x;
903}
904
905template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000906inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000907bitset<_Size>&
Howard Hinnant42b84842011-05-27 20:52:28 +0000908bitset<_Size>::flip() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000909{
910 base::flip();
911 return *this;
912}
913
914template <size_t _Size>
915bitset<_Size>&
916bitset<_Size>::flip(size_t __pos)
917{
918 if (__pos >= _Size)
Marshall Clow8fea1612016-08-25 15:09:01 +0000919 __throw_out_of_range("bitset flip argument out of range");
920
Howard Hinnantc51e1022010-05-11 19:42:16 +0000921 reference r = base::__make_ref(__pos);
922 r = ~r;
923 return *this;
924}
925
926template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000927inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000928unsigned long
929bitset<_Size>::to_ulong() const
930{
931 return base::to_ulong();
932}
933
934template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000935inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000936unsigned long long
937bitset<_Size>::to_ullong() const
938{
939 return base::to_ullong();
940}
941
942template <size_t _Size>
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000943template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000944basic_string<_CharT, _Traits, _Allocator>
945bitset<_Size>::to_string(_CharT __zero, _CharT __one) const
946{
947 basic_string<_CharT, _Traits, _Allocator> __r(_Size, __zero);
948 for (size_t __i = 0; __i < _Size; ++__i)
949 {
950 if ((*this)[__i])
951 __r[_Size - 1 - __i] = __one;
952 }
953 return __r;
954}
955
956template <size_t _Size>
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000957template <class _CharT, class _Traits>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000958inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000959basic_string<_CharT, _Traits, allocator<_CharT> >
960bitset<_Size>::to_string(_CharT __zero, _CharT __one) const
961{
962 return to_string<_CharT, _Traits, allocator<_CharT> >(__zero, __one);
963}
964
965template <size_t _Size>
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000966template <class _CharT>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000967inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000968basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> >
969bitset<_Size>::to_string(_CharT __zero, _CharT __one) const
970{
971 return to_string<_CharT, char_traits<_CharT>, allocator<_CharT> >(__zero, __one);
972}
973
974template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000975inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000976basic_string<char, char_traits<char>, allocator<char> >
977bitset<_Size>::to_string(char __zero, char __one) const
978{
979 return to_string<char, char_traits<char>, allocator<char> >(__zero, __one);
980}
981
982template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000983inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000984size_t
Howard Hinnant42b84842011-05-27 20:52:28 +0000985bitset<_Size>::count() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000986{
Arthur O'Dwyer34465da2020-12-15 19:32:29 -0500987 return static_cast<size_t>(_VSTD::__count_bool_true(base::__make_iter(0), _Size));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000988}
989
990template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000991inline
Howard Hinnantc51e1022010-05-11 19:42:16 +0000992bool
Howard Hinnant42b84842011-05-27 20:52:28 +0000993bitset<_Size>::operator==(const bitset& __rhs) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000994{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000995 return _VSTD::equal(base::__make_iter(0), base::__make_iter(_Size), __rhs.__make_iter(0));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000996}
997
998template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +0000999inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001000bool
Howard Hinnant42b84842011-05-27 20:52:28 +00001001bitset<_Size>::operator!=(const bitset& __rhs) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001002{
1003 return !(*this == __rhs);
1004}
1005
1006template <size_t _Size>
1007bool
1008bitset<_Size>::test(size_t __pos) const
1009{
1010 if (__pos >= _Size)
Marshall Clow8fea1612016-08-25 15:09:01 +00001011 __throw_out_of_range("bitset test argument out of range");
1012
Howard Hinnantc51e1022010-05-11 19:42:16 +00001013 return (*this)[__pos];
1014}
1015
1016template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001017inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001018bool
Howard Hinnant42b84842011-05-27 20:52:28 +00001019bitset<_Size>::all() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001020{
1021 return base::all();
1022}
1023
1024template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001025inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001026bool
Howard Hinnant42b84842011-05-27 20:52:28 +00001027bitset<_Size>::any() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001028{
1029 return base::any();
1030}
1031
1032template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001033inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001034bitset<_Size>
Howard Hinnant42b84842011-05-27 20:52:28 +00001035bitset<_Size>::operator<<(size_t __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001036{
1037 bitset __r = *this;
1038 __r <<= __pos;
1039 return __r;
1040}
1041
1042template <size_t _Size>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00001043inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00001044bitset<_Size>
Howard Hinnant42b84842011-05-27 20:52:28 +00001045bitset<_Size>::operator>>(size_t __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001046{
1047 bitset __r = *this;
1048 __r >>= __pos;
1049 return __r;
1050}
1051
1052template <size_t _Size>
1053inline _LIBCPP_INLINE_VISIBILITY
1054bitset<_Size>
Howard Hinnant42b84842011-05-27 20:52:28 +00001055operator&(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001056{
1057 bitset<_Size> __r = __x;
1058 __r &= __y;
1059 return __r;
1060}
1061
1062template <size_t _Size>
1063inline _LIBCPP_INLINE_VISIBILITY
1064bitset<_Size>
Howard Hinnant42b84842011-05-27 20:52:28 +00001065operator|(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001066{
1067 bitset<_Size> __r = __x;
1068 __r |= __y;
1069 return __r;
1070}
1071
1072template <size_t _Size>
1073inline _LIBCPP_INLINE_VISIBILITY
1074bitset<_Size>
Howard Hinnant42b84842011-05-27 20:52:28 +00001075operator^(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001076{
1077 bitset<_Size> __r = __x;
1078 __r ^= __y;
1079 return __r;
1080}
1081
1082template <size_t _Size>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001083struct _LIBCPP_TEMPLATE_VIS hash<bitset<_Size> >
Howard Hinnantc51e1022010-05-11 19:42:16 +00001084 : public unary_function<bitset<_Size>, size_t>
1085{
Howard Hinnant874ad9a2010-09-21 21:28:23 +00001086 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant42b84842011-05-27 20:52:28 +00001087 size_t operator()(const bitset<_Size>& __bs) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001088 {return __bs.__hash_code();}
1089};
1090
Howard Hinnantdc095972011-07-18 15:51:59 +00001091template <class _CharT, class _Traits, size_t _Size>
1092basic_istream<_CharT, _Traits>&
1093operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x);
1094
1095template <class _CharT, class _Traits, size_t _Size>
1096basic_ostream<_CharT, _Traits>&
1097operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x);
1098
Howard Hinnantc51e1022010-05-11 19:42:16 +00001099_LIBCPP_END_NAMESPACE_STD
1100
Eric Fiselierf4433a32017-05-31 22:07:49 +00001101_LIBCPP_POP_MACROS
1102
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001103#endif // _LIBCPP_BITSET