-
Notifications
You must be signed in to change notification settings - Fork 47
/
deque
executable file
·1773 lines (1456 loc) · 63.1 KB
/
deque
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
// deque standard header
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#ifndef _DEQUE_
#define _DEQUE_
#include <yvals_core.h>
#if _STL_COMPILER_PREPROCESSOR
#include <xmemory>
#if _HAS_CXX17
#include <xpolymorphic_allocator.h>
#endif // _HAS_CXX17
#pragma pack(push, _CRT_PACKING)
#pragma warning(push, _STL_WARNING_LEVEL)
#pragma warning(disable : _STL_DISABLED_WARNINGS)
_STL_DISABLE_CLANG_WARNINGS
#pragma push_macro("new")
#undef new
_STD_BEGIN
template <class _Mydeque>
class _Deque_unchecked_const_iterator {
private:
using _Size_type = typename _Mydeque::size_type;
static constexpr int _Block_size = _Mydeque::_Block_size;
public:
using iterator_category = random_access_iterator_tag;
using value_type = typename _Mydeque::value_type;
using difference_type = typename _Mydeque::difference_type;
using pointer = typename _Mydeque::const_pointer;
using reference = const value_type&;
_Deque_unchecked_const_iterator() noexcept : _Mycont(), _Myoff(0) {}
_Deque_unchecked_const_iterator(_Size_type _Off, const _Container_base12* _Pdeque) noexcept
: _Mycont(static_cast<const _Mydeque*>(_Pdeque)), _Myoff(_Off) {}
_NODISCARD reference operator*() const noexcept {
_Size_type _Block = _Mycont->_Getblock(_Myoff);
_Size_type _Off = _Myoff % _Block_size;
return _Mycont->_Map[_Block][_Off];
}
_NODISCARD pointer operator->() const noexcept {
return pointer_traits<pointer>::pointer_to(**this);
}
_Deque_unchecked_const_iterator& operator++() noexcept {
++_Myoff;
return *this;
}
_Deque_unchecked_const_iterator operator++(int) noexcept {
_Deque_unchecked_const_iterator _Tmp = *this;
++_Myoff;
return _Tmp;
}
_Deque_unchecked_const_iterator& operator--() noexcept {
--_Myoff;
return *this;
}
_Deque_unchecked_const_iterator operator--(int) noexcept {
_Deque_unchecked_const_iterator _Tmp = *this;
--_Myoff;
return _Tmp;
}
_Deque_unchecked_const_iterator& operator+=(const difference_type _Off) noexcept {
_Myoff += _Off;
return *this;
}
_NODISCARD _Deque_unchecked_const_iterator operator+(const difference_type _Off) const noexcept {
_Deque_unchecked_const_iterator _Tmp = *this;
_Tmp += _Off;
return _Tmp;
}
_NODISCARD_FRIEND _Deque_unchecked_const_iterator operator+(
const difference_type _Off, _Deque_unchecked_const_iterator _Next) noexcept {
_Next += _Off;
return _Next;
}
_Deque_unchecked_const_iterator& operator-=(const difference_type _Off) noexcept {
_Myoff -= _Off;
return *this;
}
_NODISCARD _Deque_unchecked_const_iterator operator-(const difference_type _Off) const noexcept {
_Deque_unchecked_const_iterator _Tmp = *this;
_Tmp -= _Off;
return _Tmp;
}
_NODISCARD difference_type operator-(const _Deque_unchecked_const_iterator& _Right) const noexcept {
return static_cast<difference_type>(_Myoff - _Right._Myoff);
}
_NODISCARD reference operator[](const difference_type _Off) const noexcept {
return *(*this + _Off);
}
_NODISCARD bool operator==(const _Deque_unchecked_const_iterator& _Right) const noexcept {
return _Myoff == _Right._Myoff;
}
#if _HAS_CXX20
_NODISCARD strong_ordering operator<=>(const _Deque_unchecked_const_iterator& _Right) const noexcept {
return _Myoff <=> _Right._Myoff;
}
#else // ^^^ _HAS_CXX20 / !_HAS_CXX20 vvv
_NODISCARD bool operator!=(const _Deque_unchecked_const_iterator& _Right) const noexcept {
return !(*this == _Right);
}
_NODISCARD bool operator<(const _Deque_unchecked_const_iterator& _Right) const noexcept {
return _Myoff < _Right._Myoff;
}
_NODISCARD bool operator>(const _Deque_unchecked_const_iterator& _Right) const noexcept {
return _Right < *this;
}
_NODISCARD bool operator<=(const _Deque_unchecked_const_iterator& _Right) const noexcept {
return !(_Right < *this);
}
_NODISCARD bool operator>=(const _Deque_unchecked_const_iterator& _Right) const noexcept {
return !(*this < _Right);
}
#endif // !_HAS_CXX20
const _Container_base12* _Getcont() const noexcept { // get container pointer
return _Mycont;
}
const _Mydeque* _Mycont;
_Size_type _Myoff; // offset of element in deque
};
template <class _Mydeque>
class _Deque_unchecked_iterator : public _Deque_unchecked_const_iterator<_Mydeque> {
private:
using _Size_type = typename _Mydeque::size_type;
using _Mybase = _Deque_unchecked_const_iterator<_Mydeque>;
public:
using iterator_category = random_access_iterator_tag;
using value_type = typename _Mydeque::value_type;
using difference_type = typename _Mydeque::difference_type;
using pointer = typename _Mydeque::pointer;
using reference = value_type&;
using _Mybase::_Mybase;
_NODISCARD reference operator*() const noexcept {
return const_cast<reference>(_Mybase::operator*());
}
_NODISCARD pointer operator->() const noexcept {
return pointer_traits<pointer>::pointer_to(**this);
}
_Deque_unchecked_iterator& operator++() noexcept {
_Mybase::operator++();
return *this;
}
_Deque_unchecked_iterator operator++(int) noexcept {
_Deque_unchecked_iterator _Tmp = *this;
_Mybase::operator++();
return _Tmp;
}
_Deque_unchecked_iterator& operator--() noexcept {
_Mybase::operator--();
return *this;
}
_Deque_unchecked_iterator operator--(int) noexcept {
_Deque_unchecked_iterator _Tmp = *this;
_Mybase::operator--();
return _Tmp;
}
_Deque_unchecked_iterator& operator+=(const difference_type _Off) noexcept {
_Mybase::operator+=(_Off);
return *this;
}
_NODISCARD _Deque_unchecked_iterator operator+(const difference_type _Off) const noexcept {
_Deque_unchecked_iterator _Tmp = *this;
_Tmp += _Off;
return _Tmp;
}
_NODISCARD_FRIEND _Deque_unchecked_iterator operator+(
const difference_type _Off, _Deque_unchecked_iterator _Next) noexcept {
_Next += _Off;
return _Next;
}
_Deque_unchecked_iterator& operator-=(const difference_type _Off) noexcept {
_Mybase::operator-=(_Off);
return *this;
}
_NODISCARD _Deque_unchecked_iterator operator-(const difference_type _Off) const noexcept {
_Deque_unchecked_iterator _Tmp = *this;
_Tmp -= _Off;
return _Tmp;
}
_NODISCARD difference_type operator-(const _Mybase& _Right) const noexcept {
return _Mybase::operator-(_Right);
}
_NODISCARD reference operator[](const difference_type _Off) const noexcept {
return const_cast<reference>(_Mybase::operator[](_Off));
}
};
template <class _Mydeque>
class _Deque_const_iterator : public _Iterator_base12 {
private:
using _Size_type = typename _Mydeque::size_type;
static constexpr int _Block_size = _Mydeque::_Block_size;
public:
using iterator_category = random_access_iterator_tag;
using value_type = typename _Mydeque::value_type;
using difference_type = typename _Mydeque::difference_type;
using pointer = typename _Mydeque::const_pointer;
using reference = const value_type&;
using _Mydeque_t = _Mydeque; // helper for expression evaluator
enum { _EEN_DS = _Block_size }; // helper for expression evaluator
_Deque_const_iterator() noexcept : _Myoff(0) {
_Setcont(nullptr);
}
_Deque_const_iterator(_Size_type _Off, const _Container_base12* _Pdeque) noexcept : _Myoff(_Off) {
_Setcont(static_cast<const _Mydeque*>(_Pdeque));
}
_NODISCARD reference operator*() const noexcept {
const auto _Mycont = static_cast<const _Mydeque*>(this->_Getcont());
#if _ITERATOR_DEBUG_LEVEL != 0
_STL_VERIFY(_Mycont, "cannot dereference value-initialized deque iterator");
_STL_VERIFY(_Mycont->_Myoff <= this->_Myoff && this->_Myoff < _Mycont->_Myoff + _Mycont->_Mysize,
"cannot deference out of range deque iterator");
#endif // _ITERATOR_DEBUG_LEVEL != 0
_Size_type _Block = _Mycont->_Getblock(_Myoff);
_Size_type _Off = _Myoff % _Block_size;
return _Mycont->_Map[_Block][_Off];
}
_NODISCARD pointer operator->() const noexcept {
return pointer_traits<pointer>::pointer_to(**this);
}
_Deque_const_iterator& operator++() noexcept {
#if _ITERATOR_DEBUG_LEVEL != 0
const auto _Mycont = static_cast<const _Mydeque*>(this->_Getcont());
_STL_VERIFY(_Mycont, "cannot increment value-initialized deque iterator");
_STL_VERIFY(this->_Myoff < _Mycont->_Myoff + _Mycont->_Mysize, "cannot increment deque iterator past end");
#endif // _ITERATOR_DEBUG_LEVEL != 0
++_Myoff;
return *this;
}
_Deque_const_iterator operator++(int) noexcept {
_Deque_const_iterator _Tmp = *this;
++*this;
return _Tmp;
}
_Deque_const_iterator& operator--() noexcept {
#if _ITERATOR_DEBUG_LEVEL != 0
const auto _Mycont = static_cast<const _Mydeque*>(this->_Getcont());
_STL_VERIFY(_Mycont, "cannot decrement value-initialized deque iterator");
_STL_VERIFY(_Mycont->_Myoff < this->_Myoff, "cannot decrement deque iterator before begin");
#endif // _ITERATOR_DEBUG_LEVEL != 0
--_Myoff;
return *this;
}
_Deque_const_iterator operator--(int) noexcept {
_Deque_const_iterator _Tmp = *this;
--*this;
return _Tmp;
}
_Deque_const_iterator& operator+=(const difference_type _Off) noexcept {
#if _ITERATOR_DEBUG_LEVEL != 0
if (_Off != 0) {
const auto _Mycont = static_cast<const _Mydeque*>(this->_Getcont());
_STL_VERIFY(_Mycont, "cannot seek value-initialized deque iterator");
_STL_VERIFY(
_Mycont->_Myoff <= this->_Myoff + _Off && this->_Myoff + _Off <= _Mycont->_Myoff + _Mycont->_Mysize,
"cannot seek deque iterator out of range");
}
#endif // _ITERATOR_DEBUG_LEVEL != 0
_Myoff += _Off;
return *this;
}
_NODISCARD _Deque_const_iterator operator+(const difference_type _Off) const noexcept {
_Deque_const_iterator _Tmp = *this;
_Tmp += _Off;
return _Tmp;
}
_NODISCARD_FRIEND _Deque_const_iterator operator+(
const difference_type _Off, _Deque_const_iterator _Next) noexcept {
_Next += _Off;
return _Next;
}
_Deque_const_iterator& operator-=(const difference_type _Off) noexcept {
return *this += -_Off;
}
_NODISCARD _Deque_const_iterator operator-(const difference_type _Off) const noexcept {
_Deque_const_iterator _Tmp = *this;
_Tmp -= _Off;
return _Tmp;
}
_NODISCARD difference_type operator-(const _Deque_const_iterator& _Right) const noexcept {
_Compat(_Right);
return static_cast<difference_type>(this->_Myoff - _Right._Myoff);
}
_NODISCARD reference operator[](const difference_type _Off) const noexcept {
return *(*this + _Off);
}
_NODISCARD bool operator==(const _Deque_const_iterator& _Right) const noexcept {
_Compat(_Right);
return this->_Myoff == _Right._Myoff;
}
#if _HAS_CXX20
_NODISCARD strong_ordering operator<=>(const _Deque_const_iterator& _Right) const noexcept {
_Compat(_Right);
return this->_Myoff <=> _Right._Myoff;
}
#else // ^^^ _HAS_CXX20 / !_HAS_CXX20 vvv
_NODISCARD bool operator!=(const _Deque_const_iterator& _Right) const noexcept {
return !(*this == _Right);
}
_NODISCARD bool operator<(const _Deque_const_iterator& _Right) const noexcept {
_Compat(_Right);
return this->_Myoff < _Right._Myoff;
}
_NODISCARD bool operator>(const _Deque_const_iterator& _Right) const noexcept {
return _Right < *this;
}
_NODISCARD bool operator<=(const _Deque_const_iterator& _Right) const noexcept {
return !(_Right < *this);
}
_NODISCARD bool operator>=(const _Deque_const_iterator& _Right) const noexcept {
return !(*this < _Right);
}
#endif // !_HAS_CXX20
void _Compat(const _Deque_const_iterator& _Right) const noexcept { // test for compatible iterator pair
#if _ITERATOR_DEBUG_LEVEL == 0
(void) _Right;
#else
_STL_VERIFY(this->_Getcont() == _Right._Getcont(), "deque iterators incompatible");
#endif
}
void _Setcont(const _Mydeque* _Pdeque) noexcept { // set container pointer
this->_Adopt(_Pdeque);
}
using _Prevent_inheriting_unwrap = _Deque_const_iterator;
_NODISCARD _Deque_unchecked_const_iterator<_Mydeque> _Unwrapped() const noexcept {
return {this->_Myoff, this->_Getcont()};
}
void _Verify_offset(const difference_type _Off) const noexcept {
#if _ITERATOR_DEBUG_LEVEL == 0
(void) _Off;
#else // ^^^ _ITERATOR_DEBUG_LEVEL == 0 / _ITERATOR_DEBUG_LEVEL != 0 vvv
if (_Off != 0) {
const auto _Mycont = static_cast<const _Mydeque*>(this->_Getcont());
_STL_VERIFY(_Mycont, "cannot use value-initialized deque iterator");
_STL_VERIFY(
_Mycont->_Myoff <= this->_Myoff + _Off && this->_Myoff + _Off <= _Mycont->_Myoff + _Mycont->_Mysize,
"cannot seek deque iterator out of range");
}
#endif // _ITERATOR_DEBUG_LEVEL == 0
}
#if _ITERATOR_DEBUG_LEVEL != 0
friend void _Verify_range(const _Deque_const_iterator& _First, const _Deque_const_iterator& _Last) noexcept {
// note _Compat check inside operator<=
_STL_VERIFY(_First <= _Last, "deque iterators transposed");
}
#endif // _ITERATOR_DEBUG_LEVEL != 0
void _Seek_to(const _Deque_unchecked_const_iterator<_Mydeque>& _UIt) noexcept {
_Myoff = _UIt._Myoff;
}
_Size_type _Myoff; // offset of element in deque
};
template <class _Mydeque>
class _Deque_iterator : public _Deque_const_iterator<_Mydeque> {
private:
using _Size_type = typename _Mydeque::size_type;
using _Mybase = _Deque_const_iterator<_Mydeque>;
public:
using iterator_category = random_access_iterator_tag;
using value_type = typename _Mydeque::value_type;
using difference_type = typename _Mydeque::difference_type;
using pointer = typename _Mydeque::pointer;
using reference = value_type&;
using _Mybase::_Mybase;
_NODISCARD reference operator*() const noexcept {
return const_cast<reference>(_Mybase::operator*());
}
_NODISCARD pointer operator->() const noexcept {
return pointer_traits<pointer>::pointer_to(**this);
}
_Deque_iterator& operator++() noexcept {
_Mybase::operator++();
return *this;
}
_Deque_iterator operator++(int) noexcept {
_Deque_iterator _Tmp = *this;
_Mybase::operator++();
return _Tmp;
}
_Deque_iterator& operator--() noexcept {
_Mybase::operator--();
return *this;
}
_Deque_iterator operator--(int) noexcept {
_Deque_iterator _Tmp = *this;
_Mybase::operator--();
return _Tmp;
}
_Deque_iterator& operator+=(const difference_type _Off) noexcept {
_Mybase::operator+=(_Off);
return *this;
}
_NODISCARD _Deque_iterator operator+(const difference_type _Off) const noexcept {
_Deque_iterator _Tmp = *this;
_Tmp += _Off;
return _Tmp;
}
_NODISCARD_FRIEND _Deque_iterator operator+(const difference_type _Off, _Deque_iterator _Next) noexcept {
_Next += _Off;
return _Next;
}
_Deque_iterator& operator-=(const difference_type _Off) noexcept {
_Mybase::operator-=(_Off);
return *this;
}
using _Mybase::operator-;
_NODISCARD _Deque_iterator operator-(const difference_type _Off) const noexcept {
_Deque_iterator _Tmp = *this;
_Tmp -= _Off;
return _Tmp;
}
_NODISCARD reference operator[](const difference_type _Off) const noexcept {
return const_cast<reference>(_Mybase::operator[](_Off));
}
using _Prevent_inheriting_unwrap = _Deque_iterator;
_NODISCARD _Deque_unchecked_iterator<_Mydeque> _Unwrapped() const noexcept {
return {this->_Myoff, this->_Getcont()};
}
};
template <class _Value_type, class _Size_type, class _Difference_type, class _Pointer, class _Const_pointer,
class _Mapptr_type>
struct _Deque_iter_types {
using value_type = _Value_type;
using size_type = _Size_type;
using difference_type = _Difference_type;
using pointer = _Pointer;
using const_pointer = _Const_pointer;
using _Mapptr = _Mapptr_type;
};
template <class _Ty>
struct _Deque_simple_types : _Simple_types<_Ty> {
using _Mapptr = _Ty**;
};
template <class _Val_types>
class _Deque_val : public _Container_base12 {
public:
using value_type = typename _Val_types::value_type;
using size_type = typename _Val_types::size_type;
using difference_type = typename _Val_types::difference_type;
using pointer = typename _Val_types::pointer;
using const_pointer = typename _Val_types::const_pointer;
using reference = value_type&;
using const_reference = const value_type&;
using _Mapptr = typename _Val_types::_Mapptr;
private:
static constexpr size_t _Bytes = sizeof(value_type);
public:
static constexpr int _Block_size = _Bytes <= 1 ? 16
: _Bytes <= 2 ? 8
: _Bytes <= 4 ? 4
: _Bytes <= 8 ? 2
: 1; // elements per block (a power of 2)
_Deque_val() noexcept : _Map(), _Mapsize(0), _Myoff(0), _Mysize(0) {}
size_type _Getblock(size_type _Off) const noexcept {
// NB: _Mapsize and _Block_size are guaranteed to be powers of 2
return (_Off / _Block_size) & (_Mapsize - 1);
}
_Mapptr _Map; // pointer to array of pointers to blocks
size_type _Mapsize; // size of map array, zero or 2^N
size_type _Myoff; // offset of initial element
size_type _Mysize; // current length of sequence
};
_EXPORT_STD template <class _Ty, class _Alloc = allocator<_Ty>>
class deque {
private:
friend _Tidy_guard<deque>;
static_assert(!_ENFORCE_MATCHING_ALLOCATORS || is_same_v<_Ty, typename _Alloc::value_type>,
_MISMATCHED_ALLOCATOR_MESSAGE("deque<T, Allocator>", "T"));
static_assert(is_object_v<_Ty>, "The C++ Standard forbids containers of non-object types "
"because of [container.requirements].");
using _Alty = _Rebind_alloc_t<_Alloc, _Ty>;
using _Alty_traits = allocator_traits<_Alty>;
using _Alpty = _Rebind_alloc_t<_Alloc, typename _Alty_traits::pointer>;
using _Alpty_traits = allocator_traits<_Alpty>;
using _Mapptr = typename _Alpty_traits::pointer;
using _Alproxy_ty = _Rebind_alloc_t<_Alty, _Container_proxy>;
using _Scary_val = _Deque_val<conditional_t<_Is_simple_alloc_v<_Alty>, _Deque_simple_types<_Ty>,
_Deque_iter_types<_Ty, typename _Alty_traits::size_type, typename _Alty_traits::difference_type,
typename _Alty_traits::pointer, typename _Alty_traits::const_pointer, _Mapptr>>>;
static constexpr int _Minimum_map_size = 8;
static constexpr int _Block_size = _Scary_val::_Block_size;
public:
using allocator_type = _Alloc;
using value_type = _Ty;
using size_type = typename _Alty_traits::size_type;
using difference_type = typename _Alty_traits::difference_type;
using pointer = typename _Alty_traits::pointer;
using const_pointer = typename _Alty_traits::const_pointer;
using reference = _Ty&;
using const_reference = const _Ty&;
using iterator = _Deque_iterator<_Scary_val>;
using const_iterator = _Deque_const_iterator<_Scary_val>;
using _Unchecked_iterator = _Deque_unchecked_iterator<_Scary_val>;
using _Unchecked_const_iterator = _Deque_unchecked_const_iterator<_Scary_val>;
using reverse_iterator = _STD reverse_iterator<iterator>;
using const_reverse_iterator = _STD reverse_iterator<const_iterator>;
enum { _EEN_DS = _Block_size }; // helper for expression evaluator
deque() : _Mypair(_Zero_then_variadic_args_t{}) {
_Get_data()._Alloc_proxy(static_cast<_Alproxy_ty>(_Getal()));
}
explicit deque(const _Alloc& _Al) : _Mypair(_One_then_variadic_args_t{}, _Al) {
_Get_data()._Alloc_proxy(static_cast<_Alproxy_ty>(_Getal()));
}
explicit deque(_CRT_GUARDOVERFLOW size_type _Count, const _Alloc& _Al = _Alloc())
: _Mypair(_One_then_variadic_args_t{}, _Al) {
_Alproxy_ty _Alproxy(_Getal());
_Container_proxy_ptr12<_Alproxy_ty> _Proxy(_Alproxy, _Get_data());
_Tidy_guard<deque> _Guard{this};
resize(_Count);
_Guard._Target = nullptr;
_Proxy._Release();
}
deque(_CRT_GUARDOVERFLOW size_type _Count, const _Ty& _Val) : _Mypair(_Zero_then_variadic_args_t{}) {
_Alproxy_ty _Alproxy(_Getal());
_Container_proxy_ptr12<_Alproxy_ty> _Proxy(_Alproxy, _Get_data());
_Construct_n(_Count, _Val);
_Proxy._Release();
}
deque(_CRT_GUARDOVERFLOW size_type _Count, const _Ty& _Val, const _Alloc& _Al)
: _Mypair(_One_then_variadic_args_t{}, _Al) {
_Alproxy_ty _Alproxy(_Getal());
_Container_proxy_ptr12<_Alproxy_ty> _Proxy(_Alproxy, _Get_data());
_Construct_n(_Count, _Val);
_Proxy._Release();
}
deque(const deque& _Right)
: _Mypair(_One_then_variadic_args_t{}, _Alty_traits::select_on_container_copy_construction(_Right._Getal())) {
_Alproxy_ty _Alproxy(_Getal());
_Container_proxy_ptr12<_Alproxy_ty> _Proxy(_Alproxy, _Get_data());
_Construct(_Right._Unchecked_begin(), _Right._Unchecked_end());
_Proxy._Release();
}
deque(const deque& _Right, const _Identity_t<_Alloc>& _Al) : _Mypair(_One_then_variadic_args_t{}, _Al) {
_Alproxy_ty _Alproxy(_Getal());
_Container_proxy_ptr12<_Alproxy_ty> _Proxy(_Alproxy, _Get_data());
_Construct(_Right._Unchecked_begin(), _Right._Unchecked_end());
_Proxy._Release();
}
template <class _Iter, enable_if_t<_Is_iterator_v<_Iter>, int> = 0>
deque(_Iter _First, _Iter _Last) : _Mypair(_Zero_then_variadic_args_t{}) {
_Alproxy_ty _Alproxy(_Getal());
_Container_proxy_ptr12<_Alproxy_ty> _Proxy(_Alproxy, _Get_data());
_Construct(_First, _Last);
_Proxy._Release();
}
template <class _Iter, enable_if_t<_Is_iterator_v<_Iter>, int> = 0>
deque(_Iter _First, _Iter _Last, const _Alloc& _Al) : _Mypair(_One_then_variadic_args_t{}, _Al) {
_Alproxy_ty _Alproxy(_Getal());
_Container_proxy_ptr12<_Alproxy_ty> _Proxy(_Alproxy, _Get_data());
_Construct(_First, _Last);
_Proxy._Release();
}
#if _HAS_CXX23 && defined(__cpp_lib_concepts) // TRANSITION, GH-395
template <_Container_compatible_range<_Ty> _Rng>
deque(from_range_t, _Rng&& _Range) : _Mypair(_Zero_then_variadic_args_t{}) {
_Alproxy_ty _Alproxy(_Getal());
_Container_proxy_ptr12<_Alproxy_ty> _Proxy(_Alproxy, _Get_data());
_Construct(_RANGES _Ubegin(_Range), _RANGES _Uend(_Range));
_Proxy._Release();
}
template <_Container_compatible_range<_Ty> _Rng>
deque(from_range_t, _Rng&& _Range, const _Alloc& _Al) : _Mypair(_One_then_variadic_args_t{}, _Al) {
_Alproxy_ty _Alproxy(_Getal());
_Container_proxy_ptr12<_Alproxy_ty> _Proxy(_Alproxy, _Get_data());
_Construct(_RANGES _Ubegin(_Range), _RANGES _Uend(_Range));
_Proxy._Release();
}
#endif // _HAS_CXX23 && defined(__cpp_lib_concepts)
private:
template <class _Iter, class _Sent>
void _Construct(_Iter _First, const _Sent _Last) { // initialize from input range [_First, _Last)
_Tidy_guard<deque> _Guard{this};
for (; _First != _Last; ++_First) {
_Emplace_back_internal(*_First);
}
_Guard._Target = nullptr;
}
void _Construct_n(size_type _Count, const _Ty& _Val) { // construct from _Count * _Val
_Tidy_guard<deque> _Guard{this};
for (; _Count > 0; --_Count) {
_Emplace_back_internal(_Val);
}
_Guard._Target = nullptr;
}
public:
deque(deque&& _Right) : _Mypair(_One_then_variadic_args_t{}, _STD move(_Right._Getal())) {
_Get_data()._Alloc_proxy(static_cast<_Alproxy_ty>(_Getal()));
_Take_contents(_Right);
}
deque(deque&& _Right, const _Identity_t<_Alloc>& _Al) : _Mypair(_One_then_variadic_args_t{}, _Al) {
_Alproxy_ty _Alproxy(_Getal());
if constexpr (!_Alty_traits::is_always_equal::value) {
if (_Getal() != _Right._Getal()) {
_Container_proxy_ptr12<_Alproxy_ty> _Proxy(_Alproxy, _Get_data());
_Construct(_STD make_move_iterator(_Right._Unchecked_begin()),
_STD make_move_iterator(_Right._Unchecked_end()));
_Proxy._Release();
return;
}
}
_Get_data()._Alloc_proxy(_Alproxy);
_Take_contents(_Right);
}
deque& operator=(deque&& _Right) noexcept(_Alty_traits::is_always_equal::value) {
if (this == _STD addressof(_Right)) {
return *this;
}
auto& _Al = _Getal();
auto& _Right_al = _Right._Getal();
constexpr auto _Pocma_val = _Choose_pocma_v<_Alty>;
if constexpr (_Pocma_val == _Pocma_values::_Propagate_allocators) {
if (_Al != _Right_al) {
_Alproxy_ty _Alproxy(_Al);
_Alproxy_ty _Right_alproxy(_Right_al);
_Container_proxy_ptr12<_Alproxy_ty> _Proxy(_Right_alproxy, _Leave_proxy_unbound{});
_Tidy();
_Pocma(_Al, _Right_al);
_Proxy._Bind(_Alproxy, _STD addressof(_Get_data()));
_Take_contents(_Right);
return *this;
}
} else if constexpr (_Pocma_val == _Pocma_values::_No_propagate_allocators) {
if (_Al != _Right_al) {
assign(_STD make_move_iterator(_Right._Unchecked_begin()),
_STD make_move_iterator(_Right._Unchecked_end()));
return *this;
}
}
_Tidy();
_Pocma(_Al, _Right_al);
_Take_contents(_Right);
return *this;
}
private:
void _Take_contents(deque& _Right) noexcept {
// move from _Right, stealing its contents
// pre: _Getal() == _Right._Getal()
auto& _My_data = _Get_data();
auto& _Right_data = _Right._Get_data();
_My_data._Swap_proxy_and_iterators(_Right_data);
_My_data._Map = _Right_data._Map;
_My_data._Mapsize = _Right_data._Mapsize;
_My_data._Myoff = _Right_data._Myoff;
_My_data._Mysize = _Right_data._Mysize;
_Right_data._Map = nullptr;
_Right_data._Mapsize = 0;
_Right_data._Myoff = 0;
_Right_data._Mysize = 0;
}
public:
void push_front(_Ty&& _Val) {
emplace_front(_STD move(_Val));
}
#if _HAS_CXX23 && defined(__cpp_lib_concepts) // TRANSITION, GH-395
template <_Container_compatible_range<_Ty> _Rng>
void prepend_range(_Rng&& _Range) {
_Orphan_all();
const auto _Oldsize = _Mysize();
_Restore_old_size_guard<_Pop_direction::_Front> _Guard{this, _Oldsize};
if constexpr (_RANGES bidirectional_range<_Rng>) {
const auto _UFirst = _RANGES _Ubegin(_Range);
auto _ULast = _RANGES _Get_final_iterator_unwrapped(_Range);
while (_UFirst != _ULast) {
_Emplace_front_internal(*--_ULast); // prepend in order
}
} else {
auto _UFirst = _RANGES _Ubegin(_Range);
const auto _ULast = _RANGES _Uend(_Range);
for (; _UFirst != _ULast; ++_UFirst) {
_Emplace_front_internal(*_UFirst); // prepend flipped
}
const auto _Num = static_cast<difference_type>(_Mysize() - _Oldsize);
_STD reverse(begin(), begin() + _Num);
}
_Guard._Container = nullptr;
}
#endif // _HAS_CXX23 && defined(__cpp_lib_concepts)
void push_back(_Ty&& _Val) {
_Orphan_all();
_Emplace_back_internal(_STD move(_Val));
}
#if _HAS_CXX23 && defined(__cpp_lib_concepts) // TRANSITION, GH-395
template <_Container_compatible_range<_Ty> _Rng>
void append_range(_Rng&& _Range) {
_Orphan_all();
const auto _Oldsize = _Mysize();
auto _UFirst = _RANGES _Ubegin(_Range);
const auto _ULast = _RANGES _Uend(_Range);
_Restore_old_size_guard<_Pop_direction::_Back> _Guard{this, _Oldsize};
for (; _UFirst != _ULast; ++_UFirst) {
_Emplace_back_internal(*_UFirst);
}
_Guard._Container = nullptr;
}
#endif // _HAS_CXX23 && defined(__cpp_lib_concepts)
iterator insert(const_iterator _Where, _Ty&& _Val) {
return emplace(_Where, _STD move(_Val));
}
template <class... _Valty>
decltype(auto) emplace_front(_Valty&&... _Val) {
_Orphan_all();
_Emplace_front_internal(_STD forward<_Valty>(_Val)...);
#if _HAS_CXX17
return front();
#endif // _HAS_CXX17
}
template <class... _Valty>
decltype(auto) emplace_back(_Valty&&... _Val) {
_Orphan_all();
_Emplace_back_internal(_STD forward<_Valty>(_Val)...);
#if _HAS_CXX17
return back();
#endif // _HAS_CXX17
}
template <class... _Valty>
iterator emplace(const_iterator _Where, _Valty&&... _Val) {
const auto _Off = static_cast<size_type>(_Where - begin());
#if _ITERATOR_DEBUG_LEVEL == 2
_STL_VERIFY(_Off <= _Mysize(), "deque emplace iterator outside range");
#endif // _ITERATOR_DEBUG_LEVEL == 2
if (_Off <= _Mysize() / 2) { // closer to front, push to front then rotate
emplace_front(_STD forward<_Valty>(_Val)...);
_STD rotate(begin(), _Next_iter(begin()), begin() + static_cast<difference_type>(1 + _Off));
} else { // closer to back, push to back then rotate
emplace_back(_STD forward<_Valty>(_Val)...);
_STD rotate(begin() + static_cast<difference_type>(_Off), _Prev_iter(end()), end());
}
return begin() + static_cast<difference_type>(_Off);
}
deque(initializer_list<_Ty> _Ilist, const _Alloc& _Al = allocator_type())
: _Mypair(_One_then_variadic_args_t{}, _Al) {
_Alproxy_ty _Alproxy(_Getal());
_Container_proxy_ptr12<_Alproxy_ty> _Proxy(_Alproxy, _Get_data());
_Construct(_Ilist.begin(), _Ilist.end());
_Proxy._Release();
}
deque& operator=(initializer_list<_Ty> _Ilist) {
assign(_Ilist.begin(), _Ilist.end());
return *this;
}
void assign(initializer_list<_Ty> _Ilist) {
assign(_Ilist.begin(), _Ilist.end());
}
iterator insert(const_iterator _Where, initializer_list<_Ty> _Ilist) {
return insert(_Where, _Ilist.begin(), _Ilist.end());
}
~deque() noexcept {
_Tidy();
_Alproxy_ty _Proxy_allocator(_Getal());
_Delete_plain_internal(_Proxy_allocator, _STD exchange(_Get_data()._Myproxy, nullptr));
}
deque& operator=(const deque& _Right) {
if (this == _STD addressof(_Right)) {
return *this;
}
auto& _Al = _Getal();
auto& _Right_al = _Right._Getal();
if constexpr (_Choose_pocca_v<_Alty>) {
if (_Al != _Right_al) {
_Tidy();
_Get_data()._Reload_proxy(static_cast<_Alproxy_ty>(_Al), static_cast<_Alproxy_ty>(_Right_al));
}
}
_Pocca(_Al, _Right_al);
assign(_Right._Unchecked_begin(), _Right._Unchecked_end());
return *this;
}
_NODISCARD iterator begin() noexcept {
return iterator(_Myoff(), _STD addressof(_Get_data()));
}
_NODISCARD const_iterator begin() const noexcept {
return const_iterator(_Myoff(), _STD addressof(_Get_data()));
}
_NODISCARD iterator end() noexcept {
return iterator(_Myoff() + _Mysize(), _STD addressof(_Get_data()));
}
_NODISCARD const_iterator end() const noexcept {
return const_iterator(_Myoff() + _Mysize(), _STD addressof(_Get_data()));
}
_Unchecked_iterator _Unchecked_begin() noexcept {
return _Unchecked_iterator(_Myoff(), _STD addressof(_Get_data()));
}
_Unchecked_const_iterator _Unchecked_begin() const noexcept {
return _Unchecked_const_iterator(_Myoff(), _STD addressof(_Get_data()));
}
_Unchecked_iterator _Unchecked_end() noexcept {
return _Unchecked_iterator(_Myoff() + _Mysize(), _STD addressof(_Get_data()));
}
_Unchecked_const_iterator _Unchecked_end() const noexcept {
return _Unchecked_const_iterator(_Myoff() + _Mysize(), _STD addressof(_Get_data()));
}
iterator _Make_iter(const_iterator _Where) const noexcept {
return iterator(_Where._Myoff, _STD addressof(_Get_data()));
}
_NODISCARD reverse_iterator rbegin() noexcept {
return reverse_iterator(end());
}
_NODISCARD const_reverse_iterator rbegin() const noexcept {
return const_reverse_iterator(end());
}
_NODISCARD reverse_iterator rend() noexcept {
return reverse_iterator(begin());
}
_NODISCARD const_reverse_iterator rend() const noexcept {
return const_reverse_iterator(begin());
}
_NODISCARD const_iterator cbegin() const noexcept {
return begin();
}
_NODISCARD const_iterator cend() const noexcept {
return end();
}
_NODISCARD const_reverse_iterator crbegin() const noexcept {
return rbegin();
}
_NODISCARD const_reverse_iterator crend() const noexcept {
return rend();
}
void shrink_to_fit() {
size_type _Oldcapacity = _Block_size * _Mapsize();