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 const_iterator __xbegin = __x.begin(), __xend = __x.end();
777 _M_initialize(__x.size());
778 _M_copy_aligned(__xbegin, __xend, begin());
779 }
780
781#if __cplusplus >= 201103L
782 vector(vector&&) = default;
783
784 private:
785 _GLIBCXX20_CONSTEXPR
786 vector(vector&& __x, const allocator_type& __a, true_type) noexcept
787 : _Base(std::move(__x), __a)
788 { }
789
790 _GLIBCXX20_CONSTEXPR
791 vector(vector&& __x, const allocator_type& __a, false_type)
792 : _Base(__a)
793 {
794 if (__x.get_allocator() == __a)
795 this->_M_move_data(std::move(__x));
796 else
797 {
798 _M_initialize(__x.size());
799 _M_copy_aligned(__x.begin(), __x.end(), begin());
800 __x.clear();
801 }
802 }
803
804 public:
805 _GLIBCXX20_CONSTEXPR
806 vector(vector&& __x, const __type_identity_t<allocator_type>& __a)
807 noexcept(_Bit_alloc_traits::_S_always_equal())
808 : vector(std::move(__x), __a,
810 { }
811
812 _GLIBCXX20_CONSTEXPR
813 vector(const vector& __x, const __type_identity_t<allocator_type>& __a)
814 : _Base(__a)
815 {
816 _M_initialize(__x.size());
817 _M_copy_aligned(__x.begin(), __x.end(), begin());
818 }
819
820 _GLIBCXX20_CONSTEXPR
822 const allocator_type& __a = allocator_type())
823 : _Base(__a)
824 {
825 _M_initialize_range(__l.begin(), __l.end(),
827 }
828#endif
829
830#if __cplusplus >= 201103L
831 template<typename _InputIterator,
832 typename = std::_RequireInputIter<_InputIterator>>
833 _GLIBCXX20_CONSTEXPR
834 vector(_InputIterator __first, _InputIterator __last,
835 const allocator_type& __a = allocator_type())
836 : _Base(__a)
837 {
838 _M_initialize_range(__first, __last,
839 std::__iterator_category(__first));
840 }
841#else
842 template<typename _InputIterator>
843 vector(_InputIterator __first, _InputIterator __last,
844 const allocator_type& __a = allocator_type())
845 : _Base(__a)
846 {
847 // Check whether it's an integral type. If so, it's not an iterator.
848 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
849 _M_initialize_dispatch(__first, __last, _Integral());
850 }
851#endif
852
853 _GLIBCXX20_CONSTEXPR
854 ~vector() _GLIBCXX_NOEXCEPT { }
855
856 _GLIBCXX20_CONSTEXPR
857 vector&
858 operator=(const vector& __x)
859 {
860 if (&__x == this)
861 return *this;
862#if __cplusplus >= 201103L
863 if (_Bit_alloc_traits::_S_propagate_on_copy_assign())
864 {
865 if (this->_M_get_Bit_allocator() != __x._M_get_Bit_allocator())
866 {
867 this->_M_deallocate();
868 std::__alloc_on_copy(_M_get_Bit_allocator(),
869 __x._M_get_Bit_allocator());
870 _M_initialize(__x.size());
871 }
872 else
873 std::__alloc_on_copy(_M_get_Bit_allocator(),
874 __x._M_get_Bit_allocator());
875 }
876#endif
877 if (__x.size() > capacity())
878 {
879 this->_M_deallocate();
880 _M_initialize(__x.size());
881 }
882 this->_M_impl._M_finish = _M_copy_aligned(__x.begin(), __x.end(),
883 begin());
884 return *this;
885 }
886
887#if __cplusplus >= 201103L
888 _GLIBCXX20_CONSTEXPR
889 vector&
890 operator=(vector&& __x) noexcept(_Bit_alloc_traits::_S_nothrow_move())
891 {
892 if (_Bit_alloc_traits::_S_propagate_on_move_assign()
893 || this->_M_get_Bit_allocator() == __x._M_get_Bit_allocator())
894 {
895 this->_M_deallocate();
896 this->_M_move_data(std::move(__x));
897 std::__alloc_on_move(_M_get_Bit_allocator(),
898 __x._M_get_Bit_allocator());
899 }
900 else
901 {
902 if (__x.size() > capacity())
903 {
904 this->_M_deallocate();
905 _M_initialize(__x.size());
906 }
907 this->_M_impl._M_finish = _M_copy_aligned(__x.begin(), __x.end(),
908 begin());
909 __x.clear();
910 }
911 return *this;
912 }
913
914 _GLIBCXX20_CONSTEXPR
915 vector&
917 {
918 this->assign(__l.begin(), __l.end());
919 return *this;
920 }
921#endif
922
923 // assign(), a generalized assignment member function. Two
924 // versions: one that takes a count, and one that takes a range.
925 // The range version is a member template, so we dispatch on whether
926 // or not the type is an integer.
927 _GLIBCXX20_CONSTEXPR
928 void
929 assign(size_type __n, const bool& __x)
930 { _M_fill_assign(__n, __x); }
931
932#if __cplusplus >= 201103L
933 template<typename _InputIterator,
934 typename = std::_RequireInputIter<_InputIterator>>
935 _GLIBCXX20_CONSTEXPR
936 void
937 assign(_InputIterator __first, _InputIterator __last)
938 { _M_assign_aux(__first, __last, std::__iterator_category(__first)); }
939#else
940 template<typename _InputIterator>
941 void
942 assign(_InputIterator __first, _InputIterator __last)
943 {
944 // Check whether it's an integral type. If so, it's not an iterator.
945 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
946 _M_assign_dispatch(__first, __last, _Integral());
947 }
948#endif
949
950#if __cplusplus >= 201103L
951 _GLIBCXX20_CONSTEXPR
952 void
954 { _M_assign_aux(__l.begin(), __l.end(), random_access_iterator_tag()); }
955#endif
956
957 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
958 iterator
959 begin() _GLIBCXX_NOEXCEPT
960 { return iterator(this->_M_impl._M_start._M_p, 0); }
961
962 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
963 const_iterator
964 begin() const _GLIBCXX_NOEXCEPT
965 { return const_iterator(this->_M_impl._M_start._M_p, 0); }
966
967 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
968 iterator
969 end() _GLIBCXX_NOEXCEPT
970 { return this->_M_impl._M_finish; }
971
972 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
973 const_iterator
974 end() const _GLIBCXX_NOEXCEPT
975 { return this->_M_impl._M_finish; }
976
977 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
979 rbegin() _GLIBCXX_NOEXCEPT
980 { return reverse_iterator(end()); }
981
982 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
984 rbegin() const _GLIBCXX_NOEXCEPT
985 { return const_reverse_iterator(end()); }
986
987 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
989 rend() _GLIBCXX_NOEXCEPT
990 { return reverse_iterator(begin()); }
991
992 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
994 rend() const _GLIBCXX_NOEXCEPT
995 { return const_reverse_iterator(begin()); }
996
997#if __cplusplus >= 201103L
998 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
999 const_iterator
1000 cbegin() const noexcept
1001 { return const_iterator(this->_M_impl._M_start._M_p, 0); }
1002
1003 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
1004 const_iterator
1005 cend() const noexcept
1006 { return this->_M_impl._M_finish; }
1007
1008 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
1010 crbegin() const noexcept
1011 { return const_reverse_iterator(end()); }
1012
1013 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
1015 crend() const noexcept
1016 { return const_reverse_iterator(begin()); }
1017#endif
1018
1019 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1020 size_type
1021 size() const _GLIBCXX_NOEXCEPT
1022 { return size_type(end() - begin()); }
1023
1024 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1025 size_type
1026 max_size() const _GLIBCXX_NOEXCEPT
1027 {
1028 const size_type __isize =
1029 __gnu_cxx::__numeric_traits<difference_type>::__max
1030 - int(_S_word_bit) + 1;
1031 const size_type __asize
1032 = _Bit_alloc_traits::max_size(_M_get_Bit_allocator());
1033 return (__asize <= __isize / int(_S_word_bit)
1034 ? __asize * int(_S_word_bit) : __isize);
1035 }
1036
1037 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1038 size_type
1039 capacity() const _GLIBCXX_NOEXCEPT
1040 { return size_type(const_iterator(this->_M_impl._M_end_addr(), 0)
1041 - begin()); }
1042
1043 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1044 bool
1045 empty() const _GLIBCXX_NOEXCEPT
1046 { return begin() == end(); }
1047
1048 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1049 reference
1050 operator[](size_type __n)
1051 { return begin()[__n]; }
1052
1053 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1054 const_reference
1055 operator[](size_type __n) const
1056 { return begin()[__n]; }
1057
1058 protected:
1059 _GLIBCXX20_CONSTEXPR
1060 void
1061 _M_range_check(size_type __n) const
1062 {
1063 if (__n >= this->size())
1064 __throw_out_of_range_fmt(__N("vector<bool>::_M_range_check: __n "
1065 "(which is %zu) >= this->size() "
1066 "(which is %zu)"),
1067 __n, this->size());
1068 }
1069
1070 public:
1071 _GLIBCXX20_CONSTEXPR
1072 reference
1073 at(size_type __n)
1074 {
1075 _M_range_check(__n);
1076 return (*this)[__n];
1077 }
1078
1079 _GLIBCXX20_CONSTEXPR
1080 const_reference
1081 at(size_type __n) const
1082 {
1083 _M_range_check(__n);
1084 return (*this)[__n];
1085 }
1086
1087 _GLIBCXX20_CONSTEXPR
1088 void
1089 reserve(size_type __n)
1090 {
1091 if (__n > max_size())
1092 __throw_length_error(__N("vector::reserve"));
1093 if (capacity() < __n)
1094 _M_reallocate(__n);
1095 }
1096
1097 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1098 reference
1099 front()
1100 { return *begin(); }
1101
1102 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1103 const_reference
1104 front() const
1105 { return *begin(); }
1106
1107 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1108 reference
1109 back()
1110 { return *(end() - 1); }
1111
1112 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1113 const_reference
1114 back() const
1115 { return *(end() - 1); }
1116
1117 _GLIBCXX20_CONSTEXPR
1118 void
1119 push_back(bool __x)
1120 {
1121 if (this->_M_impl._M_finish._M_p != this->_M_impl._M_end_addr())
1122 *this->_M_impl._M_finish++ = __x;
1123 else
1124 _M_insert_aux(end(), __x);
1125 }
1126
1127 _GLIBCXX20_CONSTEXPR
1128 void
1129 swap(vector& __x) _GLIBCXX_NOEXCEPT
1130 {
1131#if __cplusplus >= 201103L
1132 __glibcxx_assert(_Bit_alloc_traits::propagate_on_container_swap::value
1133 || _M_get_Bit_allocator() == __x._M_get_Bit_allocator());
1134#endif
1135 this->_M_impl._M_swap_data(__x._M_impl);
1136 _Bit_alloc_traits::_S_on_swap(_M_get_Bit_allocator(),
1137 __x._M_get_Bit_allocator());
1138 }
1139
1140 // [23.2.5]/1, third-to-last entry in synopsis listing
1141 _GLIBCXX20_CONSTEXPR
1142 static void
1143 swap(reference __x, reference __y) _GLIBCXX_NOEXCEPT
1144 {
1145 bool __tmp = __x;
1146 __x = __y;
1147 __y = __tmp;
1148 }
1149
1150 _GLIBCXX20_CONSTEXPR
1151 iterator
1152#if __cplusplus >= 201103L
1153 insert(const_iterator __position, const bool& __x)
1154#else
1155 insert(iterator __position, const bool& __x)
1156#endif
1157 {
1158 const difference_type __n = __position - begin();
1159 if (this->_M_impl._M_finish._M_p != this->_M_impl._M_end_addr()
1160 && __position == end())
1161 *this->_M_impl._M_finish++ = __x;
1162 else
1163 _M_insert_aux(__position._M_const_cast(), __x);
1164 return begin() + __n;
1165 }
1166
1167#if _GLIBCXX_USE_DEPRECATED
1168 _GLIBCXX_DEPRECATED_SUGGEST("insert(position, false)")
1169 iterator
1170 insert(const_iterator __position)
1171 { return this->insert(__position._M_const_cast(), false); }
1172#endif
1173
1174#if __cplusplus >= 201103L
1175 template<typename _InputIterator,
1176 typename = std::_RequireInputIter<_InputIterator>>
1177 _GLIBCXX20_CONSTEXPR
1178 iterator
1179 insert(const_iterator __position,
1180 _InputIterator __first, _InputIterator __last)
1181 {
1182 difference_type __offset = __position - cbegin();
1183 _M_insert_range(__position._M_const_cast(),
1184 __first, __last,
1185 std::__iterator_category(__first));
1186 return begin() + __offset;
1187 }
1188#else
1189 template<typename _InputIterator>
1190 void
1191 insert(iterator __position,
1192 _InputIterator __first, _InputIterator __last)
1193 {
1194 // Check whether it's an integral type. If so, it's not an iterator.
1195 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1196 _M_insert_dispatch(__position, __first, __last, _Integral());
1197 }
1198#endif
1199
1200#if __cplusplus >= 201103L
1201 _GLIBCXX20_CONSTEXPR
1202 iterator
1203 insert(const_iterator __position, size_type __n, const bool& __x)
1204 {
1205 difference_type __offset = __position - cbegin();
1206 _M_fill_insert(__position._M_const_cast(), __n, __x);
1207 return begin() + __offset;
1208 }
1209#else
1210 void
1211 insert(iterator __position, size_type __n, const bool& __x)
1212 { _M_fill_insert(__position, __n, __x); }
1213#endif
1214
1215#if __cplusplus >= 201103L
1216 _GLIBCXX20_CONSTEXPR
1217 iterator
1218 insert(const_iterator __p, initializer_list<bool> __l)
1219 { return this->insert(__p, __l.begin(), __l.end()); }
1220#endif
1221
1222 _GLIBCXX20_CONSTEXPR
1223 void
1224 pop_back()
1225 { --this->_M_impl._M_finish; }
1226
1227 _GLIBCXX20_CONSTEXPR
1228 iterator
1229#if __cplusplus >= 201103L
1230 erase(const_iterator __position)
1231#else
1232 erase(iterator __position)
1233#endif
1234 { return _M_erase(__position._M_const_cast()); }
1235
1236 _GLIBCXX20_CONSTEXPR
1237 iterator
1238#if __cplusplus >= 201103L
1239 erase(const_iterator __first, const_iterator __last)
1240#else
1241 erase(iterator __first, iterator __last)
1242#endif
1243 { return _M_erase(__first._M_const_cast(), __last._M_const_cast()); }
1244
1245 _GLIBCXX20_CONSTEXPR
1246 void
1247 resize(size_type __new_size, bool __x = bool())
1248 {
1249 if (__new_size < size())
1250 _M_erase_at_end(begin() + difference_type(__new_size));
1251 else
1252 insert(end(), __new_size - size(), __x);
1253 }
1254
1255#if __cplusplus >= 201103L
1256 _GLIBCXX20_CONSTEXPR
1257 void
1259 { _M_shrink_to_fit(); }
1260#endif
1261
1262 _GLIBCXX20_CONSTEXPR
1263 void
1264 flip() _GLIBCXX_NOEXCEPT
1265 {
1266 _Bit_type * const __end = this->_M_impl._M_end_addr();
1267 for (_Bit_type * __p = this->_M_impl._M_start._M_p; __p != __end; ++__p)
1268 *__p = ~*__p;
1269 }
1270
1271 _GLIBCXX20_CONSTEXPR
1272 void
1273 clear() _GLIBCXX_NOEXCEPT
1274 { _M_erase_at_end(begin()); }
1275
1276#if __cplusplus >= 201103L
1277 template<typename... _Args>
1278#if __cplusplus > 201402L
1279 _GLIBCXX20_CONSTEXPR
1280 reference
1281#else
1282 void
1283#endif
1284 emplace_back(_Args&&... __args)
1285 {
1286 push_back(bool(__args...));
1287#if __cplusplus > 201402L
1288 return back();
1289#endif
1290 }
1291
1292 template<typename... _Args>
1293 _GLIBCXX20_CONSTEXPR
1294 iterator
1295 emplace(const_iterator __pos, _Args&&... __args)
1296 { return insert(__pos, bool(__args...)); }
1297#endif
1298
1299 protected:
1300 // Precondition: __first._M_offset == 0 && __result._M_offset == 0.
1301 _GLIBCXX20_CONSTEXPR
1302 iterator
1303 _M_copy_aligned(const_iterator __first, const_iterator __last,
1304 iterator __result)
1305 {
1306 _Bit_type* __q = std::copy(__first._M_p, __last._M_p, __result._M_p);
1307 return std::copy(const_iterator(__last._M_p, 0), __last,
1308 iterator(__q, 0));
1309 }
1310
1311 _GLIBCXX20_CONSTEXPR
1312 void
1313 _M_initialize(size_type __n)
1314 {
1315 if (__n)
1316 {
1317 _Bit_pointer __q = this->_M_allocate(__n);
1318 this->_M_impl._M_end_of_storage = __q + _S_nword(__n);
1319 iterator __start = iterator(std::__addressof(*__q), 0);
1320 this->_M_impl._M_start = __start;
1321 this->_M_impl._M_finish = __start + difference_type(__n);
1322 }
1323 }
1324
1325 _GLIBCXX20_CONSTEXPR
1326 void
1327 _M_initialize_value(bool __x) _GLIBCXX_NOEXCEPT
1328 {
1329 if (_Bit_type* __p = this->_M_impl._M_start._M_p)
1330 __fill_bvector_n(__p, this->_M_impl._M_end_addr() - __p, __x);
1331 }
1332
1333 _GLIBCXX20_CONSTEXPR
1334 void
1335 _M_reallocate(size_type __n);
1336
1337#if __cplusplus >= 201103L
1338 _GLIBCXX20_CONSTEXPR
1339 bool
1340 _M_shrink_to_fit();
1341#endif
1342
1343#if __cplusplus < 201103L
1344 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1345 // 438. Ambiguity in the "do the right thing" clause
1346 template<typename _Integer>
1347 void
1348 _M_initialize_dispatch(_Integer __n, _Integer __x, __true_type)
1349 {
1350 _M_initialize(static_cast<size_type>(__n));
1351 _M_initialize_value(__x);
1352 }
1353
1354 template<typename _InputIterator>
1355 void
1356 _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
1357 __false_type)
1358 { _M_initialize_range(__first, __last,
1359 std::__iterator_category(__first)); }
1360#endif
1361
1362 template<typename _InputIterator>
1363 _GLIBCXX20_CONSTEXPR
1364 void
1365 _M_initialize_range(_InputIterator __first, _InputIterator __last,
1367 {
1368 for (; __first != __last; ++__first)
1369 push_back(*__first);
1370 }
1371
1372 template<typename _ForwardIterator>
1373 _GLIBCXX20_CONSTEXPR
1374 void
1375 _M_initialize_range(_ForwardIterator __first, _ForwardIterator __last,
1377 {
1378 const size_type __n = std::distance(__first, __last);
1379 _M_initialize(__n);
1380 std::copy(__first, __last, begin());
1381 }
1382
1383#if __cplusplus < 201103L
1384 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1385 // 438. Ambiguity in the "do the right thing" clause
1386 template<typename _Integer>
1387 void
1388 _M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
1389 { _M_fill_assign(__n, __val); }
1390
1391 template<class _InputIterator>
1392 void
1393 _M_assign_dispatch(_InputIterator __first, _InputIterator __last,
1394 __false_type)
1395 { _M_assign_aux(__first, __last, std::__iterator_category(__first)); }
1396#endif
1397
1398 _GLIBCXX20_CONSTEXPR
1399 void
1400 _M_fill_assign(size_t __n, bool __x)
1401 {
1402 if (__n > size())
1403 {
1404 _M_initialize_value(__x);
1405 insert(end(), __n - size(), __x);
1406 }
1407 else
1408 {
1409 _M_erase_at_end(begin() + __n);
1410 _M_initialize_value(__x);
1411 }
1412 }
1413
1414 template<typename _InputIterator>
1415 _GLIBCXX20_CONSTEXPR
1416 void
1417 _M_assign_aux(_InputIterator __first, _InputIterator __last,
1419 {
1420 iterator __cur = begin();
1421 for (; __first != __last && __cur != end(); ++__cur, (void)++__first)
1422 *__cur = *__first;
1423 if (__first == __last)
1424 _M_erase_at_end(__cur);
1425 else
1426 insert(end(), __first, __last);
1427 }
1428
1429 template<typename _ForwardIterator>
1430 _GLIBCXX20_CONSTEXPR
1431 void
1432 _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
1434 {
1435 const size_type __len = std::distance(__first, __last);
1436 if (__len < size())
1437 _M_erase_at_end(std::copy(__first, __last, begin()));
1438 else
1439 {
1440 _ForwardIterator __mid = __first;
1441 std::advance(__mid, size());
1442 std::copy(__first, __mid, begin());
1443 insert(end(), __mid, __last);
1444 }
1445 }
1446
1447#if __cplusplus < 201103L
1448 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1449 // 438. Ambiguity in the "do the right thing" clause
1450 template<typename _Integer>
1451 void
1452 _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __x,
1453 __true_type)
1454 { _M_fill_insert(__pos, __n, __x); }
1455
1456 template<typename _InputIterator>
1457 void
1458 _M_insert_dispatch(iterator __pos,
1459 _InputIterator __first, _InputIterator __last,
1460 __false_type)
1461 { _M_insert_range(__pos, __first, __last,
1462 std::__iterator_category(__first)); }
1463#endif
1464
1465 _GLIBCXX20_CONSTEXPR
1466 void
1467 _M_fill_insert(iterator __position, size_type __n, bool __x);
1468
1469 template<typename _InputIterator>
1470 _GLIBCXX20_CONSTEXPR
1471 void
1472 _M_insert_range(iterator __pos, _InputIterator __first,
1473 _InputIterator __last, std::input_iterator_tag)
1474 {
1475 for (; __first != __last; ++__first)
1476 {
1477 __pos = insert(__pos, *__first);
1478 ++__pos;
1479 }
1480 }
1481
1482 template<typename _ForwardIterator>
1483 _GLIBCXX20_CONSTEXPR
1484 void
1485 _M_insert_range(iterator __position, _ForwardIterator __first,
1486 _ForwardIterator __last, std::forward_iterator_tag);
1487
1488 _GLIBCXX20_CONSTEXPR
1489 void
1490 _M_insert_aux(iterator __position, bool __x);
1491
1492 _GLIBCXX20_CONSTEXPR
1493 size_type
1494 _M_check_len(size_type __n, const char* __s) const
1495 {
1496 if (max_size() - size() < __n)
1497 __throw_length_error(__N(__s));
1498
1499 const size_type __len = size() + std::max(size(), __n);
1500 return (__len < size() || __len > max_size()) ? max_size() : __len;
1501 }
1502
1503 _GLIBCXX20_CONSTEXPR
1504 void
1505 _M_erase_at_end(iterator __pos)
1506 { this->_M_impl._M_finish = __pos; }
1507
1508 _GLIBCXX20_CONSTEXPR
1509 iterator
1510 _M_erase(iterator __pos);
1511
1512 _GLIBCXX20_CONSTEXPR
1513 iterator
1514 _M_erase(iterator __first, iterator __last);
1515
1516 protected:
1517 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1518 // DR 464. Suggestion for new member functions in standard containers.
1519 // N.B. DR 464 says nothing about vector<bool> but we need something
1520 // here due to the using-declaration in __gnu_debug::vector.
1521 // vector class.
1522#if __cplusplus >= 201103L
1523 void data() = delete;
1524#else
1525 void data() { }
1526#endif
1527 };
1528
1529_GLIBCXX_END_NAMESPACE_CONTAINER
1530
1531 // Fill a partial word.
1532 _GLIBCXX20_CONSTEXPR
1533 inline void
1534 __fill_bvector(_Bit_type* __v, unsigned int __first, unsigned int __last,
1535 bool __x) _GLIBCXX_NOEXCEPT
1536 {
1537 const _Bit_type __fmask = ~0ul << __first;
1538 const _Bit_type __lmask = ~0ul >> (_S_word_bit - __last);
1539 const _Bit_type __mask = __fmask & __lmask;
1540
1541 if (__x)
1542 *__v |= __mask;
1543 else
1544 *__v &= ~__mask;
1545 }
1546
1547 // Fill N full words, as if using memset, but usable in constant expressions.
1548 __attribute__((__nonnull__))
1549 _GLIBCXX20_CONSTEXPR
1550 inline void
1551 __fill_bvector_n(_Bit_type* __p, size_t __n, bool __x) _GLIBCXX_NOEXCEPT
1552 {
1553#if __cpp_lib_is_constant_evaluated
1555 {
1556 for (size_t __i = 0; __i < __n; ++__i)
1557 __p[__i] = __x ? ~0ul : 0ul;
1558 return;
1559 }
1560#endif
1561 __builtin_memset(__p, __x ? ~0 : 0, __n * sizeof(_Bit_type));
1562 }
1563
1564
1565 _GLIBCXX20_CONSTEXPR
1566 inline void
1567 __fill_a1(_GLIBCXX_STD_C::_Bit_iterator __first,
1568 _GLIBCXX_STD_C::_Bit_iterator __last, const bool& __x)
1569 {
1570 if (__first._M_p != __last._M_p)
1571 {
1572 _Bit_type* __first_p = __first._M_p;
1573 if (__first._M_offset != 0)
1574 __fill_bvector(__first_p++, __first._M_offset, _S_word_bit, __x);
1575
1576 __fill_bvector_n(__first_p, __last._M_p - __first_p, __x);
1577
1578 if (__last._M_offset != 0)
1579 __fill_bvector(__last._M_p, 0, __last._M_offset, __x);
1580 }
1581 else if (__first._M_offset != __last._M_offset)
1582 __fill_bvector(__first._M_p, __first._M_offset, __last._M_offset, __x);
1583 }
1584
1585#if __cplusplus >= 201103L
1586 // DR 1182.
1587 /// std::hash specialization for vector<bool>.
1588 template<typename _Alloc>
1589 struct hash<_GLIBCXX_STD_C::vector<bool, _Alloc>>
1590 : public __hash_base<size_t, _GLIBCXX_STD_C::vector<bool, _Alloc>>
1591 {
1592 size_t
1593 operator()(const _GLIBCXX_STD_C::vector<bool, _Alloc>&) const noexcept;
1594 };
1595#endif // C++11
1596
1597_GLIBCXX_END_NAMESPACE_VERSION
1598} // namespace std
1599
1600#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.
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.
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.
constexpr iterator begin() noexcept
Definition stl_vector.h:870
constexpr size_type capacity() const noexcept
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 _Tp * data() noexcept
constexpr void pop_back() noexcept
Removes last element.
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.
constexpr void resize(size_type __new_size)
Resizes the vector to the specified number of elements.
constexpr void _M_range_check(size_type __n) const
Safety check used only from at().
constexpr reference front() noexcept
constexpr iterator erase(const_iterator __position)
Remove element at given position.
constexpr bool empty() const noexcept
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
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
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.
constexpr void shrink_to_fit()
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.