libstdc++
bitset
Go to the documentation of this file.
1// <bitset> -*- C++ -*-
2
3// Copyright (C) 2001-2026 Free Software Foundation, Inc.
4//
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 3, or (at your option)
9// any later version.
10
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// Under Section 7 of GPL version 3, you are granted additional
17// permissions described in the GCC Runtime Library Exception, version
18// 3.1, as published by the Free Software Foundation.
19
20// You should have received a copy of the GNU General Public License and
21// a copy of the GCC Runtime Library Exception along with this program;
22// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23// <http://www.gnu.org/licenses/>.
24
25/*
26 * Copyright (c) 1998
27 * Silicon Graphics Computer Systems, Inc.
28 *
29 * Permission to use, copy, modify, distribute and sell this software
30 * and its documentation for any purpose is hereby granted without fee,
31 * provided that the above copyright notice appear in all copies and
32 * that both that copyright notice and this permission notice appear
33 * in supporting documentation. Silicon Graphics makes no
34 * representations about the suitability of this software for any
35 * purpose. It is provided "as is" without express or implied warranty.
36 */
37
38/** @file include/bitset
39 * This is a Standard C++ Library header.
40 */
41
42#ifndef _GLIBCXX_BITSET
43#define _GLIBCXX_BITSET 1
44
45#ifdef _GLIBCXX_SYSHDR
46#pragma GCC system_header
47#endif
48
49#include <bits/stdexcept_throw.h> // For invalid_argument, out_of_range,
50 // overflow_error
51#include <bits/stl_algobase.h> // For std::fill
52
53#if _GLIBCXX_HOSTED
54# include <string>
55# include <iosfwd>
56# include <bits/cxxabi_forced.h>
57#endif
58
59#if __cplusplus >= 201103L
60# include <bits/functional_hash.h>
61#endif
62
63#define __glibcxx_want_constexpr_bitset
64#define __glibcxx_want_bitset // ...construct from string_view
65#define __glibcxx_want_hardened_bitset
66#include <bits/version.h>
67
68#ifdef __cpp_lib_bitset // ...construct from string_view
69# include <string_view>
70#endif
71
72#define _GLIBCXX_BITSET_BITS_PER_WORD (__CHAR_BIT__ * __SIZEOF_LONG__)
73#define _GLIBCXX_BITSET_WORDS(__n) \
74 ((__n) / _GLIBCXX_BITSET_BITS_PER_WORD + \
75 ((__n) % _GLIBCXX_BITSET_BITS_PER_WORD == 0 ? 0 : 1))
76
77#define _GLIBCXX_BITSET_BITS_PER_ULL (__CHAR_BIT__ * __SIZEOF_LONG_LONG__)
78
79namespace std _GLIBCXX_VISIBILITY(default)
80{
81_GLIBCXX_BEGIN_NAMESPACE_CONTAINER
82
83 /**
84 * Base class, general case. It is a class invariant that _Nw will be
85 * nonnegative.
86 *
87 * See documentation for bitset.
88 */
89 template<size_t _Nw>
90 struct _Base_bitset
91 {
92 typedef unsigned long _WordT;
93
94 /// 0 is the least significant word.
95 _WordT _M_w[_Nw];
96
97 _GLIBCXX_CONSTEXPR _Base_bitset() _GLIBCXX_NOEXCEPT
98 : _M_w() { }
99
100#if __cplusplus >= 201103L
101 constexpr _Base_bitset(unsigned long long __val) noexcept
102 : _M_w{ _WordT(__val)
103#if __SIZEOF_LONG_LONG__ > __SIZEOF_LONG__
104 , _WordT(__val >> _GLIBCXX_BITSET_BITS_PER_WORD)
105#endif
106 } { }
107#else
108 _Base_bitset(unsigned long __val)
109 : _M_w()
110 { _M_w[0] = __val; }
111#endif
112
113 static _GLIBCXX_CONSTEXPR size_t
114 _S_whichword(size_t __pos) _GLIBCXX_NOEXCEPT
115 { return __pos / _GLIBCXX_BITSET_BITS_PER_WORD; }
116
117 static _GLIBCXX_CONSTEXPR size_t
118 _S_whichbyte(size_t __pos) _GLIBCXX_NOEXCEPT
119 { return (__pos % _GLIBCXX_BITSET_BITS_PER_WORD) / __CHAR_BIT__; }
120
121 static _GLIBCXX_CONSTEXPR size_t
122 _S_whichbit(size_t __pos) _GLIBCXX_NOEXCEPT
123 { return __pos % _GLIBCXX_BITSET_BITS_PER_WORD; }
124
125 static _GLIBCXX_CONSTEXPR _WordT
126 _S_maskbit(size_t __pos) _GLIBCXX_NOEXCEPT
127 { return (static_cast<_WordT>(1)) << _S_whichbit(__pos); }
128
129 _GLIBCXX14_CONSTEXPR _WordT&
130 _M_getword(size_t __pos) _GLIBCXX_NOEXCEPT
131 { return _M_w[_S_whichword(__pos)]; }
132
133 _GLIBCXX_CONSTEXPR _WordT
134 _M_getword(size_t __pos) const _GLIBCXX_NOEXCEPT
135 { return _M_w[_S_whichword(__pos)]; }
136
137#if __cplusplus >= 201103L
138 constexpr const _WordT*
139 _M_getdata() const noexcept
140 { return _M_w; }
141#endif
142
143 _GLIBCXX23_CONSTEXPR _WordT&
144 _M_hiword() _GLIBCXX_NOEXCEPT
145 { return _M_w[_Nw - 1]; }
146
147 _GLIBCXX_CONSTEXPR _WordT
148 _M_hiword() const _GLIBCXX_NOEXCEPT
149 { return _M_w[_Nw - 1]; }
150
151 _GLIBCXX23_CONSTEXPR void
152 _M_do_and(const _Base_bitset<_Nw>& __x) _GLIBCXX_NOEXCEPT
153 {
154 for (size_t __i = 0; __i < _Nw; __i++)
155 _M_w[__i] &= __x._M_w[__i];
156 }
157
158 _GLIBCXX14_CONSTEXPR void
159 _M_do_or(const _Base_bitset<_Nw>& __x) _GLIBCXX_NOEXCEPT
160 {
161 for (size_t __i = 0; __i < _Nw; __i++)
162 _M_w[__i] |= __x._M_w[__i];
163 }
164
165 _GLIBCXX14_CONSTEXPR void
166 _M_do_xor(const _Base_bitset<_Nw>& __x) _GLIBCXX_NOEXCEPT
167 {
168 for (size_t __i = 0; __i < _Nw; __i++)
169 _M_w[__i] ^= __x._M_w[__i];
170 }
171
172 _GLIBCXX14_CONSTEXPR void
173 _M_do_left_shift(size_t __shift) _GLIBCXX_NOEXCEPT;
174
175 _GLIBCXX14_CONSTEXPR void
176 _M_do_right_shift(size_t __shift) _GLIBCXX_NOEXCEPT;
177
178 _GLIBCXX14_CONSTEXPR void
179 _M_do_flip() _GLIBCXX_NOEXCEPT
180 {
181 for (size_t __i = 0; __i < _Nw; __i++)
182 _M_w[__i] = ~_M_w[__i];
183 }
184
185 _GLIBCXX14_CONSTEXPR void
186 _M_do_set() _GLIBCXX_NOEXCEPT
187 {
188#if __cplusplus >= 201402L
189 if (__builtin_is_constant_evaluated())
190 {
191 for (_WordT& __w : _M_w)
192 __w = ~static_cast<_WordT>(0);;
193 return;
194 }
195#endif
196 __builtin_memset(_M_w, 0xFF, _Nw * sizeof(_WordT));
197 }
198
199 _GLIBCXX14_CONSTEXPR void
200 _M_do_reset() _GLIBCXX_NOEXCEPT
201 {
202#if __cplusplus >= 201402L
203 if (__builtin_is_constant_evaluated())
204 {
205 for (_WordT& __w : _M_w)
206 __w = 0;
207 return;
208 }
209#endif
210 __builtin_memset(_M_w, 0, _Nw * sizeof(_WordT));
211 }
212
213 _GLIBCXX14_CONSTEXPR bool
214 _M_is_equal(const _Base_bitset<_Nw>& __x) const _GLIBCXX_NOEXCEPT
215 {
216#if __cplusplus >= 201402L
217 if (__builtin_is_constant_evaluated())
218 {
219 for (size_t __i = 0; __i < _Nw; ++__i)
220 if (_M_w[__i] != __x._M_w[__i])
221 return false;
222 return true;
223 }
224#endif
225 return !__builtin_memcmp(_M_w, __x._M_w, _Nw * sizeof(_WordT));
226 }
227
228 template<size_t _Nb>
229 _GLIBCXX14_CONSTEXPR bool
230 _M_are_all() const _GLIBCXX_NOEXCEPT
231 {
232 for (size_t __i = 0; __i < _Nw - 1; __i++)
233 if (_M_w[__i] != ~static_cast<_WordT>(0))
234 return false;
235 return _M_hiword() == (~static_cast<_WordT>(0)
236 >> (_Nw * _GLIBCXX_BITSET_BITS_PER_WORD
237 - _Nb));
238 }
239
240 _GLIBCXX14_CONSTEXPR bool
241 _M_is_any() const _GLIBCXX_NOEXCEPT
242 {
243 for (size_t __i = 0; __i < _Nw; __i++)
244 if (_M_w[__i] != static_cast<_WordT>(0))
245 return true;
246 return false;
247 }
248
249 _GLIBCXX14_CONSTEXPR size_t
250 _M_do_count() const _GLIBCXX_NOEXCEPT
251 {
252 size_t __result = 0;
253 for (size_t __i = 0; __i < _Nw; __i++)
254 __result += __builtin_popcountl(_M_w[__i]);
255 return __result;
256 }
257
258 _GLIBCXX14_CONSTEXPR unsigned long
259 _M_do_to_ulong() const;
260
261#if __cplusplus >= 201103L
262 _GLIBCXX14_CONSTEXPR unsigned long long
263 _M_do_to_ullong() const;
264#endif
265
266 // find first "on" bit
267 _GLIBCXX14_CONSTEXPR size_t
268 _M_do_find_first(size_t) const _GLIBCXX_NOEXCEPT;
269
270 // find the next "on" bit that follows "prev"
271 _GLIBCXX14_CONSTEXPR size_t
272 _M_do_find_next(size_t, size_t) const _GLIBCXX_NOEXCEPT;
273 };
274
275 // Definitions of non-inline functions from _Base_bitset.
276 template<size_t _Nw>
277 _GLIBCXX14_CONSTEXPR void
278 _Base_bitset<_Nw>::_M_do_left_shift(size_t __shift) _GLIBCXX_NOEXCEPT
279 {
280 if (__builtin_expect(__shift != 0, 1))
281 {
282 const size_t __wshift = __shift / _GLIBCXX_BITSET_BITS_PER_WORD;
283 const size_t __offset = __shift % _GLIBCXX_BITSET_BITS_PER_WORD;
284
285 if (__offset == 0)
286 for (size_t __n = _Nw - 1; __n >= __wshift; --__n)
287 _M_w[__n] = _M_w[__n - __wshift];
288 else
289 {
290 const size_t __sub_offset = (_GLIBCXX_BITSET_BITS_PER_WORD
291 - __offset);
292 for (size_t __n = _Nw - 1; __n > __wshift; --__n)
293 _M_w[__n] = ((_M_w[__n - __wshift] << __offset)
294 | (_M_w[__n - __wshift - 1] >> __sub_offset));
295 _M_w[__wshift] = _M_w[0] << __offset;
296 }
297
298 std::fill(_M_w + 0, _M_w + __wshift, static_cast<_WordT>(0));
299 }
300 }
301
302 template<size_t _Nw>
303 _GLIBCXX14_CONSTEXPR void
304 _Base_bitset<_Nw>::_M_do_right_shift(size_t __shift) _GLIBCXX_NOEXCEPT
305 {
306 if (__builtin_expect(__shift != 0, 1))
307 {
308 const size_t __wshift = __shift / _GLIBCXX_BITSET_BITS_PER_WORD;
309 const size_t __offset = __shift % _GLIBCXX_BITSET_BITS_PER_WORD;
310 const size_t __limit = _Nw - __wshift - 1;
311
312 if (__offset == 0)
313 for (size_t __n = 0; __n <= __limit; ++__n)
314 _M_w[__n] = _M_w[__n + __wshift];
315 else
316 {
317 const size_t __sub_offset = (_GLIBCXX_BITSET_BITS_PER_WORD
318 - __offset);
319 for (size_t __n = 0; __n < __limit; ++__n)
320 _M_w[__n] = ((_M_w[__n + __wshift] >> __offset)
321 | (_M_w[__n + __wshift + 1] << __sub_offset));
322 _M_w[__limit] = _M_w[_Nw-1] >> __offset;
323 }
324
325 std::fill(_M_w + __limit + 1, _M_w + _Nw, static_cast<_WordT>(0));
326 }
327 }
328
329 template<size_t _Nw>
330 _GLIBCXX14_CONSTEXPR unsigned long
331 _Base_bitset<_Nw>::_M_do_to_ulong() const
332 {
333 for (size_t __i = 1; __i < _Nw; ++__i)
334 if (_M_w[__i])
335 __throw_overflow_error(__N("_Base_bitset::_M_do_to_ulong"));
336 return _M_w[0];
337 }
338
339#if __cplusplus >= 201103L
340 template<size_t _Nw>
341 _GLIBCXX14_CONSTEXPR unsigned long long
342 _Base_bitset<_Nw>::_M_do_to_ullong() const
343 {
344#if __SIZEOF_LONG_LONG__ == __SIZEOF_LONG__
345 return _M_do_to_ulong();
346#else
347 for (size_t __i = 2; __i < _Nw; ++__i)
348 if (_M_w[__i])
349 __throw_overflow_error(__N("_Base_bitset::_M_do_to_ullong"));
350
351 return _M_w[0] + (static_cast<unsigned long long>(_M_w[1])
352 << _GLIBCXX_BITSET_BITS_PER_WORD);
353#endif
354 }
355#endif // C++11
356
357 template<size_t _Nw>
358 _GLIBCXX14_CONSTEXPR size_t
360 _M_do_find_first(size_t __not_found) const _GLIBCXX_NOEXCEPT
361 {
362 for (size_t __i = 0; __i < _Nw; __i++)
363 {
364 _WordT __thisword = _M_w[__i];
365 if (__thisword != static_cast<_WordT>(0))
366 return (__i * _GLIBCXX_BITSET_BITS_PER_WORD
367 + __builtin_ctzl(__thisword));
368 }
369 // not found, so return an indication of failure.
370 return __not_found;
371 }
372
373 template<size_t _Nw>
374 _GLIBCXX14_CONSTEXPR size_t
376 _M_do_find_next(size_t __prev, size_t __not_found) const _GLIBCXX_NOEXCEPT
377 {
378 // make bound inclusive
379 ++__prev;
380
381 // check out of bounds
382 if (__prev >= _Nw * _GLIBCXX_BITSET_BITS_PER_WORD)
383 return __not_found;
384
385 // search first word
386 size_t __i = _S_whichword(__prev);
387 _WordT __thisword = _M_w[__i];
388
389 // mask off bits below bound
390 __thisword &= (~static_cast<_WordT>(0)) << _S_whichbit(__prev);
391
392 if (__thisword != static_cast<_WordT>(0))
393 return (__i * _GLIBCXX_BITSET_BITS_PER_WORD
394 + __builtin_ctzl(__thisword));
395
396 // check subsequent words
397 __i++;
398 for (; __i < _Nw; __i++)
399 {
400 __thisword = _M_w[__i];
401 if (__thisword != static_cast<_WordT>(0))
402 return (__i * _GLIBCXX_BITSET_BITS_PER_WORD
403 + __builtin_ctzl(__thisword));
404 }
405 // not found, so return an indication of failure.
406 return __not_found;
407 } // end _M_do_find_next
408
409 /**
410 * Base class, specialization for a single word.
411 *
412 * See documentation for bitset.
413 */
414 template<>
415 struct _Base_bitset<1>
416 {
417 typedef unsigned long _WordT;
418 _WordT _M_w;
419
420 _GLIBCXX_CONSTEXPR _Base_bitset() _GLIBCXX_NOEXCEPT
421 : _M_w(0)
422 { }
423
424#if __cplusplus >= 201103L
425 constexpr _Base_bitset(unsigned long long __val) noexcept
426#else
427 _Base_bitset(unsigned long __val)
428#endif
429 : _M_w(__val)
430 { }
431
432 static _GLIBCXX_CONSTEXPR size_t
433 _S_whichword(size_t __pos) _GLIBCXX_NOEXCEPT
434 { return __pos / _GLIBCXX_BITSET_BITS_PER_WORD; }
435
436 static _GLIBCXX_CONSTEXPR size_t
437 _S_whichbyte(size_t __pos) _GLIBCXX_NOEXCEPT
438 { return (__pos % _GLIBCXX_BITSET_BITS_PER_WORD) / __CHAR_BIT__; }
439
440 static _GLIBCXX_CONSTEXPR size_t
441 _S_whichbit(size_t __pos) _GLIBCXX_NOEXCEPT
442 { return __pos % _GLIBCXX_BITSET_BITS_PER_WORD; }
443
444 static _GLIBCXX_CONSTEXPR _WordT
445 _S_maskbit(size_t __pos) _GLIBCXX_NOEXCEPT
446 { return (static_cast<_WordT>(1)) << _S_whichbit(__pos); }
447
448 _GLIBCXX14_CONSTEXPR _WordT&
449 _M_getword(size_t) _GLIBCXX_NOEXCEPT
450 { return _M_w; }
451
452 _GLIBCXX_CONSTEXPR _WordT
453 _M_getword(size_t) const _GLIBCXX_NOEXCEPT
454 { return _M_w; }
455
456#if __cplusplus >= 201103L
457 constexpr const _WordT*
458 _M_getdata() const noexcept
459 { return &_M_w; }
460#endif
461
462 _GLIBCXX14_CONSTEXPR _WordT&
463 _M_hiword() _GLIBCXX_NOEXCEPT
464 { return _M_w; }
465
466 _GLIBCXX_CONSTEXPR _WordT
467 _M_hiword() const _GLIBCXX_NOEXCEPT
468 { return _M_w; }
469
470 _GLIBCXX14_CONSTEXPR void
471 _M_do_and(const _Base_bitset<1>& __x) _GLIBCXX_NOEXCEPT
472 { _M_w &= __x._M_w; }
473
474 _GLIBCXX14_CONSTEXPR void
475 _M_do_or(const _Base_bitset<1>& __x) _GLIBCXX_NOEXCEPT
476 { _M_w |= __x._M_w; }
477
478 _GLIBCXX14_CONSTEXPR void
479 _M_do_xor(const _Base_bitset<1>& __x) _GLIBCXX_NOEXCEPT
480 { _M_w ^= __x._M_w; }
481
482 _GLIBCXX14_CONSTEXPR void
483 _M_do_left_shift(size_t __shift) _GLIBCXX_NOEXCEPT
484 { _M_w <<= __shift; }
485
486 _GLIBCXX14_CONSTEXPR void
487 _M_do_right_shift(size_t __shift) _GLIBCXX_NOEXCEPT
488 { _M_w >>= __shift; }
489
490 _GLIBCXX14_CONSTEXPR void
491 _M_do_flip() _GLIBCXX_NOEXCEPT
492 { _M_w = ~_M_w; }
493
494 _GLIBCXX14_CONSTEXPR void
495 _M_do_set() _GLIBCXX_NOEXCEPT
496 { _M_w = ~static_cast<_WordT>(0); }
497
498 _GLIBCXX14_CONSTEXPR void
499 _M_do_reset() _GLIBCXX_NOEXCEPT
500 { _M_w = 0; }
501
502 _GLIBCXX14_CONSTEXPR bool
503 _M_is_equal(const _Base_bitset<1>& __x) const _GLIBCXX_NOEXCEPT
504 { return _M_w == __x._M_w; }
505
506 template<size_t _Nb>
507 _GLIBCXX14_CONSTEXPR bool
508 _M_are_all() const _GLIBCXX_NOEXCEPT
509 { return _M_w == (~static_cast<_WordT>(0)
510 >> (_GLIBCXX_BITSET_BITS_PER_WORD - _Nb)); }
511
512 _GLIBCXX14_CONSTEXPR bool
513 _M_is_any() const _GLIBCXX_NOEXCEPT
514 { return _M_w != 0; }
515
516 _GLIBCXX14_CONSTEXPR size_t
517 _M_do_count() const _GLIBCXX_NOEXCEPT
518 { return __builtin_popcountl(_M_w); }
519
520 _GLIBCXX14_CONSTEXPR unsigned long
521 _M_do_to_ulong() const _GLIBCXX_NOEXCEPT
522 { return _M_w; }
523
524#if __cplusplus >= 201103L
525 constexpr unsigned long long
526 _M_do_to_ullong() const noexcept
527 { return _M_w; }
528#endif
529
530 _GLIBCXX14_CONSTEXPR size_t
531 _M_do_find_first(size_t __not_found) const _GLIBCXX_NOEXCEPT
532 {
533 if (_M_w != 0)
534 return __builtin_ctzl(_M_w);
535 else
536 return __not_found;
537 }
538
539 // find the next "on" bit that follows "prev"
540 _GLIBCXX14_CONSTEXPR size_t
541 _M_do_find_next(size_t __prev, size_t __not_found) const
542 _GLIBCXX_NOEXCEPT
543 {
544 ++__prev;
545 if (__prev >= ((size_t) _GLIBCXX_BITSET_BITS_PER_WORD))
546 return __not_found;
547
548 _WordT __x = _M_w >> __prev;
549 if (__x != 0)
550 return __builtin_ctzl(__x) + __prev;
551 else
552 return __not_found;
553 }
554 };
555
556 /**
557 * Base class, specialization for no storage (zero-length %bitset).
558 *
559 * See documentation for bitset.
560 */
561 template<>
562 struct _Base_bitset<0>
563 {
564 typedef unsigned long _WordT;
565
566 _GLIBCXX_CONSTEXPR _Base_bitset() _GLIBCXX_NOEXCEPT
567 { }
568
569#if __cplusplus >= 201103L
570 constexpr _Base_bitset(unsigned long long) noexcept
571#else
572 _Base_bitset(unsigned long)
573#endif
574 { }
575
576 static _GLIBCXX_CONSTEXPR size_t
577 _S_whichword(size_t __pos) _GLIBCXX_NOEXCEPT
578 { return __pos / _GLIBCXX_BITSET_BITS_PER_WORD; }
579
580 static _GLIBCXX_CONSTEXPR size_t
581 _S_whichbyte(size_t __pos) _GLIBCXX_NOEXCEPT
582 { return (__pos % _GLIBCXX_BITSET_BITS_PER_WORD) / __CHAR_BIT__; }
583
584 static _GLIBCXX_CONSTEXPR size_t
585 _S_whichbit(size_t __pos) _GLIBCXX_NOEXCEPT
586 { return __pos % _GLIBCXX_BITSET_BITS_PER_WORD; }
587
588 static _GLIBCXX_CONSTEXPR _WordT
589 _S_maskbit(size_t __pos) _GLIBCXX_NOEXCEPT
590 { return (static_cast<_WordT>(1)) << _S_whichbit(__pos); }
591
592 // This would normally give access to the data. The bounds-checking
593 // in the bitset class will prevent the user from getting this far,
594 // but this must fail if the user calls _Unchecked_set directly.
595 // Let's not penalize zero-length users unless they actually
596 // make an unchecked call; all the memory ugliness is therefore
597 // localized to this single should-never-get-this-far function.
598 __attribute__((__noreturn__))
599 _WordT&
600 _M_getword(size_t) _GLIBCXX_NOEXCEPT
601 { __throw_out_of_range(__N("_Base_bitset::_M_getword")); }
602
603 _GLIBCXX_CONSTEXPR _WordT
604 _M_getword(size_t) const _GLIBCXX_NOEXCEPT
605 { return 0; }
606
607 _GLIBCXX_CONSTEXPR _WordT
608 _M_hiword() const _GLIBCXX_NOEXCEPT
609 { return 0; }
610
611 _GLIBCXX14_CONSTEXPR void
612 _M_do_and(const _Base_bitset<0>&) _GLIBCXX_NOEXCEPT
613 { }
614
615 _GLIBCXX14_CONSTEXPR void
616 _M_do_or(const _Base_bitset<0>&) _GLIBCXX_NOEXCEPT
617 { }
618
619 _GLIBCXX14_CONSTEXPR void
620 _M_do_xor(const _Base_bitset<0>&) _GLIBCXX_NOEXCEPT
621 { }
622
623 _GLIBCXX14_CONSTEXPR void
624 _M_do_left_shift(size_t) _GLIBCXX_NOEXCEPT
625 { }
626
627 _GLIBCXX14_CONSTEXPR void
628 _M_do_right_shift(size_t) _GLIBCXX_NOEXCEPT
629 { }
630
631 _GLIBCXX14_CONSTEXPR void
632 _M_do_flip() _GLIBCXX_NOEXCEPT
633 { }
634
635 _GLIBCXX14_CONSTEXPR void
636 _M_do_set() _GLIBCXX_NOEXCEPT
637 { }
638
639 _GLIBCXX14_CONSTEXPR void
640 _M_do_reset() _GLIBCXX_NOEXCEPT
641 { }
642
643 // Are all empty bitsets equal to each other? Are they equal to
644 // themselves? How to compare a thing which has no state? What is
645 // the sound of one zero-length bitset clapping?
646 _GLIBCXX_CONSTEXPR bool
647 _M_is_equal(const _Base_bitset<0>&) const _GLIBCXX_NOEXCEPT
648 { return true; }
649
650 template<size_t _Nb>
651 _GLIBCXX_CONSTEXPR bool
652 _M_are_all() const _GLIBCXX_NOEXCEPT
653 { return true; }
654
655 _GLIBCXX_CONSTEXPR bool
656 _M_is_any() const _GLIBCXX_NOEXCEPT
657 { return false; }
658
659 _GLIBCXX_CONSTEXPR size_t
660 _M_do_count() const _GLIBCXX_NOEXCEPT
661 { return 0; }
662
663 _GLIBCXX_CONSTEXPR unsigned long
664 _M_do_to_ulong() const _GLIBCXX_NOEXCEPT
665 { return 0; }
666
667#if __cplusplus >= 201103L
668 constexpr unsigned long long
669 _M_do_to_ullong() const noexcept
670 { return 0; }
671#endif
672
673 // Normally "not found" is the size, but that could also be
674 // misinterpreted as an index in this corner case. Oh well.
675 _GLIBCXX_CONSTEXPR size_t
676 _M_do_find_first(size_t) const _GLIBCXX_NOEXCEPT
677 { return 0; }
678
679 _GLIBCXX_CONSTEXPR size_t
680 _M_do_find_next(size_t, size_t) const _GLIBCXX_NOEXCEPT
681 { return 0; }
682 };
683
684
685 // Helper class to zero out the unused high-order bits in the highest word.
686 template<size_t _Extrabits>
687 struct _Sanitize
688 {
689 typedef unsigned long _WordT;
690
691 static _GLIBCXX14_CONSTEXPR void
692 _S_do_sanitize(_WordT& __val) _GLIBCXX_NOEXCEPT
693 { __val &= ~((~static_cast<_WordT>(0)) << _Extrabits); }
694 };
695
696 template<>
697 struct _Sanitize<0>
698 {
699 typedef unsigned long _WordT;
700
701 static _GLIBCXX14_CONSTEXPR void
702 _S_do_sanitize(_WordT) _GLIBCXX_NOEXCEPT { }
703 };
704
705#if __cplusplus >= 201103L
706 template<size_t _Nb, bool = (_Nb < _GLIBCXX_BITSET_BITS_PER_ULL)>
707 struct _Sanitize_val
708 {
709 static constexpr unsigned long long
710 _S_do_sanitize_val(unsigned long long __val)
711 { return __val; }
712 };
713
714 template<size_t _Nb>
715 struct _Sanitize_val<_Nb, true>
716 {
717 static constexpr unsigned long long
718 _S_do_sanitize_val(unsigned long long __val)
719 { return __val & ~((~static_cast<unsigned long long>(0)) << _Nb); }
720 };
721
722 namespace __bitset
723 {
724#ifdef __cpp_lib_bitset // ...construct from string_view
725 template<typename _CharT>
726 using __string = std::basic_string_view<_CharT>;
727#elif _GLIBCXX_HOSTED
728 template<typename _CharT>
729 using __string = std::basic_string<_CharT>;
730#else
731 template<typename _CharT>
732 struct __string
733 {
734 using size_type = size_t;
735 static constexpr size_type npos = size_type(-1);
736
737 struct traits_type
738 {
739 static _GLIBCXX14_CONSTEXPR size_t
740 length(const _CharT* __s) noexcept
741 {
742 size_t __n = 0;
743 while (__s[__n])
744 __n++;
745 return __n;
746 }
747
748 static constexpr bool
749 eq(_CharT __l, _CharT __r) noexcept
750 { return __l == __r; }
751 };
752 };
753#endif // HOSTED
754 } // namespace __bitset
755#endif // C++11
756
757 /**
758 * @brief The %bitset class represents a @e fixed-size sequence of bits.
759 * @ingroup utilities
760 *
761 * (Note that %bitset does @e not meet the formal requirements of a
762 * <a href="tables.html#65">container</a>. Mainly, it lacks iterators.)
763 *
764 * The template argument, `Nb`, may be any non-negative number,
765 * specifying the number of bits (e.g., "0", "12", "1024*1024").
766 *
767 * In the general unoptimized case, storage is allocated in word-sized
768 * blocks. Let B be the number of bits in a word, then (Nb+(B-1))/B
769 * words will be used for storage. B - Nb%B bits are unused. (They are
770 * the high-order bits in the highest word.) It is a class invariant
771 * that those unused bits are always zero.
772 *
773 * If you think of %bitset as <em>a simple array of bits</em>, be
774 * aware that your mental picture is reversed: a %bitset behaves
775 * the same way as bits in integers do, with the bit at index 0 in
776 * the <em>least significant / right-hand</em> position, and the bit at
777 * index Nb-1 in the <em>most significant / left-hand</em> position.
778 * Thus, unlike other containers, a %bitset's index <em>counts from
779 * right to left</em>, to put it very loosely.
780 *
781 * This behavior is preserved when translating to and from strings. For
782 * example, the first line of the following program probably prints
783 * <em>b(&apos;a&apos;) is 0001100001</em> on a modern ASCII system.
784 *
785 * @code
786 * #include <bitset>
787 * #include <iostream>
788 * #include <sstream>
789 *
790 * using namespace std;
791 *
792 * int main()
793 * {
794 * long a = 'a';
795 * bitset<10> b(a);
796 *
797 * cout << "b('a') is " << b << endl;
798 *
799 * ostringstream s;
800 * s << b;
801 * string str = s.str();
802 * cout << "index 3 in the string is " << str[3] << " but\n"
803 * << "index 3 in the bitset is " << b[3] << endl;
804 * }
805 * @endcode
806 *
807 * Also see:
808 * https://gcc.gnu.org/onlinedocs/libstdc++/manual/ext_containers.html
809 * for a description of extensions.
810 *
811 * Most of the actual code isn't contained in %bitset<> itself, but in the
812 * base class _Base_bitset. The base class works with whole words, not with
813 * individual bits. This allows us to specialize _Base_bitset for the
814 * important special case where the %bitset is only a single word.
815 *
816 * Extra confusion can result due to the fact that the storage for
817 * _Base_bitset @e is a regular array, and is indexed as such. This is
818 * carefully encapsulated.
819 */
820 template<size_t _Nb>
821 class bitset
822 : private _Base_bitset<_GLIBCXX_BITSET_WORDS(_Nb)>
823 {
824 private:
825 typedef _Base_bitset<_GLIBCXX_BITSET_WORDS(_Nb)> _Base;
826 typedef unsigned long _WordT;
827
828 template<class _Str>
829 _GLIBCXX23_CONSTEXPR void
830 _M_check_initial_position(
831 const _Str& __s, typename _Str::size_type __position) const
832 {
833 if (__position > __s.size())
834 __throw_out_of_range_fmt(
835 __N("bitset::bitset:"
836 " __position (which is %zu) > __s.size() (which is %zu)"),
837 size_t(__position), size_t(__s.size()));
838 }
839
840 _GLIBCXX23_CONSTEXPR
841 void _M_check(size_t __position, const char *__s) const
842 {
843 if (__position >= _Nb)
844 __throw_out_of_range_fmt(
845 __N("%s: __position (which is %zu) >= _Nb (which is %zu)"),
846 __s, size_t(__position), size_t(_Nb));
847 }
848
849 _GLIBCXX23_CONSTEXPR
850 void
851 _M_do_sanitize() _GLIBCXX_NOEXCEPT
852 {
853 typedef _Sanitize<_Nb % _GLIBCXX_BITSET_BITS_PER_WORD> __sanitize_type;
854 __sanitize_type::_S_do_sanitize(this->_M_hiword());
855 }
856
857#if __cplusplus >= 201103L
858 friend struct std::hash<bitset>;
859#endif
860
861 public:
862 /**
863 * This encapsulates the concept of a single bit. An instance of this
864 * class is a proxy for an actual bit; this way the individual bit
865 * operations are done as faster word-size bitwise instructions.
866 *
867 * Most users will never need to use this class directly; conversions
868 * to and from bool are automatic and should be transparent. Overloaded
869 * operators help to preserve the illusion.
870 *
871 * (On a typical system, this <em>bit %reference</em> is 64
872 * times the size of an actual bit. Ha.)
873 */
874 class reference
875 {
876 friend class bitset;
877
878 _WordT* _M_wp;
879 size_t _M_bpos;
880
881 _GLIBCXX23_CONSTEXPR
882 reference(bitset& __b, size_t __pos) _GLIBCXX_NOEXCEPT
883 {
884 _M_wp = &__b._M_getword(__pos);
885 _M_bpos = _Base::_S_whichbit(__pos);
886 }
887
888 public:
889#if __cplusplus >= 201103L
890 reference(const reference&) = default;
891#endif
892
893#if __cplusplus > 202002L && __cpp_constexpr_dynamic_alloc
894 constexpr
895#endif
896 ~reference() _GLIBCXX_NOEXCEPT
897 { }
898
899 // For b[i] = __x;
900 _GLIBCXX23_CONSTEXPR
901 reference&
902 operator=(bool __x) _GLIBCXX_NOEXCEPT
903 {
904 if (__x)
905 *_M_wp |= _Base::_S_maskbit(_M_bpos);
906 else
907 *_M_wp &= ~_Base::_S_maskbit(_M_bpos);
908 return *this;
909 }
910
911#if __glibcxx_ranges_zip // >= C++23
912 // _GLIBCXX_RESOLVE_LIB_DEFECTS
913 // 4187. bitset::reference should be const-assignable
914 constexpr const reference&
915 operator=(bool __x) const noexcept
916 {
917 if (__x)
918 *_M_wp |= _Base::_S_maskbit(_M_bpos);
919 else
920 *_M_wp &= ~_Base::_S_maskbit(_M_bpos);
921 return *this;
922 }
923#endif // C++23
924
925 // For b[i] = b[__j];
926 _GLIBCXX23_CONSTEXPR
927 reference&
928 operator=(const reference& __j) _GLIBCXX_NOEXCEPT
929 {
930 if ((*(__j._M_wp) & _Base::_S_maskbit(__j._M_bpos)))
931 *_M_wp |= _Base::_S_maskbit(_M_bpos);
932 else
933 *_M_wp &= ~_Base::_S_maskbit(_M_bpos);
934 return *this;
935 }
936
937 // Flips the bit
938 _GLIBCXX23_CONSTEXPR
939 bool
940 operator~() const _GLIBCXX_NOEXCEPT
941 { return (*(_M_wp) & _Base::_S_maskbit(_M_bpos)) == 0; }
942
943 // For __x = b[i];
944 _GLIBCXX23_CONSTEXPR
945 operator bool() const _GLIBCXX_NOEXCEPT
946 { return (*(_M_wp) & _Base::_S_maskbit(_M_bpos)) != 0; }
947
948 // For b[i].flip();
949 _GLIBCXX23_CONSTEXPR
950 reference&
951 flip() _GLIBCXX_NOEXCEPT
952 {
953 *_M_wp ^= _Base::_S_maskbit(_M_bpos);
954 return *this;
955 }
956
957#if __cplusplus >= 201103L
958 _GLIBCXX23_CONSTEXPR
959 friend void
960 swap(reference __x, reference __y) noexcept
961 {
962 bool __tmp = __x;
963 __x = __y;
964 __y = __tmp;
965 }
966
967 _GLIBCXX23_CONSTEXPR
968 friend void
969 swap(reference __x, bool& __y) noexcept
970 {
971 bool __tmp = __x;
972 __x = __y;
973 __y = __tmp;
974 }
975
976 _GLIBCXX23_CONSTEXPR
977 friend void
978 swap(bool& __x, reference __y) noexcept
979 {
980 bool __tmp = __x;
981 __x = __y;
982 __y = __tmp;
983 }
984#endif
985 };
986 friend class reference;
987
988 // 23.3.5.1 constructors:
989 /// All bits set to zero.
990 _GLIBCXX_CONSTEXPR bitset() _GLIBCXX_NOEXCEPT
991 { }
992
993 /// Initial bits bitwise-copied from a single word (others set to zero).
994#if __cplusplus >= 201103L
995 constexpr bitset(unsigned long long __val) noexcept
996 : _Base(_Sanitize_val<_Nb>::_S_do_sanitize_val(__val)) { }
997#else
998 bitset(unsigned long __val)
999 : _Base(__val)
1000 { _M_do_sanitize(); }
1001#endif
1002
1003#if _GLIBCXX_HOSTED
1004 /**
1005 * Use a subset of a string.
1006 * @param __s A string of `0` and `1` characters.
1007 * @param __position Index of the first character in `__s` to use;
1008 * defaults to zero.
1009 * @throw std::out_of_range If `__position > __s.size()`.
1010 * @throw std::invalid_argument If a character appears in the string
1011 * which is neither `0` nor `1`.
1012 */
1013 template<class _CharT, class _Traits, class _Alloc>
1014 _GLIBCXX23_CONSTEXPR
1015 explicit
1017 size_t __position = 0)
1018 : _Base()
1019 {
1020 _M_check_initial_position(__s, __position);
1021 _M_copy_from_string(__s, __position,
1023 _CharT('0'), _CharT('1'));
1024 }
1025
1026 /**
1027 * Use a subset of a string.
1028 * @param __s A string of `0` and `1` characters.
1029 * @param __position Index of the first character in `__s` to use.
1030 * @param __n The number of characters to copy.
1031 * @throw std::out_of_range If `__position > __s.size()`.
1032 * @throw std::invalid_argument If a character appears in the string
1033 * which is neither `0` nor `1`.
1034 */
1035 template<class _CharT, class _Traits, class _Alloc>
1036 _GLIBCXX23_CONSTEXPR
1038 size_t __position, size_t __n)
1039 : _Base()
1040 {
1041 _M_check_initial_position(__s, __position);
1042 _M_copy_from_string(__s, __position, __n, _CharT('0'), _CharT('1'));
1043 }
1044
1045 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1046 // 396. what are characters zero and one.
1047 template<class _CharT, class _Traits, class _Alloc>
1048 _GLIBCXX23_CONSTEXPR
1050 size_t __position, size_t __n,
1051 _CharT __zero, _CharT __one = _CharT('1'))
1052 : _Base()
1053 {
1054 _M_check_initial_position(__s, __position);
1055 _M_copy_from_string(__s, __position, __n, __zero, __one);
1056 }
1057#endif // HOSTED
1058
1059#ifdef __cpp_lib_bitset // C++ >= 23
1060 /**
1061 * Use a subset of a string view.
1062 * @param __s A `string_view` of a sequence of `0` and `1` characters.
1063 * @param __position Index of the first character in `__s` to use.
1064 * @param __n The maximum number of characters from `__s` to use.
1065 * @param __zero The character corresponding to the value 0.
1066 * @param __one The character corresponding to the value 1.
1067 * @throw std::out_of_range If `__position > __s.size()`.
1068 * @throw std::invalid_argument If a character appears in `__s`
1069 * which is neither `0` nor `1`.
1070 */
1071 template<class _CharT, class _Traits>
1072 constexpr explicit
1073 bitset(basic_string_view<_CharT, _Traits> __s,
1074 basic_string_view<_CharT, _Traits>::size_type __position = 0,
1075 basic_string_view<_CharT, _Traits>::size_type __n =
1076 basic_string_view<_CharT, _Traits>::npos,
1077 _CharT __zero = _CharT('0'), _CharT __one = _CharT('1'))
1078 : _Base()
1079 {
1080 _M_check_initial_position(__s, __position);
1081 _M_copy_from_ptr<_CharT, _Traits>(
1082 __s.data(), __s.size(), __position, __n, __zero, __one);
1083 }
1084#endif
1085
1086#if __cplusplus >= 201103L
1087 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1088 // 4294. bitset(const CharT*) constructor needs to be constrained
1089 /**
1090 * Construct from a character %array.
1091 * @param __str An %array of characters `__zero` and `__one`.
1092 * @param __n The number of characters to use.
1093 * @param __zero The character corresponding to the value 0.
1094 * @param __one The character corresponding to the value 1.
1095 * @throw std::invalid_argument If a character appears in the string
1096 * which is neither `__zero` nor `__one`.
1097 */
1098 template<typename _CharT,
1099 typename = _Require<is_trivially_copyable<_CharT>,
1102 __not_<is_array<_CharT>>>>
1103 [[__gnu__::__nonnull__]]
1104 _GLIBCXX23_CONSTEXPR
1105 explicit
1106 bitset(const _CharT* __str,
1107 typename __bitset::__string<_CharT>::size_type __n
1109 _CharT __zero = _CharT('0'), _CharT __one = _CharT('1'))
1110 : _Base()
1111 {
1112 if (!__str)
1113 __throw_logic_error(__N("bitset::bitset(const _CharT*, ...)"));
1114 using _Traits = typename __bitset::__string<_CharT>::traits_type;
1115
1117 __n = _Traits::length(__str);
1118 _M_copy_from_ptr<_CharT, _Traits>(__str, __n, 0, __n, __zero, __one);
1119 }
1120#endif // C++11
1121
1122 // 23.3.5.2 bitset operations:
1123 ///@{
1124 /**
1125 * Operations on bitsets.
1126 * @param __rhs A same-sized bitset.
1127 *
1128 * These should be self-explanatory.
1129 */
1130 _GLIBCXX23_CONSTEXPR
1132 operator&=(const bitset<_Nb>& __rhs) _GLIBCXX_NOEXCEPT
1133 {
1134 this->_M_do_and(__rhs);
1135 return *this;
1136 }
1137
1138 _GLIBCXX23_CONSTEXPR
1140 operator|=(const bitset<_Nb>& __rhs) _GLIBCXX_NOEXCEPT
1141 {
1142 this->_M_do_or(__rhs);
1143 return *this;
1144 }
1145
1146 _GLIBCXX23_CONSTEXPR
1148 operator^=(const bitset<_Nb>& __rhs) _GLIBCXX_NOEXCEPT
1149 {
1150 this->_M_do_xor(__rhs);
1151 return *this;
1152 }
1153 ///@}
1154
1155 ///@{
1156 /**
1157 * Operations on bitsets.
1158 * @param __position The number of places to shift.
1159 *
1160 * These should be self-explanatory.
1161 */
1162 _GLIBCXX23_CONSTEXPR
1164 operator<<=(size_t __position) _GLIBCXX_NOEXCEPT
1165 {
1166 if (__builtin_expect(__position < _Nb, 1))
1167 {
1168 this->_M_do_left_shift(__position);
1169 this->_M_do_sanitize();
1170 }
1171 else
1172 this->_M_do_reset();
1173 return *this;
1174 }
1175
1176 _GLIBCXX23_CONSTEXPR
1178 operator>>=(size_t __position) _GLIBCXX_NOEXCEPT
1179 {
1180 if (__builtin_expect(__position < _Nb, 1))
1181 this->_M_do_right_shift(__position);
1182 else
1183 this->_M_do_reset();
1184 return *this;
1185 }
1186 ///@}
1187
1188 ///@{
1189 /**
1190 * These versions of single-bit set, reset, flip, and test are
1191 * extensions from the SGI version. They do no range checking.
1192 * @ingroup SGIextensions
1193 */
1194 _GLIBCXX23_CONSTEXPR
1196 _Unchecked_set(size_t __pos) _GLIBCXX_NOEXCEPT
1197 {
1198 this->_M_getword(__pos) |= _Base::_S_maskbit(__pos);
1199 return *this;
1200 }
1201
1202 _GLIBCXX23_CONSTEXPR
1204 _Unchecked_set(size_t __pos, int __val) _GLIBCXX_NOEXCEPT
1205 {
1206 if (__val)
1207 this->_M_getword(__pos) |= _Base::_S_maskbit(__pos);
1208 else
1209 this->_M_getword(__pos) &= ~_Base::_S_maskbit(__pos);
1210 return *this;
1211 }
1212
1213 _GLIBCXX23_CONSTEXPR
1215 _Unchecked_reset(size_t __pos) _GLIBCXX_NOEXCEPT
1216 {
1217 this->_M_getword(__pos) &= ~_Base::_S_maskbit(__pos);
1218 return *this;
1219 }
1220
1221 _GLIBCXX23_CONSTEXPR
1223 _Unchecked_flip(size_t __pos) _GLIBCXX_NOEXCEPT
1224 {
1225 this->_M_getword(__pos) ^= _Base::_S_maskbit(__pos);
1226 return *this;
1227 }
1228
1229 _GLIBCXX_CONSTEXPR bool
1230 _Unchecked_test(size_t __pos) const _GLIBCXX_NOEXCEPT
1231 { return ((this->_M_getword(__pos) & _Base::_S_maskbit(__pos))
1232 != static_cast<_WordT>(0)); }
1233 ///@}
1234
1235 // Set, reset, and flip.
1236 /**
1237 * @brief Sets every bit to true.
1238 */
1239 _GLIBCXX23_CONSTEXPR
1241 set() _GLIBCXX_NOEXCEPT
1242 {
1243 this->_M_do_set();
1244 this->_M_do_sanitize();
1245 return *this;
1246 }
1247
1248 /**
1249 * @brief Sets a given bit to a particular value.
1250 * @param __position The index of the bit.
1251 * @param __val Either true or false, defaults to true.
1252 * @throw std::out_of_range If @a pos is bigger the size of the %set.
1253 */
1254 _GLIBCXX23_CONSTEXPR
1256 set(size_t __position, bool __val = true)
1257 {
1258 this->_M_check(__position, __N("bitset::set"));
1259 return _Unchecked_set(__position, __val);
1260 }
1261
1262 /**
1263 * @brief Sets every bit to false.
1264 */
1265 _GLIBCXX23_CONSTEXPR
1267 reset() _GLIBCXX_NOEXCEPT
1268 {
1269 this->_M_do_reset();
1270 return *this;
1271 }
1272
1273 /**
1274 * @brief Sets a given bit to false.
1275 * @param __position The index of the bit.
1276 * @throw std::out_of_range If @a pos is bigger the size of the %set.
1277 *
1278 * Same as writing @c set(pos,false).
1279 */
1280 _GLIBCXX23_CONSTEXPR
1282 reset(size_t __position)
1283 {
1284 this->_M_check(__position, __N("bitset::reset"));
1285 return _Unchecked_reset(__position);
1286 }
1287
1288 /**
1289 * @brief Toggles every bit to its opposite value.
1290 */
1291 _GLIBCXX23_CONSTEXPR
1293 flip() _GLIBCXX_NOEXCEPT
1294 {
1295 this->_M_do_flip();
1296 this->_M_do_sanitize();
1297 return *this;
1298 }
1299
1300 /**
1301 * @brief Toggles a given bit to its opposite value.
1302 * @param __position The index of the bit.
1303 * @throw std::out_of_range If @a pos is bigger the size of the %set.
1304 */
1305 _GLIBCXX23_CONSTEXPR
1307 flip(size_t __position)
1308 {
1309 this->_M_check(__position, __N("bitset::flip"));
1310 return _Unchecked_flip(__position);
1311 }
1312
1313 /// See the no-argument flip().
1314 _GLIBCXX23_CONSTEXPR
1316 operator~() const _GLIBCXX_NOEXCEPT
1317 { return bitset<_Nb>(*this).flip(); }
1318
1319 ///@{
1320 /**
1321 * @brief Array-indexing support.
1322 * @param __position Index into the %bitset.
1323 * @return A bool for a <em>const %bitset</em>. For non-const
1324 * bitsets, an instance of the reference proxy class.
1325 * @note These operators do no range checking and throw no exceptions,
1326 * as required by DR 11 to the standard.
1327 *
1328 * _GLIBCXX_RESOLVE_LIB_DEFECTS Note that this implementation already
1329 * resolves DR 11 (items 1 and 2), but does not do the range-checking
1330 * required by that DR's resolution. -pme
1331 * The DR has since been changed: range-checking is a precondition
1332 * (users' responsibility), and these functions must not throw. -pme
1333 */
1334 _GLIBCXX23_CONSTEXPR
1335 reference
1336 operator[](size_t __position)
1337 {
1338 __glibcxx_assert(__position < _Nb);
1339 return reference(*this, __position);
1340 }
1341
1342 _GLIBCXX_CONSTEXPR bool
1343 operator[](size_t __position) const
1344 {
1345#if __cplusplus != 201103L
1346 __glibcxx_assert(__position < _Nb);
1347 return _Unchecked_test(__position);
1348#elif defined(_GLIBCXX_ASSERTIONS)
1349 // C++11 forbids a compound stmt in a constexpr function.
1350 return __position < _Nb ? _Unchecked_test(__position)
1351 : (__builtin_trap(), false);
1352#else
1353 return _Unchecked_test(__position);
1354#endif
1355 }
1356 ///@}
1357
1358 /**
1359 * @brief Returns a numerical interpretation of the %bitset.
1360 * @return The integral equivalent of the bits.
1361 * @throw std::overflow_error If there are too many bits to be
1362 * represented in an @c unsigned @c long.
1363 */
1364 _GLIBCXX23_CONSTEXPR
1365 unsigned long
1366 to_ulong() const
1367 { return this->_M_do_to_ulong(); }
1368
1369#if __cplusplus >= 201103L
1370 _GLIBCXX23_CONSTEXPR
1371 unsigned long long
1372 to_ullong() const
1373 { return this->_M_do_to_ullong(); }
1374#endif
1375
1376#if _GLIBCXX_HOSTED
1377 /**
1378 * @brief Returns a character interpretation of the %bitset.
1379 * @return The string equivalent of the bits.
1380 *
1381 * Note the ordering of the bits: decreasing character positions
1382 * correspond to increasing bit positions (see the main class notes for
1383 * an example).
1384 */
1385 template<class _CharT, class _Traits, class _Alloc>
1386 _GLIBCXX23_CONSTEXPR
1389 {
1391 _M_copy_to_string(__result, _CharT('0'), _CharT('1'));
1392 return __result;
1393 }
1394
1395 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1396 // 396. what are characters zero and one.
1397 template<class _CharT, class _Traits, class _Alloc>
1398 _GLIBCXX23_CONSTEXPR
1400 to_string(_CharT __zero, _CharT __one = _CharT('1')) const
1401 {
1403 _M_copy_to_string(__result, __zero, __one);
1404 return __result;
1405 }
1406
1407 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1408 // 434. bitset::to_string() hard to use.
1409 template<class _CharT, class _Traits>
1410 _GLIBCXX23_CONSTEXPR
1412 to_string() const
1413 { return to_string<_CharT, _Traits, std::allocator<_CharT> >(); }
1414
1415 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1416 // 853. to_string needs updating with zero and one.
1417 template<class _CharT, class _Traits>
1418 _GLIBCXX23_CONSTEXPR
1419 std::basic_string<_CharT, _Traits, std::allocator<_CharT> >
1420 to_string(_CharT __zero, _CharT __one = _CharT('1')) const
1421 { return to_string<_CharT, _Traits,
1422 std::allocator<_CharT> >(__zero, __one); }
1423
1424 template<class _CharT>
1425 _GLIBCXX23_CONSTEXPR
1426 std::basic_string<_CharT, std::char_traits<_CharT>,
1427 std::allocator<_CharT> >
1428 to_string() const
1429 {
1430 return to_string<_CharT, std::char_traits<_CharT>,
1431 std::allocator<_CharT> >();
1432 }
1433
1434 template<class _CharT>
1435 _GLIBCXX23_CONSTEXPR
1436 std::basic_string<_CharT, std::char_traits<_CharT>,
1437 std::allocator<_CharT> >
1438 to_string(_CharT __zero, _CharT __one = _CharT('1')) const
1439 {
1440 return to_string<_CharT, std::char_traits<_CharT>,
1441 std::allocator<_CharT> >(__zero, __one);
1442 }
1443
1444 _GLIBCXX23_CONSTEXPR
1445 std::basic_string<char, std::char_traits<char>, std::allocator<char> >
1446 to_string() const
1447 {
1448 return to_string<char, std::char_traits<char>,
1449 std::allocator<char> >();
1450 }
1451
1452 _GLIBCXX23_CONSTEXPR
1453 std::basic_string<char, std::char_traits<char>, std::allocator<char> >
1454 to_string(char __zero, char __one = '1') const
1455 {
1456 return to_string<char, std::char_traits<char>,
1457 std::allocator<char> >(__zero, __one);
1458 }
1459#endif // HOSTED
1460
1461 /// Returns the number of bits which are set.
1462 _GLIBCXX23_CONSTEXPR
1463 size_t
1464 count() const _GLIBCXX_NOEXCEPT
1465 { return this->_M_do_count(); }
1466
1467 /// Returns the total number of bits.
1468 _GLIBCXX_CONSTEXPR size_t
1469 size() const _GLIBCXX_NOEXCEPT
1470 { return _Nb; }
1471
1472 ///@{
1473 /// These comparisons for equality/inequality are, well, @e bitwise.
1474 _GLIBCXX23_CONSTEXPR
1475 bool
1476 operator==(const bitset<_Nb>& __rhs) const _GLIBCXX_NOEXCEPT
1477 { return this->_M_is_equal(__rhs); }
1478
1479#if __cpp_impl_three_way_comparison < 201907L
1480 _GLIBCXX23_CONSTEXPR
1481 bool
1482 operator!=(const bitset<_Nb>& __rhs) const _GLIBCXX_NOEXCEPT
1483 { return !this->_M_is_equal(__rhs); }
1484#endif
1485 ///@}
1486
1487 /**
1488 * @brief Tests the value of a bit.
1489 * @param __position The index of a bit.
1490 * @return The value at @a pos.
1491 * @throw std::out_of_range If @a pos is bigger the size of the %set.
1492 */
1493 _GLIBCXX23_CONSTEXPR
1494 bool
1495 test(size_t __position) const
1496 {
1497 this->_M_check(__position, __N("bitset::test"));
1498 return _Unchecked_test(__position);
1499 }
1500
1501 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1502 // DR 693. std::bitset::all() missing.
1503 /**
1504 * @brief Tests whether all the bits are on.
1505 * @return True if all the bits are set.
1506 */
1507 _GLIBCXX23_CONSTEXPR
1508 bool
1509 all() const _GLIBCXX_NOEXCEPT
1510 { return this->template _M_are_all<_Nb>(); }
1511
1512 /**
1513 * @brief Tests whether any of the bits are on.
1514 * @return True if at least one bit is set.
1515 */
1516 _GLIBCXX23_CONSTEXPR
1517 bool
1518 any() const _GLIBCXX_NOEXCEPT
1519 { return this->_M_is_any(); }
1520
1521 /**
1522 * @brief Tests whether any of the bits are on.
1523 * @return True if none of the bits are set.
1524 */
1525 _GLIBCXX23_CONSTEXPR
1526 bool
1527 none() const _GLIBCXX_NOEXCEPT
1528 { return !this->_M_is_any(); }
1529
1530 ///@{
1531 /// Self-explanatory.
1532 _GLIBCXX23_CONSTEXPR
1534 operator<<(size_t __position) const _GLIBCXX_NOEXCEPT
1535 { return bitset<_Nb>(*this) <<= __position; }
1536
1537 _GLIBCXX23_CONSTEXPR
1539 operator>>(size_t __position) const _GLIBCXX_NOEXCEPT
1540 { return bitset<_Nb>(*this) >>= __position; }
1541 ///@}
1542
1543 /**
1544 * @brief Finds the index of the first "on" bit.
1545 * @return The index of the first bit set, or size() if not found.
1546 * @ingroup SGIextensions
1547 * @sa _Find_next
1548 */
1549 _GLIBCXX23_CONSTEXPR
1550 size_t
1551 _Find_first() const _GLIBCXX_NOEXCEPT
1552 { return this->_M_do_find_first(_Nb); }
1553
1554 /**
1555 * @brief Finds the index of the next "on" bit after prev.
1556 * @return The index of the next bit set, or size() if not found.
1557 * @param __prev Where to start searching.
1558 * @ingroup SGIextensions
1559 * @sa _Find_first
1560 */
1561 _GLIBCXX23_CONSTEXPR
1562 size_t
1563 _Find_next(size_t __prev) const _GLIBCXX_NOEXCEPT
1564 { return this->_M_do_find_next(__prev, _Nb); }
1565
1566 private:
1567 // Helper functions for string operations.
1568 template<class _CharT, class _Traits>
1569 _GLIBCXX23_CONSTEXPR
1570 void
1571 _M_copy_from_ptr(const _CharT*, size_t, size_t, size_t,
1572 _CharT, _CharT);
1573
1574#if _GLIBCXX_HOSTED
1575 template<class _CharT, class _Traits, class _Alloc>
1576 _GLIBCXX23_CONSTEXPR
1577 void
1578 _M_copy_from_string(const std::basic_string<_CharT,
1579 _Traits, _Alloc>& __s, size_t __pos, size_t __n,
1580 _CharT __zero, _CharT __one)
1581 { _M_copy_from_ptr<_CharT, _Traits>(__s.data(), __s.size(), __pos, __n,
1582 __zero, __one); }
1583
1584 template<class _CharT, class _Traits, class _Alloc>
1585 _GLIBCXX23_CONSTEXPR
1586 void
1588 _CharT, _CharT) const;
1589
1590 template<class _CharT, class _Traits, size_t _Nb2>
1593
1594 template <class _CharT, class _Traits, size_t _Nb2>
1596 operator<<(std::basic_ostream<_CharT, _Traits>&, const bitset<_Nb2>&);
1597#endif
1598 };
1599
1600 // Definitions of non-inline member functions.
1601 template<size_t _Nb>
1602 template<class _CharT, class _Traits>
1603 _GLIBCXX23_CONSTEXPR
1604 void
1606 _M_copy_from_ptr(const _CharT* __s, size_t __len,
1607 size_t __pos, size_t __n, _CharT __zero, _CharT __one)
1608 {
1609 reset();
1610 const size_t __rlen = std::min(__n, size_t(__len - __pos));
1611 const size_t __nbits = std::min(_Nb, __rlen);
1612 for (size_t __i = __rlen - __nbits; __i > 0; --__i)
1613 {
1614 const _CharT __c = __s[__pos + __rlen - __i];
1615 if (!_Traits::eq(__c, __zero) && !_Traits::eq(__c, __one))
1616 __throw_invalid_argument(__N("bitset::_M_copy_from_ptr"));
1617 }
1618 for (size_t __i = __nbits; __i > 0; --__i)
1619 {
1620 const _CharT __c = __s[__pos + __nbits - __i];
1621 if (_Traits::eq(__c, __zero))
1622 ;
1623 else if (_Traits::eq(__c, __one))
1624 _Unchecked_set(__i - 1);
1625 else
1626 __throw_invalid_argument(__N("bitset::_M_copy_from_ptr"));
1627 }
1628 }
1629
1630#if _GLIBCXX_HOSTED
1631 template<size_t _Nb>
1632 template<class _CharT, class _Traits, class _Alloc>
1633 _GLIBCXX23_CONSTEXPR
1634 void
1636 _M_copy_to_string(std::basic_string<_CharT, _Traits, _Alloc>& __s,
1637 _CharT __zero, _CharT __one) const
1638 {
1639 __s.assign(_Nb, __zero);
1640 size_t __n = this->_Find_first();
1641 while (__n < _Nb)
1642 {
1643 __s[_Nb - __n - 1] = __one;
1644 __n = _Find_next(__n);
1645 }
1646 }
1647#endif // HOSTED
1648
1649 // 23.3.5.3 bitset operations:
1650 ///@{
1651 /**
1652 * @brief Global bitwise operations on bitsets.
1653 * @param __x A bitset.
1654 * @param __y A bitset of the same size as @a __x.
1655 * @return A new bitset.
1656 *
1657 * These should be self-explanatory.
1658 */
1659 template<size_t _Nb>
1660 _GLIBCXX23_CONSTEXPR
1661 inline bitset<_Nb>
1662 operator&(const bitset<_Nb>& __x, const bitset<_Nb>& __y) _GLIBCXX_NOEXCEPT
1663 {
1664 bitset<_Nb> __result(__x);
1665 __result &= __y;
1666 return __result;
1667 }
1668
1669 template<size_t _Nb>
1670 _GLIBCXX23_CONSTEXPR
1671 inline bitset<_Nb>
1672 operator|(const bitset<_Nb>& __x, const bitset<_Nb>& __y) _GLIBCXX_NOEXCEPT
1673 {
1674 bitset<_Nb> __result(__x);
1675 __result |= __y;
1676 return __result;
1677 }
1678
1679 template <size_t _Nb>
1680 _GLIBCXX23_CONSTEXPR
1681 inline bitset<_Nb>
1682 operator^(const bitset<_Nb>& __x, const bitset<_Nb>& __y) _GLIBCXX_NOEXCEPT
1683 {
1684 bitset<_Nb> __result(__x);
1685 __result ^= __y;
1686 return __result;
1687 }
1688 ///@}
1689
1690#if _GLIBCXX_HOSTED
1691 ///@{
1692 /**
1693 * @brief Global I/O operators for bitsets.
1694 *
1695 * Direct I/O between streams and bitsets is supported. Output is
1696 * straightforward. Input will skip whitespace, only accept @a 0 and @a 1
1697 * characters, and will only extract as many digits as the %bitset will
1698 * hold.
1699 */
1700 template<class _CharT, class _Traits, size_t _Nb>
1703 {
1704 typedef typename _Traits::char_type char_type;
1705 typedef std::basic_istream<_CharT, _Traits> __istream_type;
1706 typedef typename __istream_type::ios_base __ios_base;
1707
1708#pragma GCC diagnostic push
1709#pragma GCC diagnostic ignored "-Wc++17-extensions" // if constexpr
1710 struct _Buffer
1711 {
1712 static _GLIBCXX_CONSTEXPR bool _S_use_alloca() { return _Nb <= 256; }
1713
1714 explicit _Buffer(_CharT* __p) : _M_ptr(__p) { }
1715
1716 ~_Buffer()
1717 {
1718 if _GLIBCXX_CONSTEXPR (!_S_use_alloca())
1719 delete[] _M_ptr;
1720 }
1721
1722 _CharT* const _M_ptr;
1723 };
1724 _CharT* __ptr;
1725 if _GLIBCXX_CONSTEXPR (_Buffer::_S_use_alloca())
1726 __ptr = (_CharT*)__builtin_alloca(_Nb);
1727 else
1728 __ptr = new _CharT[_Nb];
1729 const _Buffer __buf(__ptr);
1730#pragma GCC diagnostic pop
1731
1732 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1733 // 303. Bitset input operator underspecified
1734 const char_type __zero = __is.widen('0');
1735 const char_type __one = __is.widen('1');
1736
1737 typename __ios_base::iostate __state = __ios_base::goodbit;
1738 typename __istream_type::sentry __sentry(__is);
1739 if (__sentry)
1740 {
1741 __try
1742 {
1743 for (size_t __i = _Nb; __i > 0; --__i)
1744 {
1745 static typename _Traits::int_type __eof = _Traits::eof();
1746
1747 typename _Traits::int_type __c1 = __is.rdbuf()->sbumpc();
1748 if (_Traits::eq_int_type(__c1, __eof))
1749 {
1750 __state |= __ios_base::eofbit;
1751 break;
1752 }
1753 else
1754 {
1755 const char_type __c2 = _Traits::to_char_type(__c1);
1756 if (_Traits::eq(__c2, __zero))
1757 *__ptr++ = __zero;
1758 else if (_Traits::eq(__c2, __one))
1759 *__ptr++ = __one;
1760 else if (_Traits::
1761 eq_int_type(__is.rdbuf()->sputbackc(__c2),
1762 __eof))
1763 {
1764 __state |= __ios_base::failbit;
1765 break;
1766 }
1767 }
1768 }
1769 }
1771 {
1772 __is._M_setstate(__ios_base::badbit);
1773 __throw_exception_again;
1774 }
1775 __catch(...)
1776 { __is._M_setstate(__ios_base::badbit); }
1777 }
1778
1779#pragma GCC diagnostic push
1780#pragma GCC diagnostic ignored "-Wc++17-extensions" // if constexpr
1781 if _GLIBCXX_CONSTEXPR (_Nb)
1782 {
1783 if (size_t __len = __ptr - __buf._M_ptr)
1784 __x.template _M_copy_from_ptr<_CharT, _Traits>(__buf._M_ptr, __len,
1785 0, __len,
1786 __zero, __one);
1787 else
1788 __state |= __ios_base::failbit;
1789 }
1790#pragma GCC diagnostic pop
1791 if (__state)
1792 __is.setstate(__state);
1793 return __is;
1794 }
1795
1796 template <class _CharT, class _Traits, size_t _Nb>
1799 const bitset<_Nb>& __x)
1800 {
1802
1803 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1804 // 396. what are characters zero and one.
1805 const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__os.getloc());
1806 __x._M_copy_to_string(__tmp, __ct.widen('0'), __ct.widen('1'));
1807 return __os << __tmp;
1808 }
1809 ///@}
1810#endif // HOSTED
1811
1812_GLIBCXX_END_NAMESPACE_CONTAINER
1813} // namespace std
1814
1815#undef _GLIBCXX_BITSET_WORDS
1816#undef _GLIBCXX_BITSET_BITS_PER_WORD
1817#undef _GLIBCXX_BITSET_BITS_PER_ULL
1818
1819#if __cplusplus >= 201103L
1820
1821namespace std _GLIBCXX_VISIBILITY(default)
1822{
1823_GLIBCXX_BEGIN_NAMESPACE_VERSION
1824
1825 // DR 1182.
1826 /// std::hash specialization for bitset.
1827 template<size_t _Nb>
1828 struct hash<_GLIBCXX_STD_C::bitset<_Nb>>
1829 : public __hash_base<size_t, _GLIBCXX_STD_C::bitset<_Nb>>
1830 {
1831 size_t
1832 operator()(const _GLIBCXX_STD_C::bitset<_Nb>& __b) const noexcept
1833 {
1834 const size_t __clength = (_Nb + __CHAR_BIT__ - 1) / __CHAR_BIT__;
1835 return std::_Hash_impl::hash(__b._M_getdata(), __clength);
1836 }
1837 };
1838
1839 template<>
1840 struct hash<_GLIBCXX_STD_C::bitset<0>>
1841 : public __hash_base<size_t, _GLIBCXX_STD_C::bitset<0>>
1842 {
1843 size_t
1844 operator()(const _GLIBCXX_STD_C::bitset<0>&) const noexcept
1845 { return 0; }
1846 };
1847
1848_GLIBCXX_END_NAMESPACE_VERSION
1849} // namespace
1850
1851#endif // C++11
1852
1853#if defined _GLIBCXX_DEBUG && _GLIBCXX_HOSTED
1854# include <debug/bitset>
1855#endif
1856
1857#endif /* _GLIBCXX_BITSET */
constexpr bitset< _Nb > & _Unchecked_reset(size_t __pos) noexcept
Definition bitset:1215
constexpr bitset< _Nb > & _Unchecked_flip(size_t __pos) noexcept
Definition bitset:1223
constexpr size_t _Find_first() const noexcept
Finds the index of the first "on" bit.
Definition bitset:1551
constexpr bool _Unchecked_test(size_t __pos) const noexcept
Definition bitset:1230
constexpr bitset< _Nb > & _Unchecked_set(size_t __pos) noexcept
Definition bitset:1196
constexpr bitset< _Nb > & _Unchecked_set(size_t __pos, int __val) noexcept
Definition bitset:1204
constexpr size_t _Find_next(size_t __prev) const noexcept
Finds the index of the next "on" bit after prev.
Definition bitset:1563
constexpr const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
const _Facet & use_facet(const locale &__loc)
Return a facet.
ISO C++ entities toplevel namespace is std.
constexpr bitset< _Nb > operator^(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
Definition bitset:1682
std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, bitset< _Nb > &__x)
Global I/O operators for bitsets.
Definition bitset:1702
std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const bitset< _Nb > &__x)
Global I/O operators for bitsets.
Definition bitset:1798
constexpr bitset< _Nb > operator|(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
Definition bitset:1672
constexpr bitset< _Nb > operator&(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
Definition bitset:1662
The bitset class represents a fixed-size sequence of bits.
Definition bitset:823
constexpr reference operator[](size_t __position)
Array-indexing support.
Definition bitset:1336
constexpr bitset< _Nb > & operator>>=(size_t __position) noexcept
Definition bitset:1178
constexpr bitset< _Nb > & flip() noexcept
Toggles every bit to its opposite value.
Definition bitset:1293
constexpr bitset< _Nb > & operator&=(const bitset< _Nb > &__rhs) noexcept
Definition bitset:1132
constexpr bitset(const _CharT *__str, typename __bitset::__string< _CharT >::size_type __n=__bitset::__string< _CharT >::npos, _CharT __zero=_CharT('0'), _CharT __one=_CharT('1'))
Definition bitset:1106
constexpr bitset< _Nb > operator>>(size_t __position) const noexcept
Self-explanatory.
Definition bitset:1539
constexpr unsigned long to_ulong() const
Returns a numerical interpretation of the bitset.
Definition bitset:1366
constexpr bool any() const noexcept
Tests whether any of the bits are on.
Definition bitset:1518
constexpr bitset() noexcept
All bits set to zero.
Definition bitset:990
constexpr bitset< _Nb > & operator^=(const bitset< _Nb > &__rhs) noexcept
Definition bitset:1148
constexpr bool test(size_t __position) const
Tests the value of a bit.
Definition bitset:1495
constexpr bitset< _Nb > operator~() const noexcept
See the no-argument flip().
Definition bitset:1316
constexpr bitset< _Nb > & operator|=(const bitset< _Nb > &__rhs) noexcept
Definition bitset:1140
constexpr bitset< _Nb > & set(size_t __position, bool __val=true)
Sets a given bit to a particular value.
Definition bitset:1256
constexpr size_t count() const noexcept
Returns the number of bits which are set.
Definition bitset:1464
constexpr bitset< _Nb > & operator<<=(size_t __position) noexcept
Definition bitset:1164
constexpr std::basic_string< _CharT, _Traits, _Alloc > to_string() const
Returns a character interpretation of the bitset.
Definition bitset:1388
constexpr bitset< _Nb > & reset() noexcept
Sets every bit to false.
Definition bitset:1267
constexpr bitset< _Nb > & set() noexcept
Sets every bit to true.
Definition bitset:1241
constexpr bitset(const std::basic_string< _CharT, _Traits, _Alloc > &__s, size_t __position=0)
Definition bitset:1016
constexpr bitset(const std::basic_string< _CharT, _Traits, _Alloc > &__s, size_t __position, size_t __n)
Definition bitset:1037
constexpr bitset(unsigned long long __val) noexcept
Initial bits bitwise-copied from a single word (others set to zero).
Definition bitset:995
constexpr size_t size() const noexcept
Returns the total number of bits.
Definition bitset:1469
constexpr bool all() const noexcept
Tests whether all the bits are on.
Definition bitset:1509
constexpr bitset< _Nb > & reset(size_t __position)
Sets a given bit to false.
Definition bitset:1282
constexpr bool none() const noexcept
Tests whether any of the bits are on.
Definition bitset:1527
constexpr bool operator==(const bitset< _Nb > &__rhs) const noexcept
These comparisons for equality/inequality are, well, bitwise.
Definition bitset:1476
constexpr bool operator[](size_t __position) const
Array-indexing support.
Definition bitset:1343
constexpr bitset< _Nb > & flip(size_t __position)
Toggles a given bit to its opposite value.
Definition bitset:1307
Template class basic_istream.
Definition istream:73
Primary class template hash.
is_standard_layout
Definition type_traits:1006
is_trivially_default_constructible
Definition type_traits:1462
void setstate(iostate __state)
Sets additional flags in the error state.
Definition basic_ios.h:167
char_type widen(char __c) const
Widens characters.
Definition basic_ios.h:465
basic_streambuf< _CharT, _Traits > * rdbuf() const
Accessing the underlying buffer.
Definition basic_ios.h:338
Managing sequences of characters and character-like objects.
constexpr basic_string & assign(const basic_string &__str)
Set value to contents of another string.
static const size_type npos
Value returned by various member functions when they fail.
Thrown as part of forced unwinding.
locale getloc() const
Locale access.
Definition ios_base.h:841
Template class basic_ostream.
Definition ostream.h:72