mirrored from git://gcc.gnu.org/git/gcc.git
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
/
Copy pathstl_bvector.h
1636 lines (1433 loc) · 41.6 KB
/
stl_bvector.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// vector<bool> specialization -*- C++ -*-
// Copyright (C) 2001-2024 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.
// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
// <http://www.gnu.org/licenses/>.
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Hewlett-Packard Company makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*
* Copyright (c) 1996-1999
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*/
/** @file bits/stl_bvector.h
* This is an internal header file, included by other library headers.
* Do not attempt to use it directly. @headername{vector}
*/
#ifndef _STL_BVECTOR_H
#define _STL_BVECTOR_H 1
#ifndef _GLIBCXX_ALWAYS_INLINE
#define _GLIBCXX_ALWAYS_INLINE inline __attribute__((__always_inline__))
#endif
#if __cplusplus >= 201103L
#include <initializer_list>
#include <bits/functional_hash.h>
#endif
namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
typedef unsigned long _Bit_type;
enum { _S_word_bit = int(__CHAR_BIT__ * sizeof(_Bit_type)) };
__attribute__((__nonnull__))
_GLIBCXX20_CONSTEXPR
void
__fill_bvector_n(_Bit_type*, size_t, bool) _GLIBCXX_NOEXCEPT;
_GLIBCXX_BEGIN_NAMESPACE_CONTAINER
struct _Bit_reference
{
_Bit_type * _M_p;
_Bit_type _M_mask;
_GLIBCXX20_CONSTEXPR
_Bit_reference(_Bit_type * __x, _Bit_type __y)
: _M_p(__x), _M_mask(__y) { }
_GLIBCXX20_CONSTEXPR
_Bit_reference() _GLIBCXX_NOEXCEPT : _M_p(0), _M_mask(0) { }
#if __cplusplus >= 201103L
_Bit_reference(const _Bit_reference&) = default;
#endif
_GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
operator bool() const _GLIBCXX_NOEXCEPT
{ return !!(*_M_p & _M_mask); }
_GLIBCXX20_CONSTEXPR
_Bit_reference&
operator=(bool __x) _GLIBCXX_NOEXCEPT
{
if (__x)
*_M_p |= _M_mask;
else
*_M_p &= ~_M_mask;
return *this;
}
#if __cplusplus > 202002L
constexpr const _Bit_reference&
operator=(bool __x) const noexcept
{
if (__x)
*_M_p |= _M_mask;
else
*_M_p &= ~_M_mask;
return *this;
}
#endif // C++23
_GLIBCXX20_CONSTEXPR
_Bit_reference&
operator=(const _Bit_reference& __x) _GLIBCXX_NOEXCEPT
{ return *this = bool(__x); }
_GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
bool
operator==(const _Bit_reference& __x) const
{ return bool(*this) == bool(__x); }
_GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
bool
operator<(const _Bit_reference& __x) const
{ return !bool(*this) && bool(__x); }
_GLIBCXX20_CONSTEXPR
void
flip() _GLIBCXX_NOEXCEPT
{ *_M_p ^= _M_mask; }
#if __cplusplus >= 201103L
_GLIBCXX20_CONSTEXPR
friend void
swap(_Bit_reference __x, _Bit_reference __y) noexcept
{
bool __tmp = __x;
__x = __y;
__y = __tmp;
}
_GLIBCXX20_CONSTEXPR
friend void
swap(_Bit_reference __x, bool& __y) noexcept
{
bool __tmp = __x;
__x = __y;
__y = __tmp;
}
_GLIBCXX20_CONSTEXPR
friend void
swap(bool& __x, _Bit_reference __y) noexcept
{
bool __tmp = __x;
__x = __y;
__y = __tmp;
}
#endif
};
// Ignore warnings about std::iterator.
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
struct _Bit_iterator_base
: public std::iterator<std::random_access_iterator_tag, bool>
{
_Bit_type * _M_p;
unsigned int _M_offset;
_GLIBCXX20_CONSTEXPR _GLIBCXX_ALWAYS_INLINE
void
_M_assume_normalized() const
{
#if __has_attribute(__assume__) && !defined(__clang__)
unsigned int __ofst = _M_offset;
__attribute__ ((__assume__ (__ofst < unsigned(_S_word_bit))));
#endif
}
_GLIBCXX20_CONSTEXPR
_Bit_iterator_base(_Bit_type * __x, unsigned int __y)
: _M_p(__x), _M_offset(__y) { }
_GLIBCXX20_CONSTEXPR
void
_M_bump_up()
{
_M_assume_normalized();
if (_M_offset++ == int(_S_word_bit) - 1)
{
_M_offset = 0;
++_M_p;
}
}
_GLIBCXX20_CONSTEXPR
void
_M_bump_down()
{
_M_assume_normalized();
if (_M_offset-- == 0)
{
_M_offset = int(_S_word_bit) - 1;
--_M_p;
}
}
_GLIBCXX20_CONSTEXPR
void
_M_incr(ptrdiff_t __i)
{
_M_assume_normalized();
difference_type __n = __i + _M_offset;
_M_p += __n / int(_S_word_bit);
__n = __n % int(_S_word_bit);
if (__n < 0)
{
__n += int(_S_word_bit);
--_M_p;
}
_M_offset = static_cast<unsigned int>(__n);
}
_GLIBCXX_NODISCARD
friend _GLIBCXX20_CONSTEXPR bool
operator==(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y)
{
__x._M_assume_normalized();
__y._M_assume_normalized();
return __x._M_p == __y._M_p && __x._M_offset == __y._M_offset;
}
#if __cpp_lib_three_way_comparison
[[nodiscard]]
friend constexpr strong_ordering
operator<=>(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y)
noexcept
{
__x._M_assume_normalized();
__y._M_assume_normalized();
if (const auto __cmp = __x._M_p <=> __y._M_p; __cmp != 0)
return __cmp;
return __x._M_offset <=> __y._M_offset;
}
#else
_GLIBCXX_NODISCARD
friend bool
operator<(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y)
{
__x._M_assume_normalized();
__y._M_assume_normalized();
return __x._M_p < __y._M_p
|| (__x._M_p == __y._M_p && __x._M_offset < __y._M_offset);
}
_GLIBCXX_NODISCARD
friend bool
operator!=(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y)
{ return !(__x == __y); }
_GLIBCXX_NODISCARD
friend bool
operator>(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y)
{ return __y < __x; }
_GLIBCXX_NODISCARD
friend bool
operator<=(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y)
{ return !(__y < __x); }
_GLIBCXX_NODISCARD
friend bool
operator>=(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y)
{ return !(__x < __y); }
#endif // three-way comparison
friend _GLIBCXX20_CONSTEXPR ptrdiff_t
operator-(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y)
{
__x._M_assume_normalized();
__y._M_assume_normalized();
return (int(_S_word_bit) * (__x._M_p - __y._M_p)
+ __x._M_offset - __y._M_offset);
}
};
#pragma GCC diagnostic pop
struct _Bit_iterator : public _Bit_iterator_base
{
typedef _Bit_reference reference;
#if __cplusplus > 201703L
typedef void pointer;
#else
typedef _Bit_reference* pointer;
#endif
typedef _Bit_iterator iterator;
_GLIBCXX20_CONSTEXPR
_Bit_iterator() : _Bit_iterator_base(0, 0) { }
_GLIBCXX20_CONSTEXPR
_Bit_iterator(_Bit_type * __x, unsigned int __y)
: _Bit_iterator_base(__x, __y) { }
_GLIBCXX20_CONSTEXPR
iterator
_M_const_cast() const
{ return *this; }
_GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
reference
operator*() const
{
_M_assume_normalized();
return reference(_M_p, 1UL << _M_offset);
}
_GLIBCXX20_CONSTEXPR
iterator&
operator++()
{
_M_bump_up();
return *this;
}
_GLIBCXX20_CONSTEXPR
iterator
operator++(int)
{
iterator __tmp = *this;
_M_bump_up();
return __tmp;
}
_GLIBCXX20_CONSTEXPR
iterator&
operator--()
{
_M_bump_down();
return *this;
}
_GLIBCXX20_CONSTEXPR
iterator
operator--(int)
{
iterator __tmp = *this;
_M_bump_down();
return __tmp;
}
_GLIBCXX20_CONSTEXPR
iterator&
operator+=(difference_type __i)
{
_M_incr(__i);
return *this;
}
_GLIBCXX20_CONSTEXPR
iterator&
operator-=(difference_type __i)
{
*this += -__i;
return *this;
}
_GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
reference
operator[](difference_type __i) const
{ return *(*this + __i); }
_GLIBCXX_NODISCARD
friend _GLIBCXX20_CONSTEXPR iterator
operator+(const iterator& __x, difference_type __n)
{
iterator __tmp = __x;
__tmp += __n;
return __tmp;
}
_GLIBCXX_NODISCARD
friend _GLIBCXX20_CONSTEXPR iterator
operator+(difference_type __n, const iterator& __x)
{ return __x + __n; }
_GLIBCXX_NODISCARD
friend _GLIBCXX20_CONSTEXPR iterator
operator-(const iterator& __x, difference_type __n)
{
iterator __tmp = __x;
__tmp -= __n;
return __tmp;
}
};
struct _Bit_const_iterator : public _Bit_iterator_base
{
typedef bool reference;
typedef bool const_reference;
#if __cplusplus > 201703L
typedef void pointer;
#else
typedef const bool* pointer;
#endif
typedef _Bit_const_iterator const_iterator;
_GLIBCXX20_CONSTEXPR
_Bit_const_iterator() : _Bit_iterator_base(0, 0) { }
_GLIBCXX20_CONSTEXPR
_Bit_const_iterator(_Bit_type * __x, unsigned int __y)
: _Bit_iterator_base(__x, __y) { }
_GLIBCXX20_CONSTEXPR
_Bit_const_iterator(const _Bit_iterator& __x)
: _Bit_iterator_base(__x._M_p, __x._M_offset) { }
_GLIBCXX20_CONSTEXPR
_Bit_iterator
_M_const_cast() const
{ return _Bit_iterator(_M_p, _M_offset); }
_GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
const_reference
operator*() const
{
_M_assume_normalized();
return _Bit_reference(_M_p, 1UL << _M_offset);
}
_GLIBCXX20_CONSTEXPR
const_iterator&
operator++()
{
_M_bump_up();
return *this;
}
_GLIBCXX20_CONSTEXPR
const_iterator
operator++(int)
{
const_iterator __tmp = *this;
_M_bump_up();
return __tmp;
}
_GLIBCXX20_CONSTEXPR
const_iterator&
operator--()
{
_M_bump_down();
return *this;
}
_GLIBCXX20_CONSTEXPR
const_iterator
operator--(int)
{
const_iterator __tmp = *this;
_M_bump_down();
return __tmp;
}
_GLIBCXX20_CONSTEXPR
const_iterator&
operator+=(difference_type __i)
{
_M_incr(__i);
return *this;
}
_GLIBCXX20_CONSTEXPR
const_iterator&
operator-=(difference_type __i)
{
*this += -__i;
return *this;
}
_GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
const_reference
operator[](difference_type __i) const
{ return *(*this + __i); }
_GLIBCXX_NODISCARD
friend _GLIBCXX20_CONSTEXPR const_iterator
operator+(const const_iterator& __x, difference_type __n)
{
const_iterator __tmp = __x;
__tmp += __n;
return __tmp;
}
_GLIBCXX_NODISCARD
friend _GLIBCXX20_CONSTEXPR const_iterator
operator-(const const_iterator& __x, difference_type __n)
{
const_iterator __tmp = __x;
__tmp -= __n;
return __tmp;
}
_GLIBCXX_NODISCARD
friend _GLIBCXX20_CONSTEXPR const_iterator
operator+(difference_type __n, const const_iterator& __x)
{ return __x + __n; }
};
template<typename _Alloc>
struct _Bvector_base
{
typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template
rebind<_Bit_type>::other _Bit_alloc_type;
typedef typename __gnu_cxx::__alloc_traits<_Bit_alloc_type>
_Bit_alloc_traits;
typedef typename _Bit_alloc_traits::pointer _Bit_pointer;
struct _Bvector_impl_data
{
#if !_GLIBCXX_INLINE_VERSION
_Bit_iterator _M_start;
#else
// We don't need the offset field for the start, it's always zero.
struct {
_Bit_type* _M_p;
// Allow assignment from iterators (assume offset is zero):
_GLIBCXX20_CONSTEXPR
void operator=(_Bit_iterator __it) { _M_p = __it._M_p; }
} _M_start;
#endif
_Bit_iterator _M_finish;
_Bit_pointer _M_end_of_storage;
_GLIBCXX20_CONSTEXPR
_Bvector_impl_data() _GLIBCXX_NOEXCEPT
: _M_start(), _M_finish(), _M_end_of_storage()
{ }
#if __cplusplus >= 201103L
_Bvector_impl_data(const _Bvector_impl_data&) = default;
_Bvector_impl_data&
operator=(const _Bvector_impl_data&) = default;
_GLIBCXX20_CONSTEXPR
_Bvector_impl_data(_Bvector_impl_data&& __x) noexcept
: _Bvector_impl_data(__x)
{ __x._M_reset(); }
_GLIBCXX20_CONSTEXPR
void
_M_move_data(_Bvector_impl_data&& __x) noexcept
{
*this = __x;
__x._M_reset();
}
#endif
_GLIBCXX20_CONSTEXPR
void
_M_reset() _GLIBCXX_NOEXCEPT
{ *this = _Bvector_impl_data(); }
_GLIBCXX20_CONSTEXPR
void
_M_swap_data(_Bvector_impl_data& __x) _GLIBCXX_NOEXCEPT
{
// Do not use std::swap(_M_start, __x._M_start), etc as it loses
// information used by TBAA.
std::swap(*this, __x);
}
};
struct _Bvector_impl
: public _Bit_alloc_type, public _Bvector_impl_data
{
_GLIBCXX20_CONSTEXPR
_Bvector_impl() _GLIBCXX_NOEXCEPT_IF(
is_nothrow_default_constructible<_Bit_alloc_type>::value)
#if __cpp_concepts
requires is_default_constructible_v<_Bit_alloc_type>
#endif
: _Bit_alloc_type()
{ }
_GLIBCXX20_CONSTEXPR
_Bvector_impl(const _Bit_alloc_type& __a) _GLIBCXX_NOEXCEPT
: _Bit_alloc_type(__a)
{ }
#if __cplusplus >= 201103L
// Not defaulted, to enforce noexcept(true) even when
// !is_nothrow_move_constructible<_Bit_alloc_type>.
_GLIBCXX20_CONSTEXPR
_Bvector_impl(_Bvector_impl&& __x) noexcept
: _Bit_alloc_type(std::move(__x)), _Bvector_impl_data(std::move(__x))
{ }
_GLIBCXX20_CONSTEXPR
_Bvector_impl(_Bit_alloc_type&& __a, _Bvector_impl&& __x) noexcept
: _Bit_alloc_type(std::move(__a)), _Bvector_impl_data(std::move(__x))
{ }
#endif
_GLIBCXX20_CONSTEXPR
_Bit_type*
_M_end_addr() const _GLIBCXX_NOEXCEPT
{
if (this->_M_end_of_storage)
return std::__addressof(this->_M_end_of_storage[-1]) + 1;
return 0;
}
};
public:
typedef _Alloc allocator_type;
_GLIBCXX20_CONSTEXPR
_Bit_alloc_type&
_M_get_Bit_allocator() _GLIBCXX_NOEXCEPT
{ return this->_M_impl; }
_GLIBCXX20_CONSTEXPR
const _Bit_alloc_type&
_M_get_Bit_allocator() const _GLIBCXX_NOEXCEPT
{ return this->_M_impl; }
_GLIBCXX20_CONSTEXPR
allocator_type
get_allocator() const _GLIBCXX_NOEXCEPT
{ return allocator_type(_M_get_Bit_allocator()); }
#if __cplusplus >= 201103L
_Bvector_base() = default;
#else
_Bvector_base() { }
#endif
_GLIBCXX20_CONSTEXPR
_Bvector_base(const allocator_type& __a)
: _M_impl(__a) { }
#if __cplusplus >= 201103L
_Bvector_base(_Bvector_base&&) = default;
_GLIBCXX20_CONSTEXPR
_Bvector_base(_Bvector_base&& __x, const allocator_type& __a) noexcept
: _M_impl(_Bit_alloc_type(__a), std::move(__x._M_impl))
{ }
#endif
_GLIBCXX20_CONSTEXPR
~_Bvector_base()
{ this->_M_deallocate(); }
protected:
_Bvector_impl _M_impl;
_GLIBCXX20_CONSTEXPR
_Bit_pointer
_M_allocate(size_t __n)
{
_Bit_pointer __p = _Bit_alloc_traits::allocate(_M_impl, _S_nword(__n));
#if __cpp_lib_is_constant_evaluated && __cpp_constexpr_dynamic_alloc
if (std::is_constant_evaluated())
{
__n = _S_nword(__n);
for (size_t __i = 0; __i < __n; ++__i)
std::construct_at(std::to_address(__p) + __i);
}
#endif
return __p;
}
_GLIBCXX20_CONSTEXPR
void
_M_deallocate()
{
if (_M_impl._M_start._M_p)
{
const size_t __n = _M_impl._M_end_addr() - _M_impl._M_start._M_p;
_Bit_alloc_traits::deallocate(_M_impl,
_M_impl._M_end_of_storage - __n,
__n);
_M_impl._M_reset();
}
}
#if __cplusplus >= 201103L
_GLIBCXX20_CONSTEXPR
void
_M_move_data(_Bvector_base&& __x) noexcept
{ _M_impl._M_move_data(std::move(__x._M_impl)); }
#endif
_GLIBCXX_CONSTEXPR
static size_t
_S_nword(size_t __n)
{ return (__n + int(_S_word_bit) - 1) / int(_S_word_bit); }
};
/**
* @brief A specialization of vector for booleans which offers fixed time
* access to individual elements in any order.
*
* @ingroup sequences
* @headerfile vector
* @since C++98
*
* @tparam _Alloc Allocator type.
*
* Note that vector<bool> does not actually meet the requirements for being
* a container. This is because the reference and pointer types are not
* really references and pointers to bool. See DR96 for details. @see
* vector for function documentation.
*
* In some terminology a %vector can be described as a dynamic
* C-style array, it offers fast and efficient access to individual
* elements in any order and saves the user from worrying about
* memory and size allocation. Subscripting ( @c [] ) access is
* also provided as with C-style arrays.
*/
template<typename _Alloc>
class vector<bool, _Alloc> : protected _Bvector_base<_Alloc>
{
typedef _Bvector_base<_Alloc> _Base;
typedef typename _Base::_Bit_pointer _Bit_pointer;
typedef typename _Base::_Bit_alloc_traits _Bit_alloc_traits;
#if __cplusplus >= 201103L
friend struct std::hash<vector>;
#endif
public:
typedef bool value_type;
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef _Bit_reference reference;
typedef bool const_reference;
typedef _Bit_reference* pointer;
typedef const bool* const_pointer;
typedef _Bit_iterator iterator;
typedef _Bit_const_iterator const_iterator;
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
typedef std::reverse_iterator<iterator> reverse_iterator;
typedef _Alloc allocator_type;
_GLIBCXX20_CONSTEXPR
allocator_type
get_allocator() const
{ return _Base::get_allocator(); }
protected:
using _Base::_M_allocate;
using _Base::_M_deallocate;
using _Base::_S_nword;
using _Base::_M_get_Bit_allocator;
public:
#if __cplusplus >= 201103L
vector() = default;
#else
vector() { }
#endif
_GLIBCXX20_CONSTEXPR
explicit
vector(const allocator_type& __a)
: _Base(__a) { }
#if __cplusplus >= 201103L
_GLIBCXX20_CONSTEXPR
explicit
vector(size_type __n, const allocator_type& __a = allocator_type())
: vector(__n, false, __a)
{ }
_GLIBCXX20_CONSTEXPR
vector(size_type __n, const bool& __value,
const allocator_type& __a = allocator_type())
#else
explicit
vector(size_type __n, const bool& __value = bool(),
const allocator_type& __a = allocator_type())
#endif
: _Base(__a)
{
_M_initialize(__n);
_M_initialize_value(__value);
}
_GLIBCXX20_CONSTEXPR
vector(const vector& __x)
: _Base(_Bit_alloc_traits::_S_select_on_copy(__x._M_get_Bit_allocator()))
{
const_iterator __xbegin = __x.begin(), __xend = __x.end();
_M_initialize(__x.size());
_M_copy_aligned(__xbegin, __xend, begin());
}
#if __cplusplus >= 201103L
vector(vector&&) = default;
private:
_GLIBCXX20_CONSTEXPR
vector(vector&& __x, const allocator_type& __a, true_type) noexcept
: _Base(std::move(__x), __a)
{ }
_GLIBCXX20_CONSTEXPR
vector(vector&& __x, const allocator_type& __a, false_type)
: _Base(__a)
{
if (__x.get_allocator() == __a)
this->_M_move_data(std::move(__x));
else
{
_M_initialize(__x.size());
_M_copy_aligned(__x.begin(), __x.end(), begin());
__x.clear();
}
}
public:
_GLIBCXX20_CONSTEXPR
vector(vector&& __x, const __type_identity_t<allocator_type>& __a)
noexcept(_Bit_alloc_traits::_S_always_equal())
: vector(std::move(__x), __a,
typename _Bit_alloc_traits::is_always_equal{})
{ }
_GLIBCXX20_CONSTEXPR
vector(const vector& __x, const __type_identity_t<allocator_type>& __a)
: _Base(__a)
{
_M_initialize(__x.size());
_M_copy_aligned(__x.begin(), __x.end(), begin());
}
_GLIBCXX20_CONSTEXPR
vector(initializer_list<bool> __l,
const allocator_type& __a = allocator_type())
: _Base(__a)
{
_M_initialize_range(__l.begin(), __l.end(),
random_access_iterator_tag());
}
#endif
#if __cplusplus >= 201103L
template<typename _InputIterator,
typename = std::_RequireInputIter<_InputIterator>>
_GLIBCXX20_CONSTEXPR
vector(_InputIterator __first, _InputIterator __last,
const allocator_type& __a = allocator_type())
: _Base(__a)
{
_M_initialize_range(__first, __last,
std::__iterator_category(__first));
}
#else
template<typename _InputIterator>
vector(_InputIterator __first, _InputIterator __last,
const allocator_type& __a = allocator_type())
: _Base(__a)
{
// Check whether it's an integral type. If so, it's not an iterator.
typedef typename std::__is_integer<_InputIterator>::__type _Integral;
_M_initialize_dispatch(__first, __last, _Integral());
}
#endif
_GLIBCXX20_CONSTEXPR
~vector() _GLIBCXX_NOEXCEPT { }
_GLIBCXX20_CONSTEXPR
vector&
operator=(const vector& __x)
{
if (&__x == this)
return *this;
#if __cplusplus >= 201103L
if (_Bit_alloc_traits::_S_propagate_on_copy_assign())
{
if (this->_M_get_Bit_allocator() != __x._M_get_Bit_allocator())
{
this->_M_deallocate();
std::__alloc_on_copy(_M_get_Bit_allocator(),
__x._M_get_Bit_allocator());
_M_initialize(__x.size());
}
else
std::__alloc_on_copy(_M_get_Bit_allocator(),
__x._M_get_Bit_allocator());
}
#endif
if (__x.size() > capacity())
{
this->_M_deallocate();
_M_initialize(__x.size());
}
this->_M_impl._M_finish = _M_copy_aligned(__x.begin(), __x.end(),
begin());
return *this;
}
#if __cplusplus >= 201103L
_GLIBCXX20_CONSTEXPR
vector&
operator=(vector&& __x) noexcept(_Bit_alloc_traits::_S_nothrow_move())
{
if (_Bit_alloc_traits::_S_propagate_on_move_assign()
|| this->_M_get_Bit_allocator() == __x._M_get_Bit_allocator())
{
this->_M_deallocate();
this->_M_move_data(std::move(__x));
std::__alloc_on_move(_M_get_Bit_allocator(),
__x._M_get_Bit_allocator());
}
else
{
if (__x.size() > capacity())
{
this->_M_deallocate();
_M_initialize(__x.size());
}
this->_M_impl._M_finish = _M_copy_aligned(__x.begin(), __x.end(),
begin());
__x.clear();
}
return *this;
}
_GLIBCXX20_CONSTEXPR
vector&
operator=(initializer_list<bool> __l)
{
this->assign(__l.begin(), __l.end());
return *this;
}
#endif
// assign(), a generalized assignment member function. Two
// versions: one that takes a count, and one that takes a range.
// The range version is a member template, so we dispatch on whether
// or not the type is an integer.
_GLIBCXX20_CONSTEXPR
void
assign(size_type __n, const bool& __x)
{ _M_fill_assign(__n, __x); }
#if __cplusplus >= 201103L
template<typename _InputIterator,
typename = std::_RequireInputIter<_InputIterator>>
_GLIBCXX20_CONSTEXPR
void
assign(_InputIterator __first, _InputIterator __last)
{ _M_assign_aux(__first, __last, std::__iterator_category(__first)); }
#else
template<typename _InputIterator>
void
assign(_InputIterator __first, _InputIterator __last)
{
// Check whether it's an integral type. If so, it's not an iterator.
typedef typename std::__is_integer<_InputIterator>::__type _Integral;
_M_assign_dispatch(__first, __last, _Integral());
}
#endif
#if __cplusplus >= 201103L
_GLIBCXX20_CONSTEXPR
void
assign(initializer_list<bool> __l)
{ _M_assign_aux(__l.begin(), __l.end(), random_access_iterator_tag()); }
#endif
_GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
iterator
begin() _GLIBCXX_NOEXCEPT
{ return iterator(this->_M_impl._M_start._M_p, 0); }
_GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
const_iterator
begin() const _GLIBCXX_NOEXCEPT