]>
Commit | Line | Data |
---|---|---|
390e4c0d | 1 | // vector<bool> specialization -*- C++ -*- |
42526146 | 2 | |
99dee823 | 3 | // Copyright (C) 2001-2021 Free Software Foundation, Inc. |
42526146 PE |
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 | |
748086b7 | 8 | // Free Software Foundation; either version 3, or (at your option) |
42526146 PE |
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 | ||
748086b7 JJ |
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. | |
42526146 | 19 | |
748086b7 JJ |
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/>. | |
42526146 | 24 | |
725dc051 BK |
25 | /* |
26 | * | |
27 | * Copyright (c) 1994 | |
28 | * Hewlett-Packard Company | |
29 | * | |
30 | * Permission to use, copy, modify, distribute and sell this software | |
31 | * and its documentation for any purpose is hereby granted without fee, | |
32 | * provided that the above copyright notice appear in all copies and | |
33 | * that both that copyright notice and this permission notice appear | |
34 | * in supporting documentation. Hewlett-Packard Company makes no | |
35 | * representations about the suitability of this software for any | |
36 | * purpose. It is provided "as is" without express or implied warranty. | |
37 | * | |
38 | * | |
39 | * Copyright (c) 1996-1999 | |
40 | * Silicon Graphics Computer Systems, Inc. | |
41 | * | |
42 | * Permission to use, copy, modify, distribute and sell this software | |
43 | * and its documentation for any purpose is hereby granted without fee, | |
44 | * provided that the above copyright notice appear in all copies and | |
45 | * that both that copyright notice and this permission notice appear | |
46 | * in supporting documentation. Silicon Graphics makes no | |
47 | * representations about the suitability of this software for any | |
48 | * purpose. It is provided "as is" without express or implied warranty. | |
49 | */ | |
50 | ||
f910786b | 51 | /** @file bits/stl_bvector.h |
729e3d3f | 52 | * This is an internal header file, included by other library headers. |
f910786b | 53 | * Do not attempt to use it directly. @headername{vector} |
725dc051 BK |
54 | */ |
55 | ||
046d30f4 PC |
56 | #ifndef _STL_BVECTOR_H |
57 | #define _STL_BVECTOR_H 1 | |
725dc051 | 58 | |
734f5023 | 59 | #if __cplusplus >= 201103L |
988499f4 | 60 | #include <initializer_list> |
5dfb5e5b | 61 | #include <bits/functional_hash.h> |
a7d5d7e2 | 62 | #endif |
988499f4 | 63 | |
12ffa228 BK |
64 | namespace std _GLIBCXX_VISIBILITY(default) |
65 | { | |
4a15d842 | 66 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
3cbc7af0 | 67 | |
172f7610 | 68 | typedef unsigned long _Bit_type; |
f56fe8ff | 69 | enum { _S_word_bit = int(__CHAR_BIT__ * sizeof(_Bit_type)) }; |
725dc051 | 70 | |
1ae8edf5 JW |
71 | __attribute__((__nonnull__)) |
72 | _GLIBCXX20_CONSTEXPR | |
73 | void | |
74 | __fill_bvector_n(_Bit_type*, size_t, bool) _GLIBCXX_NOEXCEPT; | |
75 | ||
76 | _GLIBCXX_BEGIN_NAMESPACE_CONTAINER | |
77 | ||
ed6814f7 | 78 | struct _Bit_reference |
ba9d552e BK |
79 | { |
80 | _Bit_type * _M_p; | |
81 | _Bit_type _M_mask; | |
172f7610 | 82 | |
1ae8edf5 | 83 | _GLIBCXX20_CONSTEXPR |
ed6814f7 | 84 | _Bit_reference(_Bit_type * __x, _Bit_type __y) |
ba9d552e | 85 | : _M_p(__x), _M_mask(__y) { } |
725dc051 | 86 | |
1ae8edf5 | 87 | _GLIBCXX20_CONSTEXPR |
d3677132 | 88 | _Bit_reference() _GLIBCXX_NOEXCEPT : _M_p(0), _M_mask(0) { } |
ba9d552e | 89 | |
a1417556 JW |
90 | #if __cplusplus >= 201103L |
91 | _Bit_reference(const _Bit_reference&) = default; | |
92 | #endif | |
93 | ||
1ae8edf5 | 94 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
d3677132 | 95 | operator bool() const _GLIBCXX_NOEXCEPT |
705debec | 96 | { return !!(*_M_p & _M_mask); } |
ba9d552e | 97 | |
1ae8edf5 | 98 | _GLIBCXX20_CONSTEXPR |
ed6814f7 | 99 | _Bit_reference& |
d3677132 | 100 | operator=(bool __x) _GLIBCXX_NOEXCEPT |
ba9d552e | 101 | { |
ed6814f7 | 102 | if (__x) |
ba9d552e | 103 | *_M_p |= _M_mask; |
ed6814f7 | 104 | else |
ba9d552e BK |
105 | *_M_p &= ~_M_mask; |
106 | return *this; | |
107 | } | |
108 | ||
1ae8edf5 | 109 | _GLIBCXX20_CONSTEXPR |
ed6814f7 | 110 | _Bit_reference& |
d3677132 | 111 | operator=(const _Bit_reference& __x) _GLIBCXX_NOEXCEPT |
725dc051 | 112 | { return *this = bool(__x); } |
ba9d552e | 113 | |
1ae8edf5 | 114 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
ed6814f7 | 115 | bool |
ba9d552e | 116 | operator==(const _Bit_reference& __x) const |
725dc051 | 117 | { return bool(*this) == bool(__x); } |
ba9d552e | 118 | |
1ae8edf5 | 119 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
ed6814f7 | 120 | bool |
ba9d552e | 121 | operator<(const _Bit_reference& __x) const |
172f7610 | 122 | { return !bool(*this) && bool(__x); } |
725dc051 | 123 | |
1ae8edf5 | 124 | _GLIBCXX20_CONSTEXPR |
ed6814f7 | 125 | void |
d3677132 | 126 | flip() _GLIBCXX_NOEXCEPT |
705debec | 127 | { *_M_p ^= _M_mask; } |
ba9d552e | 128 | |
734f5023 | 129 | #if __cplusplus >= 201103L |
59434931 JW |
130 | _GLIBCXX20_CONSTEXPR |
131 | friend void | |
132 | swap(_Bit_reference __x, _Bit_reference __y) noexcept | |
133 | { | |
134 | bool __tmp = __x; | |
135 | __x = __y; | |
136 | __y = __tmp; | |
137 | } | |
93d9a365 | 138 | |
59434931 JW |
139 | _GLIBCXX20_CONSTEXPR |
140 | friend void | |
141 | swap(_Bit_reference __x, bool& __y) noexcept | |
142 | { | |
143 | bool __tmp = __x; | |
144 | __x = __y; | |
145 | __y = __tmp; | |
146 | } | |
93d9a365 | 147 | |
59434931 JW |
148 | _GLIBCXX20_CONSTEXPR |
149 | friend void | |
150 | swap(bool& __x, _Bit_reference __y) noexcept | |
151 | { | |
152 | bool __tmp = __x; | |
153 | __x = __y; | |
154 | __y = __tmp; | |
155 | } | |
93d9a365 | 156 | #endif |
59434931 | 157 | }; |
93d9a365 | 158 | |
6323b34e PC |
159 | struct _Bit_iterator_base |
160 | : public std::iterator<std::random_access_iterator_tag, bool> | |
ba9d552e BK |
161 | { |
162 | _Bit_type * _M_p; | |
163 | unsigned int _M_offset; | |
725dc051 | 164 | |
1ae8edf5 | 165 | _GLIBCXX20_CONSTEXPR |
ba9d552e BK |
166 | _Bit_iterator_base(_Bit_type * __x, unsigned int __y) |
167 | : _M_p(__x), _M_offset(__y) { } | |
725dc051 | 168 | |
1ae8edf5 | 169 | _GLIBCXX20_CONSTEXPR |
ed6814f7 BI |
170 | void |
171 | _M_bump_up() | |
ba9d552e | 172 | { |
a9dd5a46 | 173 | if (_M_offset++ == int(_S_word_bit) - 1) |
ba9d552e BK |
174 | { |
175 | _M_offset = 0; | |
176 | ++_M_p; | |
177 | } | |
725dc051 | 178 | } |
ba9d552e | 179 | |
1ae8edf5 | 180 | _GLIBCXX20_CONSTEXPR |
ed6814f7 BI |
181 | void |
182 | _M_bump_down() | |
ba9d552e | 183 | { |
ed6814f7 | 184 | if (_M_offset-- == 0) |
ba9d552e | 185 | { |
a9dd5a46 | 186 | _M_offset = int(_S_word_bit) - 1; |
ba9d552e BK |
187 | --_M_p; |
188 | } | |
189 | } | |
ed6814f7 | 190 | |
1ae8edf5 | 191 | _GLIBCXX20_CONSTEXPR |
ed6814f7 BI |
192 | void |
193 | _M_incr(ptrdiff_t __i) | |
ba9d552e BK |
194 | { |
195 | difference_type __n = __i + _M_offset; | |
a9dd5a46 PC |
196 | _M_p += __n / int(_S_word_bit); |
197 | __n = __n % int(_S_word_bit); | |
ed6814f7 | 198 | if (__n < 0) |
ba9d552e | 199 | { |
22a8ed65 | 200 | __n += int(_S_word_bit); |
ba9d552e | 201 | --_M_p; |
ed6814f7 | 202 | } |
22a8ed65 | 203 | _M_offset = static_cast<unsigned int>(__n); |
ba9d552e | 204 | } |
ed6814f7 | 205 | |
0d04fe49 | 206 | _GLIBCXX_NODISCARD |
bd2420f8 | 207 | friend _GLIBCXX20_CONSTEXPR bool |
e9c54233 FD |
208 | operator==(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) |
209 | { return __x._M_p == __y._M_p && __x._M_offset == __y._M_offset; } | |
ed6814f7 | 210 | |
bd2420f8 | 211 | #if __cpp_lib_three_way_comparison |
0d04fe49 | 212 | [[nodiscard]] |
bd2420f8 JW |
213 | friend constexpr strong_ordering |
214 | operator<=>(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) | |
215 | noexcept | |
216 | { | |
217 | if (const auto __cmp = __x._M_p <=> __y._M_p; __cmp != 0) | |
218 | return __cmp; | |
219 | return __x._M_offset <=> __y._M_offset; | |
220 | } | |
221 | #else | |
0d04fe49 | 222 | _GLIBCXX_NODISCARD |
e9c54233 FD |
223 | friend bool |
224 | operator<(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) | |
ba9d552e | 225 | { |
e9c54233 FD |
226 | return __x._M_p < __y._M_p |
227 | || (__x._M_p == __y._M_p && __x._M_offset < __y._M_offset); | |
725dc051 | 228 | } |
725dc051 | 229 | |
0d04fe49 | 230 | _GLIBCXX_NODISCARD |
e9c54233 FD |
231 | friend bool |
232 | operator!=(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) | |
233 | { return !(__x == __y); } | |
ed6814f7 | 234 | |
0d04fe49 | 235 | _GLIBCXX_NODISCARD |
e9c54233 FD |
236 | friend bool |
237 | operator>(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) | |
238 | { return __y < __x; } | |
725dc051 | 239 | |
0d04fe49 | 240 | _GLIBCXX_NODISCARD |
e9c54233 FD |
241 | friend bool |
242 | operator<=(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) | |
243 | { return !(__y < __x); } | |
ba9d552e | 244 | |
0d04fe49 | 245 | _GLIBCXX_NODISCARD |
e9c54233 FD |
246 | friend bool |
247 | operator>=(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) | |
248 | { return !(__x < __y); } | |
bd2420f8 | 249 | #endif // three-way comparison |
ba9d552e | 250 | |
1ae8edf5 | 251 | friend _GLIBCXX20_CONSTEXPR ptrdiff_t |
e9c54233 FD |
252 | operator-(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) |
253 | { | |
254 | return (int(_S_word_bit) * (__x._M_p - __y._M_p) | |
255 | + __x._M_offset - __y._M_offset); | |
256 | } | |
257 | }; | |
725dc051 | 258 | |
ba9d552e BK |
259 | struct _Bit_iterator : public _Bit_iterator_base |
260 | { | |
261 | typedef _Bit_reference reference; | |
9aeb3bef JW |
262 | #if __cplusplus > 201703L |
263 | typedef void pointer; | |
264 | #else | |
ba9d552e | 265 | typedef _Bit_reference* pointer; |
9aeb3bef | 266 | #endif |
ba9d552e | 267 | typedef _Bit_iterator iterator; |
725dc051 | 268 | |
1ae8edf5 | 269 | _GLIBCXX20_CONSTEXPR |
ba9d552e | 270 | _Bit_iterator() : _Bit_iterator_base(0, 0) { } |
705debec | 271 | |
1ae8edf5 | 272 | _GLIBCXX20_CONSTEXPR |
ed6814f7 | 273 | _Bit_iterator(_Bit_type * __x, unsigned int __y) |
ba9d552e | 274 | : _Bit_iterator_base(__x, __y) { } |
ed6814f7 | 275 | |
1ae8edf5 | 276 | _GLIBCXX20_CONSTEXPR |
7b61c5a9 PC |
277 | iterator |
278 | _M_const_cast() const | |
279 | { return *this; } | |
280 | ||
1ae8edf5 | 281 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
ed6814f7 | 282 | reference |
705debec PC |
283 | operator*() const |
284 | { return reference(_M_p, 1UL << _M_offset); } | |
725dc051 | 285 | |
1ae8edf5 | 286 | _GLIBCXX20_CONSTEXPR |
ed6814f7 BI |
287 | iterator& |
288 | operator++() | |
ba9d552e BK |
289 | { |
290 | _M_bump_up(); | |
291 | return *this; | |
292 | } | |
ed6814f7 | 293 | |
1ae8edf5 | 294 | _GLIBCXX20_CONSTEXPR |
ed6814f7 BI |
295 | iterator |
296 | operator++(int) | |
ba9d552e BK |
297 | { |
298 | iterator __tmp = *this; | |
299 | _M_bump_up(); | |
300 | return __tmp; | |
301 | } | |
725dc051 | 302 | |
1ae8edf5 | 303 | _GLIBCXX20_CONSTEXPR |
ed6814f7 BI |
304 | iterator& |
305 | operator--() | |
ba9d552e BK |
306 | { |
307 | _M_bump_down(); | |
308 | return *this; | |
309 | } | |
725dc051 | 310 | |
1ae8edf5 | 311 | _GLIBCXX20_CONSTEXPR |
ed6814f7 BI |
312 | iterator |
313 | operator--(int) | |
ba9d552e BK |
314 | { |
315 | iterator __tmp = *this; | |
316 | _M_bump_down(); | |
317 | return __tmp; | |
318 | } | |
725dc051 | 319 | |
1ae8edf5 | 320 | _GLIBCXX20_CONSTEXPR |
ed6814f7 BI |
321 | iterator& |
322 | operator+=(difference_type __i) | |
ba9d552e BK |
323 | { |
324 | _M_incr(__i); | |
325 | return *this; | |
326 | } | |
725dc051 | 327 | |
1ae8edf5 | 328 | _GLIBCXX20_CONSTEXPR |
ba9d552e | 329 | iterator& |
ed6814f7 | 330 | operator-=(difference_type __i) |
ba9d552e BK |
331 | { |
332 | *this += -__i; | |
333 | return *this; | |
334 | } | |
725dc051 | 335 | |
1ae8edf5 | 336 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
e9c54233 FD |
337 | reference |
338 | operator[](difference_type __i) const | |
339 | { return *(*this + __i); } | |
340 | ||
0d04fe49 | 341 | _GLIBCXX_NODISCARD |
1ae8edf5 | 342 | friend _GLIBCXX20_CONSTEXPR iterator |
e9c54233 | 343 | operator+(const iterator& __x, difference_type __n) |
ba9d552e | 344 | { |
e9c54233 FD |
345 | iterator __tmp = __x; |
346 | __tmp += __n; | |
347 | return __tmp; | |
ba9d552e | 348 | } |
ed6814f7 | 349 | |
0d04fe49 | 350 | _GLIBCXX_NODISCARD |
1ae8edf5 | 351 | friend _GLIBCXX20_CONSTEXPR iterator |
e9c54233 FD |
352 | operator+(difference_type __n, const iterator& __x) |
353 | { return __x + __n; } | |
354 | ||
0d04fe49 | 355 | _GLIBCXX_NODISCARD |
1ae8edf5 | 356 | friend _GLIBCXX20_CONSTEXPR iterator |
e9c54233 | 357 | operator-(const iterator& __x, difference_type __n) |
ba9d552e | 358 | { |
e9c54233 FD |
359 | iterator __tmp = __x; |
360 | __tmp -= __n; | |
361 | return __tmp; | |
ba9d552e | 362 | } |
ba9d552e | 363 | }; |
ed6814f7 | 364 | |
ba9d552e BK |
365 | struct _Bit_const_iterator : public _Bit_iterator_base |
366 | { | |
367 | typedef bool reference; | |
368 | typedef bool const_reference; | |
9aeb3bef JW |
369 | #if __cplusplus > 201703L |
370 | typedef void pointer; | |
371 | #else | |
ba9d552e | 372 | typedef const bool* pointer; |
9aeb3bef | 373 | #endif |
ba9d552e | 374 | typedef _Bit_const_iterator const_iterator; |
ed6814f7 | 375 | |
1ae8edf5 | 376 | _GLIBCXX20_CONSTEXPR |
ba9d552e | 377 | _Bit_const_iterator() : _Bit_iterator_base(0, 0) { } |
705debec | 378 | |
1ae8edf5 | 379 | _GLIBCXX20_CONSTEXPR |
ed6814f7 | 380 | _Bit_const_iterator(_Bit_type * __x, unsigned int __y) |
ba9d552e | 381 | : _Bit_iterator_base(__x, __y) { } |
705debec | 382 | |
1ae8edf5 | 383 | _GLIBCXX20_CONSTEXPR |
ed6814f7 | 384 | _Bit_const_iterator(const _Bit_iterator& __x) |
ba9d552e BK |
385 | : _Bit_iterator_base(__x._M_p, __x._M_offset) { } |
386 | ||
1ae8edf5 | 387 | _GLIBCXX20_CONSTEXPR |
94938aec PC |
388 | _Bit_iterator |
389 | _M_const_cast() const | |
390 | { return _Bit_iterator(_M_p, _M_offset); } | |
391 | ||
1ae8edf5 | 392 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
ed6814f7 BI |
393 | const_reference |
394 | operator*() const | |
ba9d552e | 395 | { return _Bit_reference(_M_p, 1UL << _M_offset); } |
ed6814f7 | 396 | |
1ae8edf5 | 397 | _GLIBCXX20_CONSTEXPR |
ed6814f7 BI |
398 | const_iterator& |
399 | operator++() | |
ba9d552e BK |
400 | { |
401 | _M_bump_up(); | |
402 | return *this; | |
403 | } | |
404 | ||
1ae8edf5 | 405 | _GLIBCXX20_CONSTEXPR |
ed6814f7 BI |
406 | const_iterator |
407 | operator++(int) | |
ba9d552e BK |
408 | { |
409 | const_iterator __tmp = *this; | |
410 | _M_bump_up(); | |
411 | return __tmp; | |
412 | } | |
725dc051 | 413 | |
1ae8edf5 | 414 | _GLIBCXX20_CONSTEXPR |
ed6814f7 BI |
415 | const_iterator& |
416 | operator--() | |
ba9d552e BK |
417 | { |
418 | _M_bump_down(); | |
419 | return *this; | |
420 | } | |
421 | ||
1ae8edf5 | 422 | _GLIBCXX20_CONSTEXPR |
ed6814f7 BI |
423 | const_iterator |
424 | operator--(int) | |
ba9d552e BK |
425 | { |
426 | const_iterator __tmp = *this; | |
427 | _M_bump_down(); | |
428 | return __tmp; | |
429 | } | |
725dc051 | 430 | |
1ae8edf5 | 431 | _GLIBCXX20_CONSTEXPR |
ed6814f7 BI |
432 | const_iterator& |
433 | operator+=(difference_type __i) | |
ba9d552e BK |
434 | { |
435 | _M_incr(__i); | |
436 | return *this; | |
437 | } | |
438 | ||
1ae8edf5 | 439 | _GLIBCXX20_CONSTEXPR |
ed6814f7 BI |
440 | const_iterator& |
441 | operator-=(difference_type __i) | |
ba9d552e BK |
442 | { |
443 | *this += -__i; | |
444 | return *this; | |
445 | } | |
446 | ||
1ae8edf5 | 447 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
e9c54233 FD |
448 | const_reference |
449 | operator[](difference_type __i) const | |
450 | { return *(*this + __i); } | |
451 | ||
0d04fe49 | 452 | _GLIBCXX_NODISCARD |
1ae8edf5 | 453 | friend _GLIBCXX20_CONSTEXPR const_iterator |
e9c54233 | 454 | operator+(const const_iterator& __x, difference_type __n) |
43da93a7 | 455 | { |
e9c54233 FD |
456 | const_iterator __tmp = __x; |
457 | __tmp += __n; | |
458 | return __tmp; | |
ba9d552e | 459 | } |
725dc051 | 460 | |
0d04fe49 | 461 | _GLIBCXX_NODISCARD |
1ae8edf5 | 462 | friend _GLIBCXX20_CONSTEXPR const_iterator |
e9c54233 | 463 | operator-(const const_iterator& __x, difference_type __n) |
ba9d552e | 464 | { |
e9c54233 FD |
465 | const_iterator __tmp = __x; |
466 | __tmp -= __n; | |
467 | return __tmp; | |
ba9d552e BK |
468 | } |
469 | ||
0d04fe49 | 470 | _GLIBCXX_NODISCARD |
1ae8edf5 | 471 | friend _GLIBCXX20_CONSTEXPR const_iterator |
e9c54233 FD |
472 | operator+(difference_type __n, const const_iterator& __x) |
473 | { return __x + __n; } | |
ba9d552e | 474 | }; |
ed6814f7 | 475 | |
232c4925 | 476 | template<typename _Alloc> |
fd09ac0c | 477 | struct _Bvector_base |
ba9d552e | 478 | { |
ccd615e3 JW |
479 | typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template |
480 | rebind<_Bit_type>::other _Bit_alloc_type; | |
481 | typedef typename __gnu_cxx::__alloc_traits<_Bit_alloc_type> | |
482 | _Bit_alloc_traits; | |
483 | typedef typename _Bit_alloc_traits::pointer _Bit_pointer; | |
484 | ||
7d594224 | 485 | struct _Bvector_impl_data |
390e4c0d | 486 | { |
6f00ccba FD |
487 | #if !_GLIBCXX_INLINE_VERSION |
488 | _Bit_iterator _M_start; | |
489 | #else | |
490 | // We don't need the offset field for the start, it's always zero. | |
491 | struct { | |
492 | _Bit_type* _M_p; | |
493 | // Allow assignment from iterators (assume offset is zero): | |
1ae8edf5 | 494 | _GLIBCXX20_CONSTEXPR |
6f00ccba FD |
495 | void operator=(_Bit_iterator __it) { _M_p = __it._M_p; } |
496 | } _M_start; | |
497 | #endif | |
498 | _Bit_iterator _M_finish; | |
499 | _Bit_pointer _M_end_of_storage; | |
78b36b70 | 500 | |
1ae8edf5 | 501 | _GLIBCXX20_CONSTEXPR |
7d594224 FD |
502 | _Bvector_impl_data() _GLIBCXX_NOEXCEPT |
503 | : _M_start(), _M_finish(), _M_end_of_storage() | |
390e4c0d | 504 | { } |
6f59ea25 | 505 | |
734f5023 | 506 | #if __cplusplus >= 201103L |
6f00ccba | 507 | _Bvector_impl_data(const _Bvector_impl_data&) = default; |
1ae8edf5 | 508 | |
6f00ccba FD |
509 | _Bvector_impl_data& |
510 | operator=(const _Bvector_impl_data&) = default; | |
511 | ||
1ae8edf5 | 512 | _GLIBCXX20_CONSTEXPR |
7d594224 | 513 | _Bvector_impl_data(_Bvector_impl_data&& __x) noexcept |
6f00ccba | 514 | : _Bvector_impl_data(__x) |
7d594224 FD |
515 | { __x._M_reset(); } |
516 | ||
1ae8edf5 | 517 | _GLIBCXX20_CONSTEXPR |
7d594224 FD |
518 | void |
519 | _M_move_data(_Bvector_impl_data&& __x) noexcept | |
520 | { | |
6f00ccba | 521 | *this = __x; |
7d594224 FD |
522 | __x._M_reset(); |
523 | } | |
524 | #endif | |
525 | ||
1ae8edf5 | 526 | _GLIBCXX20_CONSTEXPR |
7d594224 FD |
527 | void |
528 | _M_reset() _GLIBCXX_NOEXCEPT | |
6f00ccba FD |
529 | { *this = _Bvector_impl_data(); } |
530 | ||
1ae8edf5 | 531 | _GLIBCXX20_CONSTEXPR |
6f00ccba FD |
532 | void |
533 | _M_swap_data(_Bvector_impl_data& __x) _GLIBCXX_NOEXCEPT | |
7d594224 | 534 | { |
6f00ccba FD |
535 | // Do not use std::swap(_M_start, __x._M_start), etc as it loses |
536 | // information used by TBAA. | |
537 | std::swap(*this, __x); | |
7d594224 FD |
538 | } |
539 | }; | |
540 | ||
541 | struct _Bvector_impl | |
542 | : public _Bit_alloc_type, public _Bvector_impl_data | |
6f00ccba | 543 | { |
1ae8edf5 | 544 | _GLIBCXX20_CONSTEXPR |
6f00ccba FD |
545 | _Bvector_impl() _GLIBCXX_NOEXCEPT_IF( |
546 | is_nothrow_default_constructible<_Bit_alloc_type>::value) | |
547 | : _Bit_alloc_type() | |
548 | { } | |
7d594224 | 549 | |
1ae8edf5 | 550 | _GLIBCXX20_CONSTEXPR |
6f00ccba FD |
551 | _Bvector_impl(const _Bit_alloc_type& __a) _GLIBCXX_NOEXCEPT |
552 | : _Bit_alloc_type(__a) | |
553 | { } | |
7d594224 FD |
554 | |
555 | #if __cplusplus >= 201103L | |
6f00ccba FD |
556 | // Not defaulted, to enforce noexcept(true) even when |
557 | // !is_nothrow_move_constructible<_Bit_alloc_type>. | |
1ae8edf5 | 558 | _GLIBCXX20_CONSTEXPR |
6f00ccba FD |
559 | _Bvector_impl(_Bvector_impl&& __x) noexcept |
560 | : _Bit_alloc_type(std::move(__x)), _Bvector_impl_data(std::move(__x)) | |
561 | { } | |
562 | ||
1ae8edf5 | 563 | _GLIBCXX20_CONSTEXPR |
6f00ccba FD |
564 | _Bvector_impl(_Bit_alloc_type&& __a, _Bvector_impl&& __x) noexcept |
565 | : _Bit_alloc_type(std::move(__a)), _Bvector_impl_data(std::move(__x)) | |
566 | { } | |
6f59ea25 | 567 | #endif |
ccd615e3 | 568 | |
1ae8edf5 | 569 | _GLIBCXX20_CONSTEXPR |
ccd615e3 JW |
570 | _Bit_type* |
571 | _M_end_addr() const _GLIBCXX_NOEXCEPT | |
572 | { | |
7d594224 FD |
573 | if (this->_M_end_of_storage) |
574 | return std::__addressof(this->_M_end_of_storage[-1]) + 1; | |
ccd615e3 JW |
575 | return 0; |
576 | } | |
390e4c0d | 577 | }; |
ba9d552e BK |
578 | |
579 | public: | |
580 | typedef _Alloc allocator_type; | |
ed6814f7 | 581 | |
1ae8edf5 | 582 | _GLIBCXX20_CONSTEXPR |
fd09ac0c | 583 | _Bit_alloc_type& |
d3677132 | 584 | _M_get_Bit_allocator() _GLIBCXX_NOEXCEPT |
7d594224 | 585 | { return this->_M_impl; } |
fd09ac0c | 586 | |
1ae8edf5 | 587 | _GLIBCXX20_CONSTEXPR |
fd09ac0c | 588 | const _Bit_alloc_type& |
d3677132 | 589 | _M_get_Bit_allocator() const _GLIBCXX_NOEXCEPT |
7d594224 | 590 | { return this->_M_impl; } |
fd09ac0c | 591 | |
1ae8edf5 | 592 | _GLIBCXX20_CONSTEXPR |
62e67651 | 593 | allocator_type |
d3677132 | 594 | get_allocator() const _GLIBCXX_NOEXCEPT |
fd09ac0c | 595 | { return allocator_type(_M_get_Bit_allocator()); } |
ed6814f7 | 596 | |
7d594224 FD |
597 | #if __cplusplus >= 201103L |
598 | _Bvector_base() = default; | |
599 | #else | |
600 | _Bvector_base() { } | |
601 | #endif | |
b6d03af0 | 602 | |
1ae8edf5 | 603 | _GLIBCXX20_CONSTEXPR |
78b36b70 PC |
604 | _Bvector_base(const allocator_type& __a) |
605 | : _M_impl(__a) { } | |
ba9d552e | 606 | |
734f5023 | 607 | #if __cplusplus >= 201103L |
7d594224 | 608 | _Bvector_base(_Bvector_base&&) = default; |
6f00ccba | 609 | |
1ae8edf5 | 610 | _GLIBCXX20_CONSTEXPR |
6f00ccba FD |
611 | _Bvector_base(_Bvector_base&& __x, const allocator_type& __a) noexcept |
612 | : _M_impl(_Bit_alloc_type(__a), std::move(__x._M_impl)) | |
613 | { } | |
053cc380 PC |
614 | #endif |
615 | ||
1ae8edf5 | 616 | _GLIBCXX20_CONSTEXPR |
705debec PC |
617 | ~_Bvector_base() |
618 | { this->_M_deallocate(); } | |
ba9d552e BK |
619 | |
620 | protected: | |
390e4c0d BK |
621 | _Bvector_impl _M_impl; |
622 | ||
1ae8edf5 | 623 | _GLIBCXX20_CONSTEXPR |
ccd615e3 | 624 | _Bit_pointer |
390e4c0d | 625 | _M_allocate(size_t __n) |
1ae8edf5 JW |
626 | { |
627 | _Bit_pointer __p = _Bit_alloc_traits::allocate(_M_impl, _S_nword(__n)); | |
74d14778 JW |
628 | #if __cpp_lib_is_constant_evaluated |
629 | if (std::is_constant_evaluated()) | |
1ae8edf5 JW |
630 | { |
631 | __n = _S_nword(__n); | |
632 | for (size_t __i = 0; __i < __n; ++__i) | |
633 | __p[__i] = 0ul; | |
634 | } | |
635 | #endif | |
636 | return __p; | |
637 | } | |
ba9d552e | 638 | |
1ae8edf5 | 639 | _GLIBCXX20_CONSTEXPR |
ed6814f7 BI |
640 | void |
641 | _M_deallocate() | |
ba9d552e | 642 | { |
390e4c0d | 643 | if (_M_impl._M_start._M_p) |
ccd615e3 JW |
644 | { |
645 | const size_t __n = _M_impl._M_end_addr() - _M_impl._M_start._M_p; | |
646 | _Bit_alloc_traits::deallocate(_M_impl, | |
647 | _M_impl._M_end_of_storage - __n, | |
648 | __n); | |
7d594224 | 649 | _M_impl._M_reset(); |
ccd615e3 | 650 | } |
ed6814f7 | 651 | } |
8a752dfe | 652 | |
7d594224 | 653 | #if __cplusplus >= 201103L |
1ae8edf5 | 654 | _GLIBCXX20_CONSTEXPR |
7d594224 FD |
655 | void |
656 | _M_move_data(_Bvector_base&& __x) noexcept | |
657 | { _M_impl._M_move_data(std::move(__x._M_impl)); } | |
658 | #endif | |
659 | ||
1ae8edf5 | 660 | _GLIBCXX_CONSTEXPR |
8a752dfe FD |
661 | static size_t |
662 | _S_nword(size_t __n) | |
663 | { return (__n + int(_S_word_bit) - 1) / int(_S_word_bit); } | |
ba9d552e | 664 | }; |
3cbc7af0 | 665 | |
ffcec5c8 JQ |
666 | /** |
667 | * @brief A specialization of vector for booleans which offers fixed time | |
668 | * access to individual elements in any order. | |
669 | * | |
d632488a BK |
670 | * @ingroup sequences |
671 | * | |
672 | * @tparam _Alloc Allocator type. | |
673 | * | |
ffcec5c8 JQ |
674 | * Note that vector<bool> does not actually meet the requirements for being |
675 | * a container. This is because the reference and pointer types are not | |
676 | * really references and pointers to bool. See DR96 for details. @see | |
677 | * vector for function documentation. | |
678 | * | |
ba9d552e BK |
679 | * In some terminology a %vector can be described as a dynamic |
680 | * C-style array, it offers fast and efficient access to individual | |
681 | * elements in any order and saves the user from worrying about | |
682 | * memory and size allocation. Subscripting ( @c [] ) access is | |
683 | * also provided as with C-style arrays. | |
ffcec5c8 | 684 | */ |
7d594224 FD |
685 | template<typename _Alloc> |
686 | class vector<bool, _Alloc> : protected _Bvector_base<_Alloc> | |
687 | { | |
688 | typedef _Bvector_base<_Alloc> _Base; | |
689 | typedef typename _Base::_Bit_pointer _Bit_pointer; | |
690 | typedef typename _Base::_Bit_alloc_traits _Bit_alloc_traits; | |
ed6814f7 | 691 | |
734f5023 | 692 | #if __cplusplus >= 201103L |
5dfb5e5b | 693 | friend struct std::hash<vector>; |
4cd533a7 PC |
694 | #endif |
695 | ||
7d594224 FD |
696 | public: |
697 | typedef bool value_type; | |
698 | typedef size_t size_type; | |
699 | typedef ptrdiff_t difference_type; | |
700 | typedef _Bit_reference reference; | |
701 | typedef bool const_reference; | |
702 | typedef _Bit_reference* pointer; | |
703 | typedef const bool* const_pointer; | |
704 | typedef _Bit_iterator iterator; | |
705 | typedef _Bit_const_iterator const_iterator; | |
706 | typedef std::reverse_iterator<const_iterator> const_reverse_iterator; | |
707 | typedef std::reverse_iterator<iterator> reverse_iterator; | |
708 | typedef _Alloc allocator_type; | |
78b36b70 | 709 | |
1ae8edf5 | 710 | _GLIBCXX20_CONSTEXPR |
7d594224 FD |
711 | allocator_type |
712 | get_allocator() const | |
713 | { return _Base::get_allocator(); } | |
714 | ||
715 | protected: | |
716 | using _Base::_M_allocate; | |
717 | using _Base::_M_deallocate; | |
718 | using _Base::_S_nword; | |
719 | using _Base::_M_get_Bit_allocator; | |
fd09ac0c | 720 | |
7d594224 | 721 | public: |
734f5023 | 722 | #if __cplusplus >= 201103L |
7d594224 | 723 | vector() = default; |
d720a22b | 724 | #else |
7d594224 | 725 | vector() { } |
d720a22b | 726 | #endif |
62e67651 | 727 | |
1ae8edf5 | 728 | _GLIBCXX20_CONSTEXPR |
7d594224 FD |
729 | explicit |
730 | vector(const allocator_type& __a) | |
731 | : _Base(__a) { } | |
ed6814f7 | 732 | |
734f5023 | 733 | #if __cplusplus >= 201103L |
1ae8edf5 | 734 | _GLIBCXX20_CONSTEXPR |
7d594224 FD |
735 | explicit |
736 | vector(size_type __n, const allocator_type& __a = allocator_type()) | |
737 | : vector(__n, false, __a) | |
738 | { } | |
ccd615e3 | 739 | |
1ae8edf5 | 740 | _GLIBCXX20_CONSTEXPR |
b6d03af0 | 741 | vector(size_type __n, const bool& __value, |
7d594224 FD |
742 | const allocator_type& __a = allocator_type()) |
743 | #else | |
744 | explicit | |
b6d03af0 | 745 | vector(size_type __n, const bool& __value = bool(), |
7d594224 | 746 | const allocator_type& __a = allocator_type()) |
78b36b70 | 747 | #endif |
7d594224 FD |
748 | : _Base(__a) |
749 | { | |
750 | _M_initialize(__n); | |
751 | _M_initialize_value(__value); | |
752 | } | |
753 | ||
1ae8edf5 | 754 | _GLIBCXX20_CONSTEXPR |
7d594224 FD |
755 | vector(const vector& __x) |
756 | : _Base(_Bit_alloc_traits::_S_select_on_copy(__x._M_get_Bit_allocator())) | |
757 | { | |
758 | _M_initialize(__x.size()); | |
6f00ccba | 759 | _M_copy_aligned(__x.begin(), __x.end(), begin()); |
7d594224 | 760 | } |
78b36b70 | 761 | |
734f5023 | 762 | #if __cplusplus >= 201103L |
7d594224 FD |
763 | vector(vector&&) = default; |
764 | ||
6f00ccba | 765 | private: |
1ae8edf5 | 766 | _GLIBCXX20_CONSTEXPR |
6f00ccba FD |
767 | vector(vector&& __x, const allocator_type& __a, true_type) noexcept |
768 | : _Base(std::move(__x), __a) | |
769 | { } | |
770 | ||
1ae8edf5 | 771 | _GLIBCXX20_CONSTEXPR |
6f00ccba | 772 | vector(vector&& __x, const allocator_type& __a, false_type) |
2203cb90 | 773 | : _Base(__a) |
7d594224 FD |
774 | { |
775 | if (__x.get_allocator() == __a) | |
776 | this->_M_move_data(std::move(__x)); | |
777 | else | |
778 | { | |
779 | _M_initialize(__x.size()); | |
780 | _M_copy_aligned(__x.begin(), __x.end(), begin()); | |
781 | __x.clear(); | |
782 | } | |
783 | } | |
784 | ||
6f00ccba | 785 | public: |
1ae8edf5 | 786 | _GLIBCXX20_CONSTEXPR |
22d34a2a | 787 | vector(vector&& __x, const __type_identity_t<allocator_type>& __a) |
6f00ccba FD |
788 | noexcept(_Bit_alloc_traits::_S_always_equal()) |
789 | : vector(std::move(__x), __a, | |
790 | typename _Bit_alloc_traits::is_always_equal{}) | |
791 | { } | |
792 | ||
1ae8edf5 | 793 | _GLIBCXX20_CONSTEXPR |
22d34a2a | 794 | vector(const vector& __x, const __type_identity_t<allocator_type>& __a) |
7d594224 FD |
795 | : _Base(__a) |
796 | { | |
797 | _M_initialize(__x.size()); | |
6f00ccba | 798 | _M_copy_aligned(__x.begin(), __x.end(), begin()); |
7d594224 FD |
799 | } |
800 | ||
1ae8edf5 | 801 | _GLIBCXX20_CONSTEXPR |
7d594224 | 802 | vector(initializer_list<bool> __l, |
fd09ac0c PC |
803 | const allocator_type& __a = allocator_type()) |
804 | : _Base(__a) | |
705debec | 805 | { |
7d594224 FD |
806 | _M_initialize_range(__l.begin(), __l.end(), |
807 | random_access_iterator_tag()); | |
705debec | 808 | } |
2203cb90 | 809 | #endif |
ed6814f7 | 810 | |
ccd615e3 | 811 | #if __cplusplus >= 201103L |
7d594224 FD |
812 | template<typename _InputIterator, |
813 | typename = std::_RequireInputIter<_InputIterator>> | |
1ae8edf5 | 814 | _GLIBCXX20_CONSTEXPR |
7d594224 FD |
815 | vector(_InputIterator __first, _InputIterator __last, |
816 | const allocator_type& __a = allocator_type()) | |
817 | : _Base(__a) | |
6f00ccba FD |
818 | { |
819 | _M_initialize_range(__first, __last, | |
820 | std::__iterator_category(__first)); | |
821 | } | |
7d594224 FD |
822 | #else |
823 | template<typename _InputIterator> | |
824 | vector(_InputIterator __first, _InputIterator __last, | |
825 | const allocator_type& __a = allocator_type()) | |
826 | : _Base(__a) | |
ccd615e3 | 827 | { |
6f00ccba | 828 | // Check whether it's an integral type. If so, it's not an iterator. |
7d594224 FD |
829 | typedef typename std::__is_integer<_InputIterator>::__type _Integral; |
830 | _M_initialize_dispatch(__first, __last, _Integral()); | |
831 | } | |
832 | #endif | |
833 | ||
1ae8edf5 | 834 | _GLIBCXX20_CONSTEXPR |
7d594224 FD |
835 | ~vector() _GLIBCXX_NOEXCEPT { } |
836 | ||
1ae8edf5 | 837 | _GLIBCXX20_CONSTEXPR |
7d594224 FD |
838 | vector& |
839 | operator=(const vector& __x) | |
840 | { | |
841 | if (&__x == this) | |
842 | return *this; | |
843 | #if __cplusplus >= 201103L | |
844 | if (_Bit_alloc_traits::_S_propagate_on_copy_assign()) | |
845 | { | |
846 | if (this->_M_get_Bit_allocator() != __x._M_get_Bit_allocator()) | |
847 | { | |
848 | this->_M_deallocate(); | |
849 | std::__alloc_on_copy(_M_get_Bit_allocator(), | |
850 | __x._M_get_Bit_allocator()); | |
851 | _M_initialize(__x.size()); | |
852 | } | |
853 | else | |
ccd615e3 JW |
854 | std::__alloc_on_copy(_M_get_Bit_allocator(), |
855 | __x._M_get_Bit_allocator()); | |
7d594224 | 856 | } |
ccd615e3 | 857 | #endif |
7d594224 FD |
858 | if (__x.size() > capacity()) |
859 | { | |
860 | this->_M_deallocate(); | |
861 | _M_initialize(__x.size()); | |
862 | } | |
863 | this->_M_impl._M_finish = _M_copy_aligned(__x.begin(), __x.end(), | |
864 | begin()); | |
865 | return *this; | |
866 | } | |
ed6814f7 | 867 | |
734f5023 | 868 | #if __cplusplus >= 201103L |
1ae8edf5 | 869 | _GLIBCXX20_CONSTEXPR |
7d594224 FD |
870 | vector& |
871 | operator=(vector&& __x) noexcept(_Bit_alloc_traits::_S_nothrow_move()) | |
872 | { | |
873 | if (_Bit_alloc_traits::_S_propagate_on_move_assign() | |
874 | || this->_M_get_Bit_allocator() == __x._M_get_Bit_allocator()) | |
875 | { | |
876 | this->_M_deallocate(); | |
877 | this->_M_move_data(std::move(__x)); | |
878 | std::__alloc_on_move(_M_get_Bit_allocator(), | |
879 | __x._M_get_Bit_allocator()); | |
880 | } | |
881 | else | |
882 | { | |
883 | if (__x.size() > capacity()) | |
884 | { | |
885 | this->_M_deallocate(); | |
886 | _M_initialize(__x.size()); | |
887 | } | |
888 | this->_M_impl._M_finish = _M_copy_aligned(__x.begin(), __x.end(), | |
889 | begin()); | |
890 | __x.clear(); | |
891 | } | |
892 | return *this; | |
893 | } | |
988499f4 | 894 | |
1ae8edf5 | 895 | _GLIBCXX20_CONSTEXPR |
7d594224 FD |
896 | vector& |
897 | operator=(initializer_list<bool> __l) | |
898 | { | |
6f00ccba | 899 | this->assign(__l.begin(), __l.end()); |
7d594224 FD |
900 | return *this; |
901 | } | |
78b36b70 PC |
902 | #endif |
903 | ||
7d594224 FD |
904 | // assign(), a generalized assignment member function. Two |
905 | // versions: one that takes a count, and one that takes a range. | |
906 | // The range version is a member template, so we dispatch on whether | |
907 | // or not the type is an integer. | |
1ae8edf5 | 908 | _GLIBCXX20_CONSTEXPR |
7d594224 FD |
909 | void |
910 | assign(size_type __n, const bool& __x) | |
911 | { _M_fill_assign(__n, __x); } | |
fd09ac0c | 912 | |
734f5023 | 913 | #if __cplusplus >= 201103L |
7d594224 FD |
914 | template<typename _InputIterator, |
915 | typename = std::_RequireInputIter<_InputIterator>> | |
1ae8edf5 | 916 | _GLIBCXX20_CONSTEXPR |
7d594224 FD |
917 | void |
918 | assign(_InputIterator __first, _InputIterator __last) | |
919 | { _M_assign_aux(__first, __last, std::__iterator_category(__first)); } | |
2203cb90 | 920 | #else |
7d594224 FD |
921 | template<typename _InputIterator> |
922 | void | |
923 | assign(_InputIterator __first, _InputIterator __last) | |
924 | { | |
6f00ccba | 925 | // Check whether it's an integral type. If so, it's not an iterator. |
7d594224 FD |
926 | typedef typename std::__is_integer<_InputIterator>::__type _Integral; |
927 | _M_assign_dispatch(__first, __last, _Integral()); | |
928 | } | |
2203cb90 | 929 | #endif |
ed6814f7 | 930 | |
734f5023 | 931 | #if __cplusplus >= 201103L |
1ae8edf5 | 932 | _GLIBCXX20_CONSTEXPR |
7d594224 FD |
933 | void |
934 | assign(initializer_list<bool> __l) | |
935 | { _M_assign_aux(__l.begin(), __l.end(), random_access_iterator_tag()); } | |
988499f4 | 936 | #endif |
79667f82 | 937 | |
1ae8edf5 | 938 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
7d594224 FD |
939 | iterator |
940 | begin() _GLIBCXX_NOEXCEPT | |
86920074 | 941 | { return iterator(this->_M_impl._M_start._M_p, 0); } |
62e67651 | 942 | |
1ae8edf5 | 943 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
7d594224 FD |
944 | const_iterator |
945 | begin() const _GLIBCXX_NOEXCEPT | |
86920074 | 946 | { return const_iterator(this->_M_impl._M_start._M_p, 0); } |
62e67651 | 947 | |
1ae8edf5 | 948 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
7d594224 FD |
949 | iterator |
950 | end() _GLIBCXX_NOEXCEPT | |
951 | { return this->_M_impl._M_finish; } | |
62e67651 | 952 | |
1ae8edf5 | 953 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
7d594224 FD |
954 | const_iterator |
955 | end() const _GLIBCXX_NOEXCEPT | |
956 | { return this->_M_impl._M_finish; } | |
ed6814f7 | 957 | |
1ae8edf5 | 958 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
7d594224 FD |
959 | reverse_iterator |
960 | rbegin() _GLIBCXX_NOEXCEPT | |
961 | { return reverse_iterator(end()); } | |
62e67651 | 962 | |
1ae8edf5 | 963 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
7d594224 FD |
964 | const_reverse_iterator |
965 | rbegin() const _GLIBCXX_NOEXCEPT | |
966 | { return const_reverse_iterator(end()); } | |
62e67651 | 967 | |
1ae8edf5 | 968 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
7d594224 FD |
969 | reverse_iterator |
970 | rend() _GLIBCXX_NOEXCEPT | |
971 | { return reverse_iterator(begin()); } | |
62e67651 | 972 | |
1ae8edf5 | 973 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
7d594224 FD |
974 | const_reverse_iterator |
975 | rend() const _GLIBCXX_NOEXCEPT | |
976 | { return const_reverse_iterator(begin()); } | |
ed6814f7 | 977 | |
734f5023 | 978 | #if __cplusplus >= 201103L |
1ae8edf5 | 979 | [[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
7d594224 FD |
980 | const_iterator |
981 | cbegin() const noexcept | |
86920074 | 982 | { return const_iterator(this->_M_impl._M_start._M_p, 0); } |
0cd50f89 | 983 | |
1ae8edf5 | 984 | [[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
7d594224 FD |
985 | const_iterator |
986 | cend() const noexcept | |
987 | { return this->_M_impl._M_finish; } | |
0cd50f89 | 988 | |
1ae8edf5 | 989 | [[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
7d594224 FD |
990 | const_reverse_iterator |
991 | crbegin() const noexcept | |
992 | { return const_reverse_iterator(end()); } | |
0cd50f89 | 993 | |
1ae8edf5 | 994 | [[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
7d594224 FD |
995 | const_reverse_iterator |
996 | crend() const noexcept | |
997 | { return const_reverse_iterator(begin()); } | |
0cd50f89 PC |
998 | #endif |
999 | ||
1ae8edf5 | 1000 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
7d594224 FD |
1001 | size_type |
1002 | size() const _GLIBCXX_NOEXCEPT | |
1003 | { return size_type(end() - begin()); } | |
62e67651 | 1004 | |
1ae8edf5 | 1005 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
7d594224 FD |
1006 | size_type |
1007 | max_size() const _GLIBCXX_NOEXCEPT | |
1008 | { | |
1009 | const size_type __isize = | |
1010 | __gnu_cxx::__numeric_traits<difference_type>::__max | |
1011 | - int(_S_word_bit) + 1; | |
1012 | const size_type __asize | |
1013 | = _Bit_alloc_traits::max_size(_M_get_Bit_allocator()); | |
1014 | return (__asize <= __isize / int(_S_word_bit) | |
1015 | ? __asize * int(_S_word_bit) : __isize); | |
1016 | } | |
62e67651 | 1017 | |
1ae8edf5 | 1018 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
7d594224 FD |
1019 | size_type |
1020 | capacity() const _GLIBCXX_NOEXCEPT | |
1021 | { return size_type(const_iterator(this->_M_impl._M_end_addr(), 0) | |
1022 | - begin()); } | |
fd09ac0c | 1023 | |
1ae8edf5 JW |
1024 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
1025 | bool | |
7d594224 FD |
1026 | empty() const _GLIBCXX_NOEXCEPT |
1027 | { return begin() == end(); } | |
ed6814f7 | 1028 | |
1ae8edf5 | 1029 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
7d594224 FD |
1030 | reference |
1031 | operator[](size_type __n) | |
6f00ccba | 1032 | { return begin()[__n]; } |
62e67651 | 1033 | |
1ae8edf5 | 1034 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
7d594224 FD |
1035 | const_reference |
1036 | operator[](size_type __n) const | |
6f00ccba | 1037 | { return begin()[__n]; } |
ed6814f7 | 1038 | |
7d594224 | 1039 | protected: |
1ae8edf5 | 1040 | _GLIBCXX20_CONSTEXPR |
7d594224 FD |
1041 | void |
1042 | _M_range_check(size_type __n) const | |
1043 | { | |
1044 | if (__n >= this->size()) | |
1045 | __throw_out_of_range_fmt(__N("vector<bool>::_M_range_check: __n " | |
1046 | "(which is %zu) >= this->size() " | |
1047 | "(which is %zu)"), | |
1048 | __n, this->size()); | |
1049 | } | |
ed6814f7 | 1050 | |
7d594224 | 1051 | public: |
1ae8edf5 | 1052 | _GLIBCXX20_CONSTEXPR |
7d594224 FD |
1053 | reference |
1054 | at(size_type __n) | |
1ae8edf5 JW |
1055 | { |
1056 | _M_range_check(__n); | |
1057 | return (*this)[__n]; | |
1058 | } | |
62e67651 | 1059 | |
1ae8edf5 | 1060 | _GLIBCXX20_CONSTEXPR |
7d594224 FD |
1061 | const_reference |
1062 | at(size_type __n) const | |
1ae8edf5 JW |
1063 | { |
1064 | _M_range_check(__n); | |
1065 | return (*this)[__n]; | |
1066 | } | |
ed6814f7 | 1067 | |
1ae8edf5 | 1068 | _GLIBCXX20_CONSTEXPR |
7d594224 FD |
1069 | void |
1070 | reserve(size_type __n) | |
1071 | { | |
1072 | if (__n > max_size()) | |
1073 | __throw_length_error(__N("vector::reserve")); | |
1074 | if (capacity() < __n) | |
1075 | _M_reallocate(__n); | |
1076 | } | |
ed6814f7 | 1077 | |
1ae8edf5 | 1078 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
7d594224 FD |
1079 | reference |
1080 | front() | |
1081 | { return *begin(); } | |
fd09ac0c | 1082 | |
1ae8edf5 | 1083 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
7d594224 FD |
1084 | const_reference |
1085 | front() const | |
1086 | { return *begin(); } | |
fd09ac0c | 1087 | |
1ae8edf5 | 1088 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
7d594224 FD |
1089 | reference |
1090 | back() | |
1091 | { return *(end() - 1); } | |
1092 | ||
1ae8edf5 | 1093 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
7d594224 FD |
1094 | const_reference |
1095 | back() const | |
1096 | { return *(end() - 1); } | |
1097 | ||
1ae8edf5 | 1098 | _GLIBCXX20_CONSTEXPR |
7d594224 FD |
1099 | void |
1100 | push_back(bool __x) | |
1101 | { | |
1102 | if (this->_M_impl._M_finish._M_p != this->_M_impl._M_end_addr()) | |
1103 | *this->_M_impl._M_finish++ = __x; | |
1104 | else | |
1105 | _M_insert_aux(end(), __x); | |
1106 | } | |
fd09ac0c | 1107 | |
1ae8edf5 | 1108 | _GLIBCXX20_CONSTEXPR |
7d594224 FD |
1109 | void |
1110 | swap(vector& __x) _GLIBCXX_NOEXCEPT | |
1111 | { | |
6f00ccba FD |
1112 | #if __cplusplus >= 201103L |
1113 | __glibcxx_assert(_Bit_alloc_traits::propagate_on_container_swap::value | |
1114 | || _M_get_Bit_allocator() == __x._M_get_Bit_allocator()); | |
1115 | #endif | |
1116 | this->_M_impl._M_swap_data(__x._M_impl); | |
7d594224 FD |
1117 | _Bit_alloc_traits::_S_on_swap(_M_get_Bit_allocator(), |
1118 | __x._M_get_Bit_allocator()); | |
1119 | } | |
ed6814f7 | 1120 | |
7d594224 | 1121 | // [23.2.5]/1, third-to-last entry in synopsis listing |
1ae8edf5 | 1122 | _GLIBCXX20_CONSTEXPR |
7d594224 FD |
1123 | static void |
1124 | swap(reference __x, reference __y) _GLIBCXX_NOEXCEPT | |
1125 | { | |
1126 | bool __tmp = __x; | |
1127 | __x = __y; | |
1128 | __y = __tmp; | |
1129 | } | |
ed6814f7 | 1130 | |
1ae8edf5 | 1131 | _GLIBCXX20_CONSTEXPR |
7d594224 FD |
1132 | iterator |
1133 | #if __cplusplus >= 201103L | |
1134 | insert(const_iterator __position, const bool& __x = bool()) | |
1135 | #else | |
1136 | insert(iterator __position, const bool& __x = bool()) | |
1137 | #endif | |
1138 | { | |
1139 | const difference_type __n = __position - begin(); | |
1140 | if (this->_M_impl._M_finish._M_p != this->_M_impl._M_end_addr() | |
1141 | && __position == end()) | |
1142 | *this->_M_impl._M_finish++ = __x; | |
1143 | else | |
1144 | _M_insert_aux(__position._M_const_cast(), __x); | |
1145 | return begin() + __n; | |
1146 | } | |
ed6814f7 | 1147 | |
7b61c5a9 | 1148 | #if __cplusplus >= 201103L |
7d594224 FD |
1149 | template<typename _InputIterator, |
1150 | typename = std::_RequireInputIter<_InputIterator>> | |
1ae8edf5 | 1151 | _GLIBCXX20_CONSTEXPR |
7d594224 FD |
1152 | iterator |
1153 | insert(const_iterator __position, | |
1154 | _InputIterator __first, _InputIterator __last) | |
1155 | { | |
1156 | difference_type __offset = __position - cbegin(); | |
6f00ccba FD |
1157 | _M_insert_range(__position._M_const_cast(), |
1158 | __first, __last, | |
1159 | std::__iterator_category(__first)); | |
7d594224 FD |
1160 | return begin() + __offset; |
1161 | } | |
7b61c5a9 | 1162 | #else |
7d594224 FD |
1163 | template<typename _InputIterator> |
1164 | void | |
1165 | insert(iterator __position, | |
1166 | _InputIterator __first, _InputIterator __last) | |
1167 | { | |
6f00ccba | 1168 | // Check whether it's an integral type. If so, it's not an iterator. |
7d594224 FD |
1169 | typedef typename std::__is_integer<_InputIterator>::__type _Integral; |
1170 | _M_insert_dispatch(__position, __first, __last, _Integral()); | |
1171 | } | |
7b61c5a9 | 1172 | #endif |
ed6814f7 | 1173 | |
734f5023 | 1174 | #if __cplusplus >= 201103L |
1ae8edf5 | 1175 | _GLIBCXX20_CONSTEXPR |
06eed9f5 | 1176 | iterator |
7d594224 | 1177 | insert(const_iterator __position, size_type __n, const bool& __x) |
06eed9f5 PC |
1178 | { |
1179 | difference_type __offset = __position - cbegin(); | |
7d594224 | 1180 | _M_fill_insert(__position._M_const_cast(), __n, __x); |
06eed9f5 PC |
1181 | return begin() + __offset; |
1182 | } | |
2203cb90 | 1183 | #else |
fd09ac0c | 1184 | void |
7d594224 FD |
1185 | insert(iterator __position, size_type __n, const bool& __x) |
1186 | { _M_fill_insert(__position, __n, __x); } | |
06eed9f5 | 1187 | #endif |
ed6814f7 | 1188 | |
734f5023 | 1189 | #if __cplusplus >= 201103L |
1ae8edf5 | 1190 | _GLIBCXX20_CONSTEXPR |
7d594224 FD |
1191 | iterator |
1192 | insert(const_iterator __p, initializer_list<bool> __l) | |
1193 | { return this->insert(__p, __l.begin(), __l.end()); } | |
988499f4 JM |
1194 | #endif |
1195 | ||
1ae8edf5 | 1196 | _GLIBCXX20_CONSTEXPR |
7d594224 FD |
1197 | void |
1198 | pop_back() | |
1199 | { --this->_M_impl._M_finish; } | |
fd09ac0c | 1200 | |
1ae8edf5 | 1201 | _GLIBCXX20_CONSTEXPR |
7d594224 | 1202 | iterator |
94938aec | 1203 | #if __cplusplus >= 201103L |
7d594224 | 1204 | erase(const_iterator __position) |
94938aec | 1205 | #else |
7d594224 | 1206 | erase(iterator __position) |
94938aec | 1207 | #endif |
7d594224 | 1208 | { return _M_erase(__position._M_const_cast()); } |
ed6814f7 | 1209 | |
1ae8edf5 | 1210 | _GLIBCXX20_CONSTEXPR |
7d594224 | 1211 | iterator |
94938aec | 1212 | #if __cplusplus >= 201103L |
7d594224 | 1213 | erase(const_iterator __first, const_iterator __last) |
94938aec | 1214 | #else |
7d594224 | 1215 | erase(iterator __first, iterator __last) |
94938aec | 1216 | #endif |
7d594224 | 1217 | { return _M_erase(__first._M_const_cast(), __last._M_const_cast()); } |
ed6814f7 | 1218 | |
1ae8edf5 | 1219 | _GLIBCXX20_CONSTEXPR |
7d594224 FD |
1220 | void |
1221 | resize(size_type __new_size, bool __x = bool()) | |
1222 | { | |
1223 | if (__new_size < size()) | |
1224 | _M_erase_at_end(begin() + difference_type(__new_size)); | |
1225 | else | |
1226 | insert(end(), __new_size - size(), __x); | |
1227 | } | |
ed6814f7 | 1228 | |
734f5023 | 1229 | #if __cplusplus >= 201103L |
1ae8edf5 | 1230 | _GLIBCXX20_CONSTEXPR |
7d594224 FD |
1231 | void |
1232 | shrink_to_fit() | |
1233 | { _M_shrink_to_fit(); } | |
79667f82 PC |
1234 | #endif |
1235 | ||
1ae8edf5 | 1236 | _GLIBCXX20_CONSTEXPR |
7d594224 FD |
1237 | void |
1238 | flip() _GLIBCXX_NOEXCEPT | |
1239 | { | |
1240 | _Bit_type * const __end = this->_M_impl._M_end_addr(); | |
1241 | for (_Bit_type * __p = this->_M_impl._M_start._M_p; __p != __end; ++__p) | |
1242 | *__p = ~*__p; | |
1243 | } | |
fd09ac0c | 1244 | |
1ae8edf5 | 1245 | _GLIBCXX20_CONSTEXPR |
7d594224 FD |
1246 | void |
1247 | clear() _GLIBCXX_NOEXCEPT | |
1248 | { _M_erase_at_end(begin()); } | |
fd09ac0c | 1249 | |
3aaaa651 | 1250 | #if __cplusplus >= 201103L |
7d594224 | 1251 | template<typename... _Args> |
594ef205 | 1252 | #if __cplusplus > 201402L |
1ae8edf5 | 1253 | _GLIBCXX20_CONSTEXPR |
7d594224 | 1254 | reference |
594ef205 | 1255 | #else |
7d594224 | 1256 | void |
594ef205 | 1257 | #endif |
7d594224 FD |
1258 | emplace_back(_Args&&... __args) |
1259 | { | |
1260 | push_back(bool(__args...)); | |
594ef205 | 1261 | #if __cplusplus > 201402L |
7d594224 | 1262 | return back(); |
3aaaa651 | 1263 | #endif |
046a8476 | 1264 | } |
fd09ac0c | 1265 | |
7d594224 | 1266 | template<typename... _Args> |
1ae8edf5 | 1267 | _GLIBCXX20_CONSTEXPR |
7d594224 FD |
1268 | iterator |
1269 | emplace(const_iterator __pos, _Args&&... __args) | |
1270 | { return insert(__pos, bool(__args...)); } | |
8a752dfe FD |
1271 | #endif |
1272 | ||
7d594224 FD |
1273 | protected: |
1274 | // Precondition: __first._M_offset == 0 && __result._M_offset == 0. | |
1ae8edf5 | 1275 | _GLIBCXX20_CONSTEXPR |
7d594224 FD |
1276 | iterator |
1277 | _M_copy_aligned(const_iterator __first, const_iterator __last, | |
1278 | iterator __result) | |
fd09ac0c | 1279 | { |
7d594224 FD |
1280 | _Bit_type* __q = std::copy(__first._M_p, __last._M_p, __result._M_p); |
1281 | return std::copy(const_iterator(__last._M_p, 0), __last, | |
1282 | iterator(__q, 0)); | |
fd09ac0c PC |
1283 | } |
1284 | ||
1ae8edf5 | 1285 | _GLIBCXX20_CONSTEXPR |
705debec | 1286 | void |
7d594224 | 1287 | _M_initialize(size_type __n) |
705debec | 1288 | { |
7d594224 FD |
1289 | if (__n) |
1290 | { | |
1291 | _Bit_pointer __q = this->_M_allocate(__n); | |
1292 | this->_M_impl._M_end_of_storage = __q + _S_nword(__n); | |
6f00ccba FD |
1293 | iterator __start = iterator(std::__addressof(*__q), 0); |
1294 | this->_M_impl._M_start = __start; | |
1295 | this->_M_impl._M_finish = __start + difference_type(__n); | |
7d594224 | 1296 | } |
fd09ac0c PC |
1297 | } |
1298 | ||
1ae8edf5 | 1299 | _GLIBCXX20_CONSTEXPR |
fd09ac0c | 1300 | void |
1ae8edf5 | 1301 | _M_initialize_value(bool __x) _GLIBCXX_NOEXCEPT |
fd09ac0c | 1302 | { |
b6d03af0 | 1303 | if (_Bit_type* __p = this->_M_impl._M_start._M_p) |
1ae8edf5 | 1304 | __fill_bvector_n(__p, this->_M_impl._M_end_addr() - __p, __x); |
705debec | 1305 | } |
ed6814f7 | 1306 | |
1ae8edf5 | 1307 | _GLIBCXX20_CONSTEXPR |
705debec | 1308 | void |
7d594224 | 1309 | _M_reallocate(size_type __n); |
ed6814f7 | 1310 | |
7d594224 | 1311 | #if __cplusplus >= 201103L |
1ae8edf5 | 1312 | _GLIBCXX20_CONSTEXPR |
7d594224 FD |
1313 | bool |
1314 | _M_shrink_to_fit(); | |
1315 | #endif | |
ed6814f7 | 1316 | |
6f00ccba | 1317 | #if __cplusplus < 201103L |
7d594224 FD |
1318 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
1319 | // 438. Ambiguity in the "do the right thing" clause | |
1320 | template<typename _Integer> | |
1321 | void | |
1322 | _M_initialize_dispatch(_Integer __n, _Integer __x, __true_type) | |
fd09ac0c | 1323 | { |
7d594224 FD |
1324 | _M_initialize(static_cast<size_type>(__n)); |
1325 | _M_initialize_value(__x); | |
fd09ac0c | 1326 | } |
7d594224 FD |
1327 | |
1328 | template<typename _InputIterator> | |
b6d03af0 | 1329 | void |
7d594224 FD |
1330 | _M_initialize_dispatch(_InputIterator __first, _InputIterator __last, |
1331 | __false_type) | |
b6d03af0 | 1332 | { _M_initialize_range(__first, __last, |
7d594224 | 1333 | std::__iterator_category(__first)); } |
6f00ccba | 1334 | #endif |
7d594224 FD |
1335 | |
1336 | template<typename _InputIterator> | |
1ae8edf5 | 1337 | _GLIBCXX20_CONSTEXPR |
7d594224 FD |
1338 | void |
1339 | _M_initialize_range(_InputIterator __first, _InputIterator __last, | |
1340 | std::input_iterator_tag) | |
fd09ac0c | 1341 | { |
7d594224 FD |
1342 | for (; __first != __last; ++__first) |
1343 | push_back(*__first); | |
fd09ac0c | 1344 | } |
fd09ac0c | 1345 | |
7d594224 | 1346 | template<typename _ForwardIterator> |
1ae8edf5 | 1347 | _GLIBCXX20_CONSTEXPR |
7d594224 FD |
1348 | void |
1349 | _M_initialize_range(_ForwardIterator __first, _ForwardIterator __last, | |
1350 | std::forward_iterator_tag) | |
1351 | { | |
1352 | const size_type __n = std::distance(__first, __last); | |
1353 | _M_initialize(__n); | |
6f00ccba | 1354 | std::copy(__first, __last, begin()); |
7d594224 FD |
1355 | } |
1356 | ||
1357 | #if __cplusplus < 201103L | |
1358 | // _GLIBCXX_RESOLVE_LIB_DEFECTS | |
1359 | // 438. Ambiguity in the "do the right thing" clause | |
1360 | template<typename _Integer> | |
1361 | void | |
1362 | _M_assign_dispatch(_Integer __n, _Integer __val, __true_type) | |
1363 | { _M_fill_assign(__n, __val); } | |
1364 | ||
1365 | template<class _InputIterator> | |
1366 | void | |
1367 | _M_assign_dispatch(_InputIterator __first, _InputIterator __last, | |
1368 | __false_type) | |
1369 | { _M_assign_aux(__first, __last, std::__iterator_category(__first)); } | |
1370 | #endif | |
1371 | ||
1ae8edf5 | 1372 | _GLIBCXX20_CONSTEXPR |
705debec | 1373 | void |
7d594224 | 1374 | _M_fill_assign(size_t __n, bool __x) |
705debec | 1375 | { |
7d594224 FD |
1376 | if (__n > size()) |
1377 | { | |
1378 | _M_initialize_value(__x); | |
1379 | insert(end(), __n - size(), __x); | |
1380 | } | |
705debec PC |
1381 | else |
1382 | { | |
7d594224 FD |
1383 | _M_erase_at_end(begin() + __n); |
1384 | _M_initialize_value(__x); | |
705debec PC |
1385 | } |
1386 | } | |
ed6814f7 | 1387 | |
7d594224 | 1388 | template<typename _InputIterator> |
1ae8edf5 | 1389 | _GLIBCXX20_CONSTEXPR |
7d594224 FD |
1390 | void |
1391 | _M_assign_aux(_InputIterator __first, _InputIterator __last, | |
1392 | std::input_iterator_tag) | |
1393 | { | |
1394 | iterator __cur = begin(); | |
27db01d8 | 1395 | for (; __first != __last && __cur != end(); ++__cur, (void)++__first) |
7d594224 FD |
1396 | *__cur = *__first; |
1397 | if (__first == __last) | |
1398 | _M_erase_at_end(__cur); | |
1399 | else | |
1400 | insert(end(), __first, __last); | |
1401 | } | |
b6d03af0 | 1402 | |
7d594224 | 1403 | template<typename _ForwardIterator> |
1ae8edf5 | 1404 | _GLIBCXX20_CONSTEXPR |
7d594224 FD |
1405 | void |
1406 | _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last, | |
1407 | std::forward_iterator_tag) | |
1408 | { | |
1409 | const size_type __len = std::distance(__first, __last); | |
1410 | if (__len < size()) | |
1411 | _M_erase_at_end(std::copy(__first, __last, begin())); | |
1412 | else | |
1413 | { | |
1414 | _ForwardIterator __mid = __first; | |
1415 | std::advance(__mid, size()); | |
1416 | std::copy(__first, __mid, begin()); | |
1417 | insert(end(), __mid, __last); | |
1418 | } | |
1419 | } | |
25959e29 | 1420 | |
6f00ccba | 1421 | #if __cplusplus < 201103L |
7d594224 FD |
1422 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
1423 | // 438. Ambiguity in the "do the right thing" clause | |
1424 | template<typename _Integer> | |
1425 | void | |
1426 | _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __x, | |
1427 | __true_type) | |
1428 | { _M_fill_insert(__pos, __n, __x); } | |
ed6814f7 | 1429 | |
7d594224 FD |
1430 | template<typename _InputIterator> |
1431 | void | |
1432 | _M_insert_dispatch(iterator __pos, | |
1433 | _InputIterator __first, _InputIterator __last, | |
1434 | __false_type) | |
1435 | { _M_insert_range(__pos, __first, __last, | |
1436 | std::__iterator_category(__first)); } | |
6f00ccba | 1437 | #endif |
ed6814f7 | 1438 | |
1ae8edf5 | 1439 | _GLIBCXX20_CONSTEXPR |
fd09ac0c | 1440 | void |
7d594224 | 1441 | _M_fill_insert(iterator __position, size_type __n, bool __x); |
62e67651 | 1442 | |
7d594224 | 1443 | template<typename _InputIterator> |
1ae8edf5 | 1444 | _GLIBCXX20_CONSTEXPR |
7d594224 | 1445 | void |
b6d03af0 | 1446 | _M_insert_range(iterator __pos, _InputIterator __first, |
7d594224 FD |
1447 | _InputIterator __last, std::input_iterator_tag) |
1448 | { | |
1449 | for (; __first != __last; ++__first) | |
1450 | { | |
1451 | __pos = insert(__pos, *__first); | |
1452 | ++__pos; | |
1453 | } | |
1454 | } | |
62e67651 | 1455 | |
7d594224 | 1456 | template<typename _ForwardIterator> |
1ae8edf5 | 1457 | _GLIBCXX20_CONSTEXPR |
7d594224 | 1458 | void |
b6d03af0 | 1459 | _M_insert_range(iterator __position, _ForwardIterator __first, |
7d594224 | 1460 | _ForwardIterator __last, std::forward_iterator_tag); |
ed6814f7 | 1461 | |
1ae8edf5 | 1462 | _GLIBCXX20_CONSTEXPR |
7d594224 FD |
1463 | void |
1464 | _M_insert_aux(iterator __position, bool __x); | |
be1088fa | 1465 | |
1ae8edf5 | 1466 | _GLIBCXX20_CONSTEXPR |
7d594224 FD |
1467 | size_type |
1468 | _M_check_len(size_type __n, const char* __s) const | |
1469 | { | |
1470 | if (max_size() - size() < __n) | |
1471 | __throw_length_error(__N(__s)); | |
be1088fa | 1472 | |
7d594224 FD |
1473 | const size_type __len = size() + std::max(size(), __n); |
1474 | return (__len < size() || __len > max_size()) ? max_size() : __len; | |
1475 | } | |
94938aec | 1476 | |
1ae8edf5 | 1477 | _GLIBCXX20_CONSTEXPR |
7d594224 FD |
1478 | void |
1479 | _M_erase_at_end(iterator __pos) | |
1480 | { this->_M_impl._M_finish = __pos; } | |
94938aec | 1481 | |
1ae8edf5 | 1482 | _GLIBCXX20_CONSTEXPR |
7d594224 FD |
1483 | iterator |
1484 | _M_erase(iterator __pos); | |
1485 | ||
1ae8edf5 | 1486 | _GLIBCXX20_CONSTEXPR |
7d594224 FD |
1487 | iterator |
1488 | _M_erase(iterator __first, iterator __last); | |
ef0e100f JW |
1489 | |
1490 | protected: | |
1491 | // _GLIBCXX_RESOLVE_LIB_DEFECTS | |
1492 | // DR 464. Suggestion for new member functions in standard containers. | |
1493 | // N.B. DR 464 says nothing about vector<bool> but we need something | |
1494 | // here due to the using-declaration in __gnu_debug::vector. | |
1495 | // vector class. | |
1496 | #if __cplusplus >= 201103L | |
1497 | void data() = delete; | |
1498 | #else | |
1499 | void data() { } | |
1500 | #endif | |
1501 | }; | |
3cbc7af0 | 1502 | |
12ffa228 | 1503 | _GLIBCXX_END_NAMESPACE_CONTAINER |
725dc051 | 1504 | |
1ae8edf5 JW |
1505 | // Fill a partial word. |
1506 | _GLIBCXX20_CONSTEXPR | |
72a54e5e | 1507 | inline void |
1ae8edf5 JW |
1508 | __fill_bvector(_Bit_type* __v, unsigned int __first, unsigned int __last, |
1509 | bool __x) _GLIBCXX_NOEXCEPT | |
72a54e5e | 1510 | { |
72a54e5e FD |
1511 | const _Bit_type __fmask = ~0ul << __first; |
1512 | const _Bit_type __lmask = ~0ul >> (_S_word_bit - __last); | |
1513 | const _Bit_type __mask = __fmask & __lmask; | |
4cd533a7 | 1514 | |
72a54e5e FD |
1515 | if (__x) |
1516 | *__v |= __mask; | |
1517 | else | |
1518 | *__v &= ~__mask; | |
1519 | } | |
4cd533a7 | 1520 | |
1ae8edf5 JW |
1521 | // Fill N full words, as if using memset, but usable in constant expressions. |
1522 | __attribute__((__nonnull__)) | |
1523 | _GLIBCXX20_CONSTEXPR | |
1524 | inline void | |
1525 | __fill_bvector_n(_Bit_type* __p, size_t __n, bool __x) _GLIBCXX_NOEXCEPT | |
1526 | { | |
74d14778 JW |
1527 | #if __cpp_lib_is_constant_evaluated |
1528 | if (std::is_constant_evaluated()) | |
1ae8edf5 JW |
1529 | { |
1530 | for (size_t __i = 0; __i < __n; ++__i) | |
1531 | __p[__i] = __x ? ~0ul : 0ul; | |
1532 | return; | |
1533 | } | |
1534 | #endif | |
1535 | __builtin_memset(__p, __x ? ~0 : 0, __n * sizeof(_Bit_type)); | |
1536 | } | |
1537 | ||
1538 | ||
1539 | _GLIBCXX20_CONSTEXPR | |
72a54e5e FD |
1540 | inline void |
1541 | __fill_a1(_GLIBCXX_STD_C::_Bit_iterator __first, | |
1542 | _GLIBCXX_STD_C::_Bit_iterator __last, const bool& __x) | |
1543 | { | |
72a54e5e FD |
1544 | if (__first._M_p != __last._M_p) |
1545 | { | |
1546 | _Bit_type* __first_p = __first._M_p; | |
1547 | if (__first._M_offset != 0) | |
1548 | __fill_bvector(__first_p++, __first._M_offset, _S_word_bit, __x); | |
1549 | ||
1ae8edf5 | 1550 | __fill_bvector_n(__first_p, __last._M_p - __first_p, __x); |
72a54e5e FD |
1551 | |
1552 | if (__last._M_offset != 0) | |
1553 | __fill_bvector(__last._M_p, 0, __last._M_offset, __x); | |
1554 | } | |
1555 | else if (__first._M_offset != __last._M_offset) | |
1556 | __fill_bvector(__first._M_p, __first._M_offset, __last._M_offset, __x); | |
1557 | } | |
1558 | ||
1559 | #if __cplusplus >= 201103L | |
4cd533a7 PC |
1560 | // DR 1182. |
1561 | /// std::hash specialization for vector<bool>. | |
1562 | template<typename _Alloc> | |
12ffa228 BK |
1563 | struct hash<_GLIBCXX_STD_C::vector<bool, _Alloc>> |
1564 | : public __hash_base<size_t, _GLIBCXX_STD_C::vector<bool, _Alloc>> | |
4cd533a7 PC |
1565 | { |
1566 | size_t | |
72f1c34b | 1567 | operator()(const _GLIBCXX_STD_C::vector<bool, _Alloc>&) const noexcept; |
4cd533a7 | 1568 | }; |
72a54e5e | 1569 | #endif // C++11 |
4cd533a7 | 1570 | |
12ffa228 | 1571 | _GLIBCXX_END_NAMESPACE_VERSION |
72a54e5e | 1572 | } // namespace std |
4cd533a7 | 1573 | |
62e67651 | 1574 | #endif |