libstdc++: bitset Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29#ifndef _GLIBCXX_DEBUG_BITSET
30#define _GLIBCXX_DEBUG_BITSET
31
32#pragma GCC system_header
33
37
38namespace std _GLIBCXX_VISIBILITY(default)
39{
40namespace __debug
41{
42
43 template<size_t _Nb>
45 : public _GLIBCXX_STD_C::bitset<_Nb>
46#if __cplusplus < 201103L
48#endif
49 {
50 typedef _GLIBCXX_STD_C::bitset<_Nb> _Base;
51
52 public:
53
54
55
56#if __cplusplus >= 201103L
57 typedef typename _Base::reference reference;
58#else
59
60 class reference
61 : private _Base::reference
63 {
64 typedef typename _Base::reference _Base_ref;
65
67 reference();
68
69 reference(const _Base_ref& __base, bitset* __seq) _GLIBCXX_NOEXCEPT
70 : _Base_ref(__base)
71 , _Safe_iterator_base(__seq, false)
72 { }
73
74 public:
75 reference(const reference& __x) _GLIBCXX_NOEXCEPT
76 : _Base_ref(__x)
77 , _Safe_iterator_base(__x, false)
78 { }
79
80 reference&
81 operator=(bool __x) _GLIBCXX_NOEXCEPT
82 {
83 _GLIBCXX_DEBUG_VERIFY(!this->_M_singular(),
84 _M_message(__gnu_debug::__msg_bad_bitset_write)
85 ._M_iterator(*this));
86 *static_cast<_Base_ref*>(this) = __x;
87 return *this;
88 }
89
90 reference&
91 operator=(const reference& __x) _GLIBCXX_NOEXCEPT
92 {
93 _GLIBCXX_DEBUG_VERIFY(!__x._M_singular(),
94 _M_message(__gnu_debug::__msg_bad_bitset_read)
95 ._M_iterator(__x));
96 _GLIBCXX_DEBUG_VERIFY(!this->_M_singular(),
97 _M_message(__gnu_debug::__msg_bad_bitset_write)
98 ._M_iterator(*this));
99 *static_cast<_Base_ref*>(this) = __x;
100 return *this;
101 }
102
103 bool
104 operator~() const _GLIBCXX_NOEXCEPT
105 {
106 _GLIBCXX_DEBUG_VERIFY(!this->_M_singular(),
107 _M_message(__gnu_debug::__msg_bad_bitset_read)
108 ._M_iterator(*this));
109 return ~(*static_cast<const _Base_ref*>(this));
110 }
111
112 operator bool() const _GLIBCXX_NOEXCEPT
113 {
114 _GLIBCXX_DEBUG_VERIFY(!this->_M_singular(),
115 _M_message(__gnu_debug::__msg_bad_bitset_read)
116 ._M_iterator(*this));
117 return *static_cast<const _Base_ref*>(this);
118 }
119
120 reference&
121 flip() _GLIBCXX_NOEXCEPT
122 {
123 _GLIBCXX_DEBUG_VERIFY(!this->_M_singular(),
124 _M_message(__gnu_debug::__msg_bad_bitset_flip)
125 ._M_iterator(*this));
126 _Base_ref::flip();
127 return *this;
128 }
129 };
130#endif
131
132
133 _GLIBCXX_CONSTEXPR bitset() _GLIBCXX_NOEXCEPT
135
136#if __cplusplus >= 201103L
137 constexpr bitset(unsigned long long __val) noexcept
138#else
139 bitset(unsigned long __val)
140#endif
141 : _Base(__val) { }
142
143 template<typename _CharT, typename _Traits, typename _Alloc>
144 _GLIBCXX23_CONSTEXPR
145 explicit
147 typename std::basic_string<_CharT, _Traits, _Alloc>::size_type
148 __pos = 0,
149 typename std::basic_string<_CharT, _Traits, _Alloc>::size_type
151 : _Base(__str, __pos, __n) { }
152
153
154
155 template<class _CharT, class _Traits, class _Alloc>
156 _GLIBCXX23_CONSTEXPR
158 typename std::basic_string<_CharT, _Traits, _Alloc>::size_type
159 __pos,
160 typename std::basic_string<_CharT, _Traits, _Alloc>::size_type
161 __n,
162 _CharT __zero, _CharT __one = _CharT('1'))
163 : _Base(__str, __pos, __n, __zero, __one) { }
164
165 _GLIBCXX23_CONSTEXPR
167
168#if __cplusplus >= 201103L
169 template<typename _CharT>
170 _GLIBCXX23_CONSTEXPR
171 explicit
172 bitset(const _CharT* __str,
173 typename std::basic_string<_CharT>::size_type __n
175 _CharT __zero = _CharT('0'), _CharT __one = _CharT('1'))
176 : _Base(__str, __n, __zero, __one) { }
177#endif
178
179
180 _GLIBCXX23_CONSTEXPR
182 operator&=(const bitset<_Nb>& __rhs) _GLIBCXX_NOEXCEPT
183 {
184 _M_base() &= __rhs;
185 return *this;
186 }
187
188 _GLIBCXX23_CONSTEXPR
190 operator|=(const bitset<_Nb>& __rhs) _GLIBCXX_NOEXCEPT
191 {
192 _M_base() |= __rhs;
193 return *this;
194 }
195
196 _GLIBCXX23_CONSTEXPR
198 operator^=(const bitset<_Nb>& __rhs) _GLIBCXX_NOEXCEPT
199 {
200 _M_base() ^= __rhs;
201 return *this;
202 }
203
204 _GLIBCXX23_CONSTEXPR
206 operator<<=(size_t __pos) _GLIBCXX_NOEXCEPT
207 {
208 _M_base() <<= __pos;
209 return *this;
210 }
211
212 _GLIBCXX23_CONSTEXPR
214 operator>>=(size_t __pos) _GLIBCXX_NOEXCEPT
215 {
216 _M_base() >>= __pos;
217 return *this;
218 }
219
220 _GLIBCXX23_CONSTEXPR
222 set() _GLIBCXX_NOEXCEPT
223 {
224 _Base::set();
225 return *this;
226 }
227
228
229
230 _GLIBCXX23_CONSTEXPR
232 set(size_t __pos, bool __val = true)
233 {
234 _Base::set(__pos, __val);
235 return *this;
236 }
237
238 _GLIBCXX23_CONSTEXPR
240 reset() _GLIBCXX_NOEXCEPT
241 {
242 _Base::reset();
243 return *this;
244 }
245
246 _GLIBCXX23_CONSTEXPR
248 reset(size_t __pos)
249 {
250 _Base::reset(__pos);
251 return *this;
252 }
253
254 _GLIBCXX23_CONSTEXPR
256 operator~() const _GLIBCXX_NOEXCEPT
257 { return bitset(~_M_base()); }
258
259 _GLIBCXX23_CONSTEXPR
261 flip() _GLIBCXX_NOEXCEPT
262 {
263 _Base::flip();
264 return *this;
265 }
266
267 _GLIBCXX23_CONSTEXPR
269 flip(size_t __pos)
270 {
271 _Base::flip(__pos);
272 return *this;
273 }
274
275
276
277
278 _GLIBCXX23_CONSTEXPR
279 reference
280 operator[](size_t __pos)
281 {
282 __glibcxx_check_subscript(__pos);
283#if __cplusplus >= 201103L
284 return _M_base()[__pos];
285#else
286 return reference(_M_base()[__pos], this);
287#endif
288 }
289
290
291
292 _GLIBCXX_CONSTEXPR bool
293 operator[](size_t __pos) const
294 {
295#if __cplusplus < 201103L
296
297 __glibcxx_check_subscript(__pos);
298#endif
299 return _Base::operator[](__pos);
300 }
301
302 using _Base::to_ulong;
303#if __cplusplus >= 201103L
304 using _Base::to_ullong;
305#endif
306
307 template <typename _CharT, typename _Traits, typename _Alloc>
308 _GLIBCXX23_CONSTEXPR
310 to_string() const
311 { return _M_base().template to_string<_CharT, _Traits, _Alloc>(); }
312
313
314
315 template<class _CharT, class _Traits, class _Alloc>
316 _GLIBCXX23_CONSTEXPR
318 to_string(_CharT __zero, _CharT __one = _CharT('1')) const
319 {
320 return _M_base().template
321 to_string<_CharT, _Traits, _Alloc>(__zero, __one);
322 }
323
324
325
326 template<typename _CharT, typename _Traits>
327 _GLIBCXX23_CONSTEXPR
329 to_string() const
330 { return to_string<_CharT, _Traits, std::allocator<_CharT> >(); }
331
332
333
334 template<class _CharT, class _Traits>
335 _GLIBCXX23_CONSTEXPR
337 to_string(_CharT __zero, _CharT __one = _CharT('1')) const
338 { return to_string<_CharT, _Traits,
340
341 template<typename _CharT>
342 _GLIBCXX23_CONSTEXPR
345 to_string() const
346 {
347 return to_string<_CharT, std::char_traits<_CharT>,
349 }
350
351 template<class _CharT>
352 _GLIBCXX23_CONSTEXPR
355 to_string(_CharT __zero, _CharT __one = _CharT('1')) const
356 {
357 return to_string<_CharT, std::char_traits<_CharT>,
359 }
360
361 _GLIBCXX23_CONSTEXPR
363 to_string() const
364 {
366 }
367
368 _GLIBCXX23_CONSTEXPR
370 to_string(char __zero, char __one = '1') const
371 {
372 return to_string<char, std::char_traits,
374 }
375
376 using _Base::count;
377 using _Base::size;
378
379 _GLIBCXX23_CONSTEXPR
380 bool
381 operator==(const bitset<_Nb>& __rhs) const _GLIBCXX_NOEXCEPT
382 { return _M_base() == __rhs._M_base(); }
383
384#if __cpp_impl_three_way_comparison < 201907L
385 bool
386 operator!=(const bitset<_Nb>& __rhs) const _GLIBCXX_NOEXCEPT
387 { return _M_base() != __rhs._M_base(); }
388#endif
389
390 using _Base::test;
391 using _Base::all;
392 using _Base::any;
393 using _Base::none;
394
395 _GLIBCXX23_CONSTEXPR
397 operator<<(size_t __pos) const _GLIBCXX_NOEXCEPT
398 { return bitset<_Nb>(_M_base() << __pos); }
399
400 _GLIBCXX23_CONSTEXPR
402 operator>>(size_t __pos) const _GLIBCXX_NOEXCEPT
403 { return bitset<_Nb>(_M_base() >> __pos); }
404
405 _GLIBCXX23_CONSTEXPR
407 _M_base() _GLIBCXX_NOEXCEPT
408 { return *this; }
409
410 _GLIBCXX23_CONSTEXPR
412 _M_base() const _GLIBCXX_NOEXCEPT
413 { return *this; }
414 };
415
416 template<size_t _Nb>
417 _GLIBCXX23_CONSTEXPR
421
422 template<size_t _Nb>
423 _GLIBCXX23_CONSTEXPR
427
428 template<size_t _Nb>
429 _GLIBCXX23_CONSTEXPR
430 inline bitset<_Nb>
431 operator^(const bitset<_Nb>& __x, const bitset<_Nb>& __y) _GLIBCXX_NOEXCEPT
432 { return bitset<_Nb>(__x) ^= __y; }
433
434 template<typename _CharT, typename _Traits, size_t _Nb>
437 { return __is >> __x._M_base(); }
438
439 template<typename _CharT, typename _Traits, size_t _Nb>
442 const bitset<_Nb>& __x)
443 { return __os << __x._M_base(); }
444
445}
446
447#if __cplusplus >= 201103L
448
449
450 template<size_t _Nb>
452 : public __hash_base<size_t, __debug::bitset<_Nb>>
453 {
454 size_t
457 };
458#endif
459
460}
461
462#endif
ISO C++ entities toplevel namespace is std.
std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, bitset< _Nb > &__x)
Global I/O operators for bitsets.
std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const bitset< _Nb > &__x)
Global I/O operators for bitsets.
constexpr bitset< _Nb > operator|(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
constexpr bitset< _Nb > operator&(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
The bitset class represents a fixed-size sequence of bits.
Template class basic_istream.
Template class basic_ostream.
Primary class template hash.
The standard allocator, as per C++03 [20.4.1].
Managing sequences of characters and character-like objects.
Basic functionality for a safe iterator.
Base class that supports tracking of iterators that reference a sequence.
Class std::set with safety/checking/debug instrumentation.
Class std::bitset with additional safety/checking/debug instrumentation.