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