/src/llvm-project-18.1.8.build/include/c++/v1/bitset
Line | Count | Source (jump to first uncovered line) |
1 | | // -*- C++ -*- |
2 | | //===----------------------------------------------------------------------===// |
3 | | // |
4 | | // 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 |
7 | | // |
8 | | //===----------------------------------------------------------------------===// |
9 | | |
10 | | #ifndef _LIBCPP_BITSET |
11 | | #define _LIBCPP_BITSET |
12 | | |
13 | | // clang-format off |
14 | | |
15 | | /* |
16 | | bitset synopsis |
17 | | |
18 | | namespace std |
19 | | { |
20 | | |
21 | | namespace std { |
22 | | |
23 | | template <size_t N> |
24 | | class bitset |
25 | | { |
26 | | public: |
27 | | // bit reference: |
28 | | class reference |
29 | | { |
30 | | friend class bitset; |
31 | | reference() noexcept; |
32 | | public: |
33 | | ~reference() noexcept; |
34 | | reference& operator=(bool x) noexcept; // for b[i] = x; |
35 | | reference& operator=(const reference&) noexcept; // for b[i] = b[j]; |
36 | | bool operator~() const noexcept; // flips the bit |
37 | | operator bool() const noexcept; // for x = b[i]; |
38 | | reference& flip() noexcept; // for b[i].flip(); |
39 | | }; |
40 | | |
41 | | // 23.3.5.1 constructors: |
42 | | constexpr bitset() noexcept; |
43 | | constexpr bitset(unsigned long long val) noexcept; |
44 | | template <class charT> |
45 | | constexpr explicit bitset(const charT* str, |
46 | | typename basic_string<charT>::size_type n = basic_string<charT>::npos, |
47 | | charT zero = charT('0'), charT one = charT('1')); // until C++26, constexpr since C++23 |
48 | | template <class charT> |
49 | | constexpr explicit bitset(const charT* str, |
50 | | typename basic_string_view<charT>::size_type n = basic_string_view<charT>::npos, |
51 | | charT zero = charT('0'), charT one = charT('1')); // since C++26 |
52 | | template<class charT, class traits> |
53 | | explicit bitset( |
54 | | const basic_string_view<charT,traits>& str, |
55 | | typename basic_string_view<charT,traits>::size_type pos = 0, |
56 | | typename basic_string_view<charT,traits>::size_type n = basic_string_view<charT,traits>::npos, |
57 | | charT zero = charT('0'), charT one = charT('1')); // since C++26 |
58 | | template<class charT, class traits, class Allocator> |
59 | | constexpr explicit bitset( |
60 | | const basic_string<charT,traits,Allocator>& str, |
61 | | typename basic_string<charT,traits,Allocator>::size_type pos = 0, |
62 | | typename basic_string<charT,traits,Allocator>::size_type n = basic_string<charT,traits,Allocator>::npos, |
63 | | charT zero = charT('0'), charT one = charT('1')); // constexpr since C++23 |
64 | | |
65 | | // 23.3.5.2 bitset operations: |
66 | | bitset& operator&=(const bitset& rhs) noexcept; // constexpr since C++23 |
67 | | bitset& operator|=(const bitset& rhs) noexcept; // constexpr since C++23 |
68 | | bitset& operator^=(const bitset& rhs) noexcept; // constexpr since C++23 |
69 | | bitset& operator<<=(size_t pos) noexcept; // constexpr since C++23 |
70 | | bitset& operator>>=(size_t pos) noexcept; // constexpr since C++23 |
71 | | bitset& set() noexcept; // constexpr since C++23 |
72 | | bitset& set(size_t pos, bool val = true); // constexpr since C++23 |
73 | | bitset& reset() noexcept; // constexpr since C++23 |
74 | | bitset& reset(size_t pos); // constexpr since C++23 |
75 | | bitset operator~() const noexcept; // constexpr since C++23 |
76 | | bitset& flip() noexcept; // constexpr since C++23 |
77 | | bitset& flip(size_t pos); // constexpr since C++23 |
78 | | |
79 | | // element access: |
80 | | constexpr bool operator[](size_t pos) const; |
81 | | reference operator[](size_t pos); // constexpr since C++23 |
82 | | unsigned long to_ulong() const; // constexpr since C++23 |
83 | | unsigned long long to_ullong() const; // constexpr since C++23 |
84 | | template <class charT, class traits, class Allocator> // constexpr since C++23 |
85 | | basic_string<charT, traits, Allocator> to_string(charT zero = charT('0'), charT one = charT('1')) const; |
86 | | template <class charT, class traits> // constexpr since C++23 |
87 | | basic_string<charT, traits, allocator<charT> > to_string(charT zero = charT('0'), charT one = charT('1')) const; |
88 | | template <class charT> // constexpr since C++23 |
89 | | basic_string<charT, char_traits<charT>, allocator<charT> > to_string(charT zero = charT('0'), charT one = charT('1')) const; |
90 | | basic_string<char, char_traits<char>, allocator<char> > to_string(char zero = '0', char one = '1') const; // constexpr since C++23 |
91 | | size_t count() const noexcept; // constexpr since C++23 |
92 | | constexpr size_t size() const noexcept; // constexpr since C++23 |
93 | | bool operator==(const bitset& rhs) const noexcept; // constexpr since C++23 |
94 | | bool operator!=(const bitset& rhs) const noexcept; // removed in C++20 |
95 | | bool test(size_t pos) const; // constexpr since C++23 |
96 | | bool all() const noexcept; // constexpr since C++23 |
97 | | bool any() const noexcept; // constexpr since C++23 |
98 | | bool none() const noexcept; // constexpr since C++23 |
99 | | bitset<N> operator<<(size_t pos) const noexcept; // constexpr since C++23 |
100 | | bitset<N> operator>>(size_t pos) const noexcept; // constexpr since C++23 |
101 | | }; |
102 | | |
103 | | // 23.3.5.3 bitset operators: |
104 | | template <size_t N> |
105 | | bitset<N> operator&(const bitset<N>&, const bitset<N>&) noexcept; // constexpr since C++23 |
106 | | |
107 | | template <size_t N> |
108 | | bitset<N> operator|(const bitset<N>&, const bitset<N>&) noexcept; // constexpr since C++23 |
109 | | |
110 | | template <size_t N> |
111 | | bitset<N> operator^(const bitset<N>&, const bitset<N>&) noexcept; // constexpr since C++23 |
112 | | |
113 | | template <class charT, class traits, size_t N> |
114 | | basic_istream<charT, traits>& |
115 | | operator>>(basic_istream<charT, traits>& is, bitset<N>& x); |
116 | | |
117 | | template <class charT, class traits, size_t N> |
118 | | basic_ostream<charT, traits>& |
119 | | operator<<(basic_ostream<charT, traits>& os, const bitset<N>& x); |
120 | | |
121 | | template <size_t N> struct hash<std::bitset<N>>; |
122 | | |
123 | | } // std |
124 | | |
125 | | */ |
126 | | |
127 | | // clang-format on |
128 | | |
129 | | #include <__algorithm/count.h> |
130 | | #include <__algorithm/fill.h> |
131 | | #include <__algorithm/find.h> |
132 | | #include <__assert> // all public C++ headers provide the assertion handler |
133 | | #include <__bit_reference> |
134 | | #include <__config> |
135 | | #include <__functional/hash.h> |
136 | | #include <__functional/unary_function.h> |
137 | | #include <__type_traits/is_char_like_type.h> |
138 | | #include <climits> |
139 | | #include <cstddef> |
140 | | #include <stdexcept> |
141 | | #include <string_view> |
142 | | #include <version> |
143 | | |
144 | | // standard-mandated includes |
145 | | |
146 | | // [bitset.syn] |
147 | | #include <iosfwd> |
148 | | #include <string> |
149 | | |
150 | | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
151 | | # pragma GCC system_header |
152 | | #endif |
153 | | |
154 | | _LIBCPP_PUSH_MACROS |
155 | | #include <__undef_macros> |
156 | | |
157 | | _LIBCPP_BEGIN_NAMESPACE_STD |
158 | | |
159 | | template <size_t _N_words, size_t _Size> |
160 | | class __bitset; |
161 | | |
162 | | template <size_t _N_words, size_t _Size> |
163 | | struct __has_storage_type<__bitset<_N_words, _Size> > { |
164 | | static const bool value = true; |
165 | | }; |
166 | | |
167 | | template <size_t _N_words, size_t _Size> |
168 | | class __bitset { |
169 | | public: |
170 | | typedef ptrdiff_t difference_type; |
171 | | typedef size_t size_type; |
172 | | typedef size_type __storage_type; |
173 | | |
174 | | protected: |
175 | | typedef __bitset __self; |
176 | | typedef __storage_type* __storage_pointer; |
177 | | typedef const __storage_type* __const_storage_pointer; |
178 | | static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT); |
179 | | |
180 | | friend class __bit_reference<__bitset>; |
181 | | friend class __bit_const_reference<__bitset>; |
182 | | friend class __bit_iterator<__bitset, false>; |
183 | | friend class __bit_iterator<__bitset, true>; |
184 | | friend struct __bit_array<__bitset>; |
185 | | |
186 | | __storage_type __first_[_N_words]; |
187 | | |
188 | | typedef __bit_reference<__bitset> reference; |
189 | | typedef __bit_const_reference<__bitset> const_reference; |
190 | | typedef __bit_iterator<__bitset, false> iterator; |
191 | | typedef __bit_iterator<__bitset, true> const_iterator; |
192 | | |
193 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT; |
194 | | _LIBCPP_HIDE_FROM_ABI explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT; |
195 | | |
196 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 reference __make_ref(size_t __pos) _NOEXCEPT { |
197 | | return reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word); |
198 | | } |
199 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT { |
200 | | return const_reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word); |
201 | | } |
202 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 iterator __make_iter(size_t __pos) _NOEXCEPT { |
203 | | return iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word); |
204 | | } |
205 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 const_iterator __make_iter(size_t __pos) const _NOEXCEPT { |
206 | | return const_iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word); |
207 | | } |
208 | | |
209 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator&=(const __bitset& __v) _NOEXCEPT; |
210 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator|=(const __bitset& __v) _NOEXCEPT; |
211 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator^=(const __bitset& __v) _NOEXCEPT; |
212 | | |
213 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void flip() _NOEXCEPT; |
214 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong() const { |
215 | | return to_ulong(integral_constant < bool, _Size< sizeof(unsigned long) * CHAR_BIT>()); |
216 | | } |
217 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong() const { |
218 | | return to_ullong(integral_constant < bool, _Size< sizeof(unsigned long long) * CHAR_BIT>()); |
219 | | } |
220 | | |
221 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT; |
222 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT; |
223 | | _LIBCPP_HIDE_FROM_ABI size_t __hash_code() const _NOEXCEPT; |
224 | | |
225 | | private: |
226 | | #ifdef _LIBCPP_CXX03_LANG |
227 | | void __init(unsigned long long __v, false_type) _NOEXCEPT; |
228 | | _LIBCPP_HIDE_FROM_ABI void __init(unsigned long long __v, true_type) _NOEXCEPT; |
229 | | #endif // _LIBCPP_CXX03_LANG |
230 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong(false_type) const; |
231 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong(true_type) const; |
232 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong(false_type) const; |
233 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong(true_type) const; |
234 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong(true_type, false_type) const; |
235 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong(true_type, true_type) const; |
236 | | }; |
237 | | |
238 | | template <size_t _N_words, size_t _Size> |
239 | | inline _LIBCPP_CONSTEXPR __bitset<_N_words, _Size>::__bitset() _NOEXCEPT |
240 | | #ifndef _LIBCPP_CXX03_LANG |
241 | | : __first_{0} |
242 | | #endif |
243 | | { |
244 | | #ifdef _LIBCPP_CXX03_LANG |
245 | | std::fill_n(__first_, _N_words, __storage_type(0)); |
246 | | #endif |
247 | | } |
248 | | |
249 | | #ifdef _LIBCPP_CXX03_LANG |
250 | | |
251 | | template <size_t _N_words, size_t _Size> |
252 | | void __bitset<_N_words, _Size>::__init(unsigned long long __v, false_type) _NOEXCEPT { |
253 | | __storage_type __t[sizeof(unsigned long long) / sizeof(__storage_type)]; |
254 | | size_t __sz = _Size; |
255 | | for (size_t __i = 0; __i < sizeof(__t) / sizeof(__t[0]); ++__i, __v >>= __bits_per_word, __sz -= __bits_per_word) |
256 | | if (__sz < __bits_per_word) |
257 | | __t[__i] = static_cast<__storage_type>(__v) & (1ULL << __sz) - 1; |
258 | | else |
259 | | __t[__i] = static_cast<__storage_type>(__v); |
260 | | |
261 | | std::copy(__t, __t + sizeof(__t) / sizeof(__t[0]), __first_); |
262 | | std::fill( |
263 | | __first_ + sizeof(__t) / sizeof(__t[0]), __first_ + sizeof(__first_) / sizeof(__first_[0]), __storage_type(0)); |
264 | | } |
265 | | |
266 | | template <size_t _N_words, size_t _Size> |
267 | | inline _LIBCPP_HIDE_FROM_ABI void __bitset<_N_words, _Size>::__init(unsigned long long __v, true_type) _NOEXCEPT { |
268 | | __first_[0] = __v; |
269 | | if (_Size < __bits_per_word) |
270 | | __first_[0] &= (1ULL << _Size) - 1; |
271 | | |
272 | | std::fill(__first_ + 1, __first_ + sizeof(__first_) / sizeof(__first_[0]), __storage_type(0)); |
273 | | } |
274 | | |
275 | | #endif // _LIBCPP_CXX03_LANG |
276 | | |
277 | | template <size_t _N_words, size_t _Size> |
278 | | inline _LIBCPP_CONSTEXPR __bitset<_N_words, _Size>::__bitset(unsigned long long __v) _NOEXCEPT |
279 | | #ifndef _LIBCPP_CXX03_LANG |
280 | | # if __SIZEOF_SIZE_T__ == 8 |
281 | | : __first_{__v} |
282 | | # elif __SIZEOF_SIZE_T__ == 4 |
283 | | : __first_{static_cast<__storage_type>(__v), |
284 | | _Size >= 2 * __bits_per_word |
285 | | ? static_cast<__storage_type>(__v >> __bits_per_word) |
286 | | : static_cast<__storage_type>((__v >> __bits_per_word) & |
287 | | (__storage_type(1) << (_Size - __bits_per_word)) - 1)} |
288 | | # else |
289 | | # error This constructor has not been ported to this platform |
290 | | # endif |
291 | | #endif |
292 | | { |
293 | | #ifdef _LIBCPP_CXX03_LANG |
294 | | __init(__v, integral_constant<bool, sizeof(unsigned long long) == sizeof(__storage_type)>()); |
295 | | #endif |
296 | | } |
297 | | |
298 | | template <size_t _N_words, size_t _Size> |
299 | | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void |
300 | | __bitset<_N_words, _Size>::operator&=(const __bitset& __v) _NOEXCEPT { |
301 | | for (size_type __i = 0; __i < _N_words; ++__i) |
302 | | __first_[__i] &= __v.__first_[__i]; |
303 | | } |
304 | | |
305 | | template <size_t _N_words, size_t _Size> |
306 | | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void |
307 | | __bitset<_N_words, _Size>::operator|=(const __bitset& __v) _NOEXCEPT { |
308 | | for (size_type __i = 0; __i < _N_words; ++__i) |
309 | | __first_[__i] |= __v.__first_[__i]; |
310 | | } |
311 | | |
312 | | template <size_t _N_words, size_t _Size> |
313 | | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void |
314 | | __bitset<_N_words, _Size>::operator^=(const __bitset& __v) _NOEXCEPT { |
315 | | for (size_type __i = 0; __i < _N_words; ++__i) |
316 | | __first_[__i] ^= __v.__first_[__i]; |
317 | | } |
318 | | |
319 | | template <size_t _N_words, size_t _Size> |
320 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void __bitset<_N_words, _Size>::flip() _NOEXCEPT { |
321 | | // do middle whole words |
322 | | size_type __n = _Size; |
323 | | __storage_pointer __p = __first_; |
324 | | for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) |
325 | | *__p = ~*__p; |
326 | | // do last partial word |
327 | | if (__n > 0) { |
328 | | __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); |
329 | | __storage_type __b = *__p & __m; |
330 | | *__p &= ~__m; |
331 | | *__p |= ~__b & __m; |
332 | | } |
333 | | } |
334 | | |
335 | | template <size_t _N_words, size_t _Size> |
336 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long |
337 | | __bitset<_N_words, _Size>::to_ulong(false_type) const { |
338 | | const_iterator __e = __make_iter(_Size); |
339 | | const_iterator __i = std::find(__make_iter(sizeof(unsigned long) * CHAR_BIT), __e, true); |
340 | | if (__i != __e) |
341 | | __throw_overflow_error("bitset to_ulong overflow error"); |
342 | | |
343 | | return __first_[0]; |
344 | | } |
345 | | |
346 | | template <size_t _N_words, size_t _Size> |
347 | | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long |
348 | | __bitset<_N_words, _Size>::to_ulong(true_type) const { |
349 | | return __first_[0]; |
350 | | } |
351 | | |
352 | | template <size_t _N_words, size_t _Size> |
353 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long |
354 | | __bitset<_N_words, _Size>::to_ullong(false_type) const { |
355 | | const_iterator __e = __make_iter(_Size); |
356 | | const_iterator __i = std::find(__make_iter(sizeof(unsigned long long) * CHAR_BIT), __e, true); |
357 | | if (__i != __e) |
358 | | __throw_overflow_error("bitset to_ullong overflow error"); |
359 | | |
360 | | return to_ullong(true_type()); |
361 | | } |
362 | | |
363 | | template <size_t _N_words, size_t _Size> |
364 | | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long |
365 | | __bitset<_N_words, _Size>::to_ullong(true_type) const { |
366 | | return to_ullong(true_type(), integral_constant<bool, sizeof(__storage_type) < sizeof(unsigned long long)>()); |
367 | | } |
368 | | |
369 | | template <size_t _N_words, size_t _Size> |
370 | | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long |
371 | | __bitset<_N_words, _Size>::to_ullong(true_type, false_type) const { |
372 | | return __first_[0]; |
373 | | } |
374 | | |
375 | | template <size_t _N_words, size_t _Size> |
376 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long |
377 | | __bitset<_N_words, _Size>::to_ullong(true_type, true_type) const { |
378 | | unsigned long long __r = __first_[0]; |
379 | | for (size_t __i = 1; __i < sizeof(unsigned long long) / sizeof(__storage_type); ++__i) |
380 | | __r |= static_cast<unsigned long long>(__first_[__i]) << (sizeof(__storage_type) * CHAR_BIT); |
381 | | return __r; |
382 | | } |
383 | | |
384 | | template <size_t _N_words, size_t _Size> |
385 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool __bitset<_N_words, _Size>::all() const _NOEXCEPT { |
386 | | // do middle whole words |
387 | | size_type __n = _Size; |
388 | | __const_storage_pointer __p = __first_; |
389 | | for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) |
390 | | if (~*__p) |
391 | | return false; |
392 | | // do last partial word |
393 | | if (__n > 0) { |
394 | | __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); |
395 | | if (~*__p & __m) |
396 | | return false; |
397 | | } |
398 | | return true; |
399 | | } |
400 | | |
401 | | template <size_t _N_words, size_t _Size> |
402 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool __bitset<_N_words, _Size>::any() const _NOEXCEPT { |
403 | | // do middle whole words |
404 | | size_type __n = _Size; |
405 | | __const_storage_pointer __p = __first_; |
406 | | for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) |
407 | | if (*__p) |
408 | | return true; |
409 | | // do last partial word |
410 | | if (__n > 0) { |
411 | | __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); |
412 | | if (*__p & __m) |
413 | | return true; |
414 | | } |
415 | | return false; |
416 | | } |
417 | | |
418 | | template <size_t _N_words, size_t _Size> |
419 | | inline size_t __bitset<_N_words, _Size>::__hash_code() const _NOEXCEPT { |
420 | | size_t __h = 0; |
421 | | for (size_type __i = 0; __i < _N_words; ++__i) |
422 | | __h ^= __first_[__i]; |
423 | | return __h; |
424 | | } |
425 | | |
426 | | template <size_t _Size> |
427 | | class __bitset<1, _Size> { |
428 | | public: |
429 | | typedef ptrdiff_t difference_type; |
430 | | typedef size_t size_type; |
431 | | typedef size_type __storage_type; |
432 | | |
433 | | protected: |
434 | | typedef __bitset __self; |
435 | | typedef __storage_type* __storage_pointer; |
436 | | typedef const __storage_type* __const_storage_pointer; |
437 | | static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT); |
438 | | |
439 | | friend class __bit_reference<__bitset>; |
440 | | friend class __bit_const_reference<__bitset>; |
441 | | friend class __bit_iterator<__bitset, false>; |
442 | | friend class __bit_iterator<__bitset, true>; |
443 | | friend struct __bit_array<__bitset>; |
444 | | |
445 | | __storage_type __first_; |
446 | | |
447 | | typedef __bit_reference<__bitset> reference; |
448 | | typedef __bit_const_reference<__bitset> const_reference; |
449 | | typedef __bit_iterator<__bitset, false> iterator; |
450 | | typedef __bit_iterator<__bitset, true> const_iterator; |
451 | | |
452 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT; |
453 | | _LIBCPP_HIDE_FROM_ABI explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT; |
454 | | |
455 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 reference __make_ref(size_t __pos) _NOEXCEPT { |
456 | | return reference(&__first_, __storage_type(1) << __pos); |
457 | | } |
458 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT { |
459 | | return const_reference(&__first_, __storage_type(1) << __pos); |
460 | | } |
461 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 iterator __make_iter(size_t __pos) _NOEXCEPT { |
462 | | return iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word); |
463 | | } |
464 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 const_iterator __make_iter(size_t __pos) const _NOEXCEPT { |
465 | | return const_iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word); |
466 | | } |
467 | | |
468 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator&=(const __bitset& __v) _NOEXCEPT; |
469 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator|=(const __bitset& __v) _NOEXCEPT; |
470 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator^=(const __bitset& __v) _NOEXCEPT; |
471 | | |
472 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void flip() _NOEXCEPT; |
473 | | |
474 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong() const; |
475 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong() const; |
476 | | |
477 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT; |
478 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT; |
479 | | |
480 | | _LIBCPP_HIDE_FROM_ABI size_t __hash_code() const _NOEXCEPT; |
481 | | }; |
482 | | |
483 | | template <size_t _Size> |
484 | | inline _LIBCPP_CONSTEXPR __bitset<1, _Size>::__bitset() _NOEXCEPT : __first_(0) {} |
485 | | |
486 | | template <size_t _Size> |
487 | | inline _LIBCPP_CONSTEXPR __bitset<1, _Size>::__bitset(unsigned long long __v) _NOEXCEPT |
488 | | : __first_(_Size == __bits_per_word ? static_cast<__storage_type>(__v) |
489 | | : static_cast<__storage_type>(__v) & ((__storage_type(1) << _Size) - 1)) {} |
490 | | |
491 | | template <size_t _Size> |
492 | | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void |
493 | | __bitset<1, _Size>::operator&=(const __bitset& __v) _NOEXCEPT { |
494 | | __first_ &= __v.__first_; |
495 | | } |
496 | | |
497 | | template <size_t _Size> |
498 | | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void |
499 | | __bitset<1, _Size>::operator|=(const __bitset& __v) _NOEXCEPT { |
500 | | __first_ |= __v.__first_; |
501 | | } |
502 | | |
503 | | template <size_t _Size> |
504 | | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void |
505 | | __bitset<1, _Size>::operator^=(const __bitset& __v) _NOEXCEPT { |
506 | | __first_ ^= __v.__first_; |
507 | | } |
508 | | |
509 | | template <size_t _Size> |
510 | | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void __bitset<1, _Size>::flip() _NOEXCEPT { |
511 | | __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size); |
512 | | __first_ = ~__first_; |
513 | | __first_ &= __m; |
514 | | } |
515 | | |
516 | | template <size_t _Size> |
517 | | inline _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long __bitset<1, _Size>::to_ulong() const { |
518 | | return __first_; |
519 | | } |
520 | | |
521 | | template <size_t _Size> |
522 | | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long __bitset<1, _Size>::to_ullong() const { |
523 | | return __first_; |
524 | | } |
525 | | |
526 | | template <size_t _Size> |
527 | | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool __bitset<1, _Size>::all() const _NOEXCEPT { |
528 | | __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size); |
529 | | return !(~__first_ & __m); |
530 | | } |
531 | | |
532 | | template <size_t _Size> |
533 | | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool __bitset<1, _Size>::any() const _NOEXCEPT { |
534 | | __storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size); |
535 | | return __first_ & __m; |
536 | | } |
537 | | |
538 | | template <size_t _Size> |
539 | | inline size_t __bitset<1, _Size>::__hash_code() const _NOEXCEPT { |
540 | | return __first_; |
541 | | } |
542 | | |
543 | | template <> |
544 | | class __bitset<0, 0> { |
545 | | public: |
546 | | typedef ptrdiff_t difference_type; |
547 | | typedef size_t size_type; |
548 | | typedef size_type __storage_type; |
549 | | |
550 | | protected: |
551 | | typedef __bitset __self; |
552 | | typedef __storage_type* __storage_pointer; |
553 | | typedef const __storage_type* __const_storage_pointer; |
554 | | static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT); |
555 | | |
556 | | friend class __bit_reference<__bitset>; |
557 | | friend class __bit_const_reference<__bitset>; |
558 | | friend class __bit_iterator<__bitset, false>; |
559 | | friend class __bit_iterator<__bitset, true>; |
560 | | friend struct __bit_array<__bitset>; |
561 | | |
562 | | typedef __bit_reference<__bitset> reference; |
563 | | typedef __bit_const_reference<__bitset> const_reference; |
564 | | typedef __bit_iterator<__bitset, false> iterator; |
565 | | typedef __bit_iterator<__bitset, true> const_iterator; |
566 | | |
567 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT; |
568 | | _LIBCPP_HIDE_FROM_ABI explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long) _NOEXCEPT; |
569 | | |
570 | 0 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 reference __make_ref(size_t) _NOEXCEPT { |
571 | 0 | return reference(nullptr, 1); |
572 | 0 | } |
573 | 0 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const_reference __make_ref(size_t) const _NOEXCEPT { |
574 | 0 | return const_reference(nullptr, 1); |
575 | 0 | } |
576 | 0 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 iterator __make_iter(size_t) _NOEXCEPT { |
577 | 0 | return iterator(nullptr, 0); |
578 | 0 | } |
579 | 0 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 const_iterator __make_iter(size_t) const _NOEXCEPT { |
580 | 0 | return const_iterator(nullptr, 0); |
581 | 0 | } |
582 | | |
583 | 0 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator&=(const __bitset&) _NOEXCEPT {} |
584 | 0 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator|=(const __bitset&) _NOEXCEPT {} |
585 | 0 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator^=(const __bitset&) _NOEXCEPT {} |
586 | | |
587 | 0 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void flip() _NOEXCEPT {} |
588 | | |
589 | 0 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong() const { return 0; } |
590 | 0 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong() const { return 0; } |
591 | | |
592 | 0 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT { return true; } |
593 | 0 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT { return false; } |
594 | | |
595 | 0 | _LIBCPP_HIDE_FROM_ABI size_t __hash_code() const _NOEXCEPT { return 0; } |
596 | | }; |
597 | | |
598 | | inline _LIBCPP_CONSTEXPR __bitset<0, 0>::__bitset() _NOEXCEPT {} |
599 | | |
600 | | inline _LIBCPP_CONSTEXPR __bitset<0, 0>::__bitset(unsigned long long) _NOEXCEPT {} |
601 | | |
602 | | template <size_t _Size> |
603 | | class _LIBCPP_TEMPLATE_VIS bitset; |
604 | | template <size_t _Size> |
605 | | struct hash<bitset<_Size> >; |
606 | | |
607 | | template <size_t _Size> |
608 | | class _LIBCPP_TEMPLATE_VIS bitset |
609 | | : private __bitset<_Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1, _Size> { |
610 | | public: |
611 | | static const unsigned __n_words = _Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1; |
612 | | typedef __bitset<__n_words, _Size> base; |
613 | | |
614 | | public: |
615 | | typedef typename base::reference reference; |
616 | | typedef typename base::const_reference const_reference; |
617 | | |
618 | | // 23.3.5.1 constructors: |
619 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bitset() _NOEXCEPT {} |
620 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bitset(unsigned long long __v) _NOEXCEPT : base(__v) {} |
621 | | template <class _CharT, class = __enable_if_t<_IsCharLikeType<_CharT>::value> > |
622 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 explicit bitset( |
623 | | const _CharT* __str, |
624 | | #if _LIBCPP_STD_VER >= 26 |
625 | | typename basic_string_view<_CharT>::size_type __n = basic_string_view<_CharT>::npos, |
626 | | #else |
627 | | typename basic_string<_CharT>::size_type __n = basic_string<_CharT>::npos, |
628 | | #endif |
629 | | _CharT __zero = _CharT('0'), |
630 | | _CharT __one = _CharT('1')) { |
631 | | |
632 | | size_t __rlen = std::min(__n, char_traits<_CharT>::length(__str)); |
633 | | __init_from_string_view(basic_string_view<_CharT>(__str, __rlen), __zero, __one); |
634 | | } |
635 | | #if _LIBCPP_STD_VER >= 26 |
636 | | template <class _CharT, class _Traits> |
637 | | _LIBCPP_HIDE_FROM_ABI constexpr explicit bitset( |
638 | | basic_string_view<_CharT, _Traits> __str, |
639 | | typename basic_string_view<_CharT, _Traits>::size_type __pos = 0, |
640 | | typename basic_string_view<_CharT, _Traits>::size_type __n = basic_string_view<_CharT, _Traits>::npos, |
641 | | _CharT __zero = _CharT('0'), |
642 | | _CharT __one = _CharT('1')) { |
643 | | if (__pos > __str.size()) |
644 | | __throw_out_of_range("bitset string pos out of range"); |
645 | | |
646 | | size_t __rlen = std::min(__n, __str.size() - __pos); |
647 | | __init_from_string_view(basic_string_view<_CharT, _Traits>(__str.data() + __pos, __rlen), __zero, __one); |
648 | | } |
649 | | #endif |
650 | | template <class _CharT, class _Traits, class _Allocator> |
651 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 explicit bitset( |
652 | | const basic_string<_CharT, _Traits, _Allocator>& __str, |
653 | | typename basic_string<_CharT, _Traits, _Allocator>::size_type __pos = 0, |
654 | | typename basic_string<_CharT, _Traits, _Allocator>::size_type __n = |
655 | | basic_string<_CharT, _Traits, _Allocator>::npos, |
656 | | _CharT __zero = _CharT('0'), |
657 | | _CharT __one = _CharT('1')) { |
658 | | if (__pos > __str.size()) |
659 | | std::__throw_out_of_range("bitset string pos out of range"); |
660 | | |
661 | | size_t __rlen = std::min(__n, __str.size() - __pos); |
662 | | __init_from_string_view(basic_string_view<_CharT, _Traits>(__str.data() + __pos, __rlen), __zero, __one); |
663 | | } |
664 | | |
665 | | // 23.3.5.2 bitset operations: |
666 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& operator&=(const bitset& __rhs) _NOEXCEPT; |
667 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& operator|=(const bitset& __rhs) _NOEXCEPT; |
668 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& operator^=(const bitset& __rhs) _NOEXCEPT; |
669 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& operator<<=(size_t __pos) _NOEXCEPT; |
670 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& operator>>=(size_t __pos) _NOEXCEPT; |
671 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& set() _NOEXCEPT; |
672 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& set(size_t __pos, bool __val = true); |
673 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& reset() _NOEXCEPT; |
674 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& reset(size_t __pos); |
675 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset operator~() const _NOEXCEPT; |
676 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& flip() _NOEXCEPT; |
677 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset& flip(size_t __pos); |
678 | | |
679 | | // element access: |
680 | | #ifdef _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL |
681 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool operator[](size_t __p) const { return base::__make_ref(__p); } |
682 | | #else |
683 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const_reference operator[](size_t __p) const { return base::__make_ref(__p); } |
684 | | #endif |
685 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 reference operator[](size_t __p) { return base::__make_ref(__p); } |
686 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long to_ulong() const; |
687 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long to_ullong() const; |
688 | | template <class _CharT, class _Traits, class _Allocator> |
689 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, _Traits, _Allocator> |
690 | | to_string(_CharT __zero = _CharT('0'), _CharT __one = _CharT('1')) const; |
691 | | template <class _CharT, class _Traits> |
692 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, _Traits, allocator<_CharT> > |
693 | | to_string(_CharT __zero = _CharT('0'), _CharT __one = _CharT('1')) const; |
694 | | template <class _CharT> |
695 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > |
696 | | to_string(_CharT __zero = _CharT('0'), _CharT __one = _CharT('1')) const; |
697 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<char, char_traits<char>, allocator<char> > |
698 | | to_string(char __zero = '0', char __one = '1') const; |
699 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 size_t count() const _NOEXCEPT; |
700 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR size_t size() const _NOEXCEPT { return _Size; } |
701 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool operator==(const bitset& __rhs) const _NOEXCEPT; |
702 | | #if _LIBCPP_STD_VER <= 17 |
703 | | _LIBCPP_HIDE_FROM_ABI bool operator!=(const bitset& __rhs) const _NOEXCEPT; |
704 | | #endif |
705 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool test(size_t __pos) const; |
706 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool all() const _NOEXCEPT; |
707 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool any() const _NOEXCEPT; |
708 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool none() const _NOEXCEPT { return !any(); } |
709 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset operator<<(size_t __pos) const _NOEXCEPT; |
710 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset operator>>(size_t __pos) const _NOEXCEPT; |
711 | | |
712 | | private: |
713 | | template <class _CharT, class _Traits> |
714 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void |
715 | | __init_from_string_view(basic_string_view<_CharT, _Traits> __str, _CharT __zero, _CharT __one) { |
716 | | for (size_t __i = 0; __i < __str.size(); ++__i) |
717 | | if (!_Traits::eq(__str[__i], __zero) && !_Traits::eq(__str[__i], __one)) |
718 | | std::__throw_invalid_argument("bitset string ctor has invalid argument"); |
719 | | |
720 | | size_t __mp = std::min(__str.size(), _Size); |
721 | | size_t __i = 0; |
722 | | for (; __i < __mp; ++__i) { |
723 | | _CharT __c = __str[__mp - 1 - __i]; |
724 | | (*this)[__i] = _Traits::eq(__c, __one); |
725 | | } |
726 | | std::fill(base::__make_iter(__i), base::__make_iter(_Size), false); |
727 | | } |
728 | | |
729 | | _LIBCPP_HIDE_FROM_ABI size_t __hash_code() const _NOEXCEPT { return base::__hash_code(); } |
730 | | |
731 | | friend struct hash<bitset>; |
732 | | }; |
733 | | |
734 | | template <size_t _Size> |
735 | | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& |
736 | | bitset<_Size>::operator&=(const bitset& __rhs) _NOEXCEPT { |
737 | | base::operator&=(__rhs); |
738 | | return *this; |
739 | | } |
740 | | |
741 | | template <size_t _Size> |
742 | | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& |
743 | | bitset<_Size>::operator|=(const bitset& __rhs) _NOEXCEPT { |
744 | | base::operator|=(__rhs); |
745 | | return *this; |
746 | | } |
747 | | |
748 | | template <size_t _Size> |
749 | | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& |
750 | | bitset<_Size>::operator^=(const bitset& __rhs) _NOEXCEPT { |
751 | | base::operator^=(__rhs); |
752 | | return *this; |
753 | | } |
754 | | |
755 | | template <size_t _Size> |
756 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::operator<<=(size_t __pos) _NOEXCEPT { |
757 | | __pos = std::min(__pos, _Size); |
758 | | std::copy_backward(base::__make_iter(0), base::__make_iter(_Size - __pos), base::__make_iter(_Size)); |
759 | | std::fill_n(base::__make_iter(0), __pos, false); |
760 | | return *this; |
761 | | } |
762 | | |
763 | | template <size_t _Size> |
764 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::operator>>=(size_t __pos) _NOEXCEPT { |
765 | | __pos = std::min(__pos, _Size); |
766 | | std::copy(base::__make_iter(__pos), base::__make_iter(_Size), base::__make_iter(0)); |
767 | | std::fill_n(base::__make_iter(_Size - __pos), __pos, false); |
768 | | return *this; |
769 | | } |
770 | | |
771 | | template <size_t _Size> |
772 | | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::set() _NOEXCEPT { |
773 | | std::fill_n(base::__make_iter(0), _Size, true); |
774 | | return *this; |
775 | | } |
776 | | |
777 | | template <size_t _Size> |
778 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::set(size_t __pos, bool __val) { |
779 | | if (__pos >= _Size) |
780 | | __throw_out_of_range("bitset set argument out of range"); |
781 | | |
782 | | (*this)[__pos] = __val; |
783 | | return *this; |
784 | | } |
785 | | |
786 | | template <size_t _Size> |
787 | | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::reset() _NOEXCEPT { |
788 | | std::fill_n(base::__make_iter(0), _Size, false); |
789 | | return *this; |
790 | | } |
791 | | |
792 | | template <size_t _Size> |
793 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::reset(size_t __pos) { |
794 | | if (__pos >= _Size) |
795 | | __throw_out_of_range("bitset reset argument out of range"); |
796 | | |
797 | | (*this)[__pos] = false; |
798 | | return *this; |
799 | | } |
800 | | |
801 | | template <size_t _Size> |
802 | | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size> bitset<_Size>::operator~() const _NOEXCEPT { |
803 | | bitset __x(*this); |
804 | | __x.flip(); |
805 | | return __x; |
806 | | } |
807 | | |
808 | | template <size_t _Size> |
809 | | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::flip() _NOEXCEPT { |
810 | | base::flip(); |
811 | | return *this; |
812 | | } |
813 | | |
814 | | template <size_t _Size> |
815 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size>& bitset<_Size>::flip(size_t __pos) { |
816 | | if (__pos >= _Size) |
817 | | __throw_out_of_range("bitset flip argument out of range"); |
818 | | |
819 | | reference __r = base::__make_ref(__pos); |
820 | | __r = ~__r; |
821 | | return *this; |
822 | | } |
823 | | |
824 | | template <size_t _Size> |
825 | | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long bitset<_Size>::to_ulong() const { |
826 | | return base::to_ulong(); |
827 | | } |
828 | | |
829 | | template <size_t _Size> |
830 | | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unsigned long long bitset<_Size>::to_ullong() const { |
831 | | return base::to_ullong(); |
832 | | } |
833 | | |
834 | | template <size_t _Size> |
835 | | template <class _CharT, class _Traits, class _Allocator> |
836 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, _Traits, _Allocator> |
837 | | bitset<_Size>::to_string(_CharT __zero, _CharT __one) const { |
838 | | basic_string<_CharT, _Traits, _Allocator> __r(_Size, __zero); |
839 | | for (size_t __i = 0; __i != _Size; ++__i) { |
840 | | if ((*this)[__i]) |
841 | | __r[_Size - 1 - __i] = __one; |
842 | | } |
843 | | return __r; |
844 | | } |
845 | | |
846 | | template <size_t _Size> |
847 | | template <class _CharT, class _Traits> |
848 | | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, _Traits, allocator<_CharT> > |
849 | | bitset<_Size>::to_string(_CharT __zero, _CharT __one) const { |
850 | | return to_string<_CharT, _Traits, allocator<_CharT> >(__zero, __one); |
851 | | } |
852 | | |
853 | | template <size_t _Size> |
854 | | template <class _CharT> |
855 | | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > |
856 | | bitset<_Size>::to_string(_CharT __zero, _CharT __one) const { |
857 | | return to_string<_CharT, char_traits<_CharT>, allocator<_CharT> >(__zero, __one); |
858 | | } |
859 | | |
860 | | template <size_t _Size> |
861 | | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 basic_string<char, char_traits<char>, allocator<char> > |
862 | | bitset<_Size>::to_string(char __zero, char __one) const { |
863 | | return to_string<char, char_traits<char>, allocator<char> >(__zero, __one); |
864 | | } |
865 | | |
866 | | template <size_t _Size> |
867 | | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 size_t bitset<_Size>::count() const _NOEXCEPT { |
868 | | return static_cast<size_t>(std::count(base::__make_iter(0), base::__make_iter(_Size), true)); |
869 | | } |
870 | | |
871 | | template <size_t _Size> |
872 | | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool |
873 | | bitset<_Size>::operator==(const bitset& __rhs) const _NOEXCEPT { |
874 | | return std::equal(base::__make_iter(0), base::__make_iter(_Size), __rhs.__make_iter(0)); |
875 | | } |
876 | | |
877 | | #if _LIBCPP_STD_VER <= 17 |
878 | | |
879 | | template <size_t _Size> |
880 | | inline _LIBCPP_HIDE_FROM_ABI bool bitset<_Size>::operator!=(const bitset& __rhs) const _NOEXCEPT { |
881 | | return !(*this == __rhs); |
882 | | } |
883 | | |
884 | | #endif |
885 | | |
886 | | template <size_t _Size> |
887 | | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool bitset<_Size>::test(size_t __pos) const { |
888 | | if (__pos >= _Size) |
889 | | __throw_out_of_range("bitset test argument out of range"); |
890 | | |
891 | | return (*this)[__pos]; |
892 | | } |
893 | | |
894 | | template <size_t _Size> |
895 | | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool bitset<_Size>::all() const _NOEXCEPT { |
896 | | return base::all(); |
897 | | } |
898 | | |
899 | | template <size_t _Size> |
900 | | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool bitset<_Size>::any() const _NOEXCEPT { |
901 | | return base::any(); |
902 | | } |
903 | | |
904 | | template <size_t _Size> |
905 | | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size> |
906 | | bitset<_Size>::operator<<(size_t __pos) const _NOEXCEPT { |
907 | | bitset __r = *this; |
908 | | __r <<= __pos; |
909 | | return __r; |
910 | | } |
911 | | |
912 | | template <size_t _Size> |
913 | | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size> |
914 | | bitset<_Size>::operator>>(size_t __pos) const _NOEXCEPT { |
915 | | bitset __r = *this; |
916 | | __r >>= __pos; |
917 | | return __r; |
918 | | } |
919 | | |
920 | | template <size_t _Size> |
921 | | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size> |
922 | | operator&(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT { |
923 | | bitset<_Size> __r = __x; |
924 | | __r &= __y; |
925 | | return __r; |
926 | | } |
927 | | |
928 | | template <size_t _Size> |
929 | | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size> |
930 | | operator|(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT { |
931 | | bitset<_Size> __r = __x; |
932 | | __r |= __y; |
933 | | return __r; |
934 | | } |
935 | | |
936 | | template <size_t _Size> |
937 | | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bitset<_Size> |
938 | | operator^(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT { |
939 | | bitset<_Size> __r = __x; |
940 | | __r ^= __y; |
941 | | return __r; |
942 | | } |
943 | | |
944 | | template <size_t _Size> |
945 | | struct _LIBCPP_TEMPLATE_VIS hash<bitset<_Size> > : public __unary_function<bitset<_Size>, size_t> { |
946 | | _LIBCPP_HIDE_FROM_ABI size_t operator()(const bitset<_Size>& __bs) const _NOEXCEPT { return __bs.__hash_code(); } |
947 | | }; |
948 | | |
949 | | template <class _CharT, class _Traits, size_t _Size> |
950 | | _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>& |
951 | | operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x); |
952 | | |
953 | | template <class _CharT, class _Traits, size_t _Size> |
954 | | _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& |
955 | | operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x); |
956 | | |
957 | | _LIBCPP_END_NAMESPACE_STD |
958 | | |
959 | | _LIBCPP_POP_MACROS |
960 | | |
961 | | #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 |
962 | | # include <concepts> |
963 | | # include <cstdlib> |
964 | | # include <type_traits> |
965 | | #endif |
966 | | |
967 | | #endif // _LIBCPP_BITSET |