Форум программистов, компьютерный форум, киберфорум
С++ для начинающих
Войти
Регистрация
Восстановить пароль
Карта форума Темы раздела Блоги Сообщество Поиск Заказать работу  
 
Рейтинг 4.71/34: Рейтинг темы: голосов - 34, средняя оценка - 4.71
0 / 0 / 0
Регистрация: 10.02.2014
Сообщений: 24
1

Программа учета заявок

08.04.2014, 10:10. Показов 6814. Ответов 18
Метки нет (Все метки)

Author24 — интернет-сервис помощи студентам
Здравствуйте. Задали курсовую, нужна помощь в некоторых моментах.
Задание

Написать программу учета заявок на авиабилеты. Каждая заявка содержит: пункт назначения, номер рейса, фамилию и инициалы пассажира, желаемую дату вылета. Программа должна обеспечивать выбор с помощью меню и выполнение одной из следующих функций:
• добавление заявок в список;
• удаление заявок;
• вывод заявок по заданному номеру рейса и дате вылета;
• вывод всех заявок.
Для хранения данных использовать класс "коллекция ключ-значение" в качестве ключа использовать "пункт назначения". Предусмотреть сохранение всех данных при выходе в файл и восстановление при повторном запуске программы.


Мой код(Не доделанный)

C++
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
#include <iostream>
#include <fstream>
#include <conio.h>
#define BUF_SIZE 50
using namespace std;
 
void OutputAll()
{
}
 
 
void getDeleteTicket()
{
    
}
 
char* getAddTicket(char Surname[BUF_SIZE], char Destination[BUF_SIZE], char Date[BUF_SIZE], char FlightNumber[BUF_SIZE])
{
    cout << "Добавление заявки в список. Шаг 1/4" << endl
         << "-------------------------------------------------" << endl
         << "Введите Фамилию И.О. пассажира: ";
    cin >> Surname;
    system("cls");
    cout << "Добавление заявки в список. Шаг 2/4" << endl
         << "-------------------------------------------------" << endl
         << "Введите Пункт назначения: ";
    cin >> Destination;
    system("cls");
    cout << "Добавление заявки в список. Шаг 3/4" << endl
         << "-------------------------------------------------" << endl
         << "Введите желаемую дату вылета: ";
    cin >> Date;
    system("cls");
    cout << "Добавление заявки в список. Шаг 4/4" << endl
         << "-------------------------------------------------" << endl
         << "Введите номер рейса: ";
    cin >> FlightNumber;
    system("cls");
    return Surname, Destination, Date, FlightNumber;
}
 
 
int main()
{
    char Sur[BUF_SIZE], Des[BUF_SIZE], Dat[BUF_SIZE], Num[BUF_SIZE];
    int Number;
    loop:
    setlocale(LC_ALL, "");
    cout << "\tПрограмма учета заявок на авиабилеты: " << endl
              << "-------------------------------------------------" << endl
              << "1. Добавление заявок в список. " << endl
              << "2. Удаление заявок." << endl
              << "3. Вывод заявок по заданному номеру рейсу дате вылета. " << endl
              << "4. Вывод всех заявок. " << endl
              << "5. Выход. " << endl
              << "Выберите действие: ";
    cin >> Number;
    switch(Number)
    {
    case 1:
        system("cls");
        getAddTicket(Sur, Des, Dat, Num);
        goto loop;
    case 2:
        system("cls");
        getDeleteTicket();
        goto loop;
    case 3:
        system("cls");
        system("pause");
        goto loop;
    case 4:
        system("cls");
        cout << "Вывод всех заявок" << endl
         << "-------------------------------------------------" << endl
         << "Фамилия И.О: " << Sur << endl
         << "Пункт назначения: " << Des << endl
         << "Дата вылета: " << Dat << endl
         << "Номер рейса: " << Num << endl;
        system("pause");
        goto loop;
    }
    system("pause");
    return 0;
}

Собственно в чем вопросы:
• 1. И самый главный вопрос: Как организовать работу с файлом? Чтоб для каждой строчки была своя запись. С возможностью добавления/удаления.
• 2. В моей программе функцию вывода заявок я сделал в main. Как отправить значения Sur, Dat, Des, Num в функцию OutputAll и уже там вывести?
0
Лучшие ответы (1)
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
08.04.2014, 10:10
Ответы с готовыми решениями:

Программа учета за складом
Здравствуйте, есть задача: Разработать программу, которая может быть использована для поддержания...

Программа учета книг
Написать программу, выполняющую следующие действия со структурой и файлами: Программа учета книг,...

Программа учета больных в поликлинике
Здраствуите,всем!! Я тут написал программу, уже мозги ломаю не могу понять почему слетает...

Нужна программа учета диких животных
Такое задание. Разработать приложение, позволяющее собирать и накапливать сведения по учёту...

18
Эксперт по математике/физикеЭксперт С++
2049 / 1367 / 396
Регистрация: 16.05.2013
Сообщений: 3,508
Записей в блоге: 6
08.04.2014, 10:22 2
Наверное самый простой метод ввести структуру вида:
C++
1
2
3
4
5
6
struct Request {
    string Surname;
    string Destination;
    string Date;
    string Destination;
};
Работа с файлом:
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
//Создать поток и связать его с файлом
fstream file("name_file");
...
Request request;
...
//Запись в файл переменной request
file.write(reinterpret_cast<char*>(&request), sizeof(Request));
...
//Чтение из файла в переменную request
file.read(reinterpret_cast<char*>(&request), sizeof(Request));
...
//Закрыть файл
file.close();
1
0 / 0 / 0
Регистрация: 10.02.2014
Сообщений: 24
08.04.2014, 10:30  [ТС] 3
Ilot, Про структуру: лучше делать через string или массив символом, как делал я?
Про файл: мало что понял. Не имел еще дела никогда с файлами, если не сложно, можно поподробнее пожалуйста.
0
Эксперт по математике/физикеЭксперт С++
2049 / 1367 / 396
Регистрация: 16.05.2013
Сообщений: 3,508
Записей в блоге: 6
08.04.2014, 12:16 4
Щаз накидаю решение...

Добавлено через 1 час 14 минут
Что-то у меня с файлами не получается работать. Посмотрите как у вас будет...
Кликните здесь для просмотра всего текста
C++
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
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <iomanip>
#define BUF_SIZE 50
using std::cout;
using std::cin;
using std::endl;
using std::fstream;
using std::string;
using std::vector;
struct Request {
    char Surname[BUF_SIZE];
    char Destination[BUF_SIZE];
    char Date[BUF_SIZE];
    char FlightNumber[BUF_SIZE];
};
void OutputAll()
{
}
void getDeleteTicket()
{
}
//========================================================================//
//                      Точка входа                                       //
//========================================================================//
void GetAddTicket(Request&);
void Handler(vector<Request>&, int);
int Greeting();
int main()
{
    system("chcp 1251>0");
    fstream file;
    file.open("base.txt");
    if(!file) {
        std::cerr << "Error open file!" << endl;
        exit(1);
    }
 
    file.seekg(0, std::ios::end);
    size_t length = file.tellg() / sizeof(Request);
    vector<Request> base(length);
 
    vector<Request>::iterator baseIter = base.begin();
    while (!file.eof()) {
        file >> baseIter->Surname;
        file >> baseIter->Destination;
        file >> baseIter->Date;
        file >> baseIter->FlightNumber;
        ++baseIter;
    }
 
    cout.setf(std::ios::left);
 
    int action = Greeting();
    while(action != 5) {
        Handler(base, action);
        action = Greeting();
    }
 
    baseIter = base.begin();
    vector<Request>::iterator base_end = base.end();
    while (baseIter != base_end) {
        file << baseIter->Surname;
        file << baseIter->Destination;
        file << baseIter->Date;
        file << baseIter->FlightNumber;
        ++baseIter;
    }
    file.close();
 
    system("pause");
    return 0;
}
void Handler(vector<Request>& base, int number)
{
    Request temp;
    switch(number)
    {
        case 1:
            system("cls");
            char ch;
            do {
                GetAddTicket(temp);
                base.push_back(temp);
                cout << "Продолжить(д/н)? ";
                cin >> ch;
                system("cls");
            } while (ch == 'д');
            break;
        case 2:
            system("cls");
            getDeleteTicket();
            break;
        case 3:
            system("cls");
            system("pause");
            break;
        case 4:
            system("cls");
            vector<Request>::iterator baseIter = base.begin();
            vector<Request>::iterator base_end = base.end();
            cout << "Вывод всех заявок" << endl;
            while (baseIter != base_end) {
                cout << "-------------------------------------------------" << endl;
                cout << std::setw(20) << "Фамилия И.О: "      << baseIter->Surname      << endl;
                cout << std::setw(20) << "Пункт назначения: " << baseIter->Destination  << endl;
                cout << std::setw(20) << "Дата вылета: "      << baseIter->Date         << endl;
                cout << std::setw(20) << "Номер рейса: "      << baseIter->FlightNumber << endl;
                ++baseIter;
            }
            system("pause");
            break;
    }
}
int Greeting()
{
    system("cls");
    cout << "\tПрограмма учета заявок на авиабилеты: " << endl
              << "-------------------------------------------------" << endl
              << "1. Добавление заявок в список. " << endl
              << "2. Удаление заявок." << endl
              << "3. Вывод заявок по заданному номеру рейсу дате вылета. " << endl
              << "4. Вывод всех заявок. " << endl
              << "5. Выход. " << endl
              << "Выберите действие: ";
 
    int number;
    cin >> number;
    return number;
}
void GetAddTicket(Request& request) {
    cout << "Добавление заявки в список. Шаг 1/4" << endl
         << "-------------------------------------------------" << endl
         << "Введите Фамилию И.О. пассажира: ";
    cin >> request.Surname;
    system("cls");
    cout << "Добавление заявки в список. Шаг 2/4" << endl
         << "-------------------------------------------------" << endl
         << "Введите Пункт назначения: ";
    cin >> request.Destination;
    system("cls");
    cout << "Добавление заявки в список. Шаг 3/4" << endl
         << "-------------------------------------------------" << endl
         << "Введите желаемую дату вылета: ";
    cin >> request.Date;
    system("cls");
    cout << "Добавление заявки в список. Шаг 4/4" << endl
         << "-------------------------------------------------" << endl
         << "Введите номер рейса: ";
    cin >> request.FlightNumber;
    system("cls");
    cout << "Запись успешно добавленна!\n";
}
1
0 / 0 / 0
Регистрация: 10.02.2014
Сообщений: 24
08.04.2014, 13:05  [ТС] 5
Ilot, у меня вообще ошибка программы.
ошибка

[]http://s019.***********/i630/1404/08/62d56d8f0b99.png[/]
0
Эксперт по математике/физикеЭксперт С++
2049 / 1367 / 396
Регистрация: 16.05.2013
Сообщений: 3,508
Записей в блоге: 6
08.04.2014, 13:07 6
Ошибкаи набирать ручками. Я ничего не вижу
0
0 / 0 / 0
Регистрация: 10.02.2014
Сообщений: 24
08.04.2014, 13:14  [ТС] 7
Ilot,
Debug Assertion Failed!

Program: C:\WINDOWS\SYSTEM32\MSVCP110D.dll
File: c:\program files (x86)\microsoft visual studio 11.0\vc\include\vector
Line:72

Expression: vector iterator not dereferencable

For information oh how your program can cause an assertion failure, see the Visual c++ documentation on asserts.
0
Эксперт по математике/физикеЭксперт С++
2049 / 1367 / 396
Регистрация: 16.05.2013
Сообщений: 3,508
Записей в блоге: 6
08.04.2014, 13:19 8
Строчку указать можете где происходит ошибка?
0
0 / 0 / 0
Регистрация: 10.02.2014
Сообщений: 24
08.04.2014, 13:21  [ТС] 9
Ilot, Это не ошибка компиляции. Компилируется она без ошибок. А когда запускаешь выползает окно с ошибкой.
0
Эксперт по математике/физикеЭксперт С++
2049 / 1367 / 396
Регистрация: 16.05.2013
Сообщений: 3,508
Записей в блоге: 6
08.04.2014, 13:29 10
72-я строка у вас что?
Пока в ошибке говориться о невозможности разыменовать итератор. Непонятно откуда она берется...
0
0 / 0 / 0
Регистрация: 10.02.2014
Сообщений: 24
08.04.2014, 13:30  [ТС] 11
Ilot, Пустая строчка . Выше где Вы код скидывали. Там написаны номера строк. Я оттуда копировал.
0
Эксперт по математике/физикеЭксперт С++
2049 / 1367 / 396
Регистрация: 16.05.2013
Сообщений: 3,508
Записей в блоге: 6
08.04.2014, 13:36 12
По этому пути
File: c:\program files (x86)\microsoft visual studio 11.0\vc\include\vector
у вас лежит заголовочник vector. Что в этом файле на 72 строке?
1
0 / 0 / 0
Регистрация: 10.02.2014
Сообщений: 24
08.04.2014, 13:38  [ТС] 13
Ilot, _DEBUG_ERROR("vector iterator not dereferencable");
0
Эксперт по математике/физикеЭксперт С++
2049 / 1367 / 396
Регистрация: 16.05.2013
Сообщений: 3,508
Записей в блоге: 6
08.04.2014, 13:44 14
Вы прикалываетесь надо мной?
В какой функции этот макрос описан?
1
0 / 0 / 0
Регистрация: 10.02.2014
Сообщений: 24
08.04.2014, 13:47  [ТС] 15
Ilot, нет, не прикалываюсь. Вы попросили скинуть, то что было на 72 строке.
vector

C++
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
// vector standard header
#pragma once
#ifndef _VECTOR_
#define _VECTOR_
#ifndef RC_INVOKED
#include <xmemory>
#include <stdexcept>
 
 #pragma pack(push,_CRT_PACKING)
 #pragma warning(push,3)
 #pragma push_macro("new")
 #undef new
 
 #pragma warning(disable: 4127)
 #pragma warning(disable: 4244)
 
_STD_BEGIN
 #define _VECTOR_ORPHAN_RANGE   (_ITERATOR_DEBUG_LEVEL == 2)
 
        // TEMPLATE CLASS _Vector_const_iterator
template<class _Myvec>
    class _Vector_const_iterator
        : public _Iterator012<random_access_iterator_tag,
            typename _Myvec::value_type,
            typename _Myvec::difference_type,
            typename _Myvec::const_pointer,
            typename _Myvec::const_reference,
            _Iterator_base>
    {   // iterator for nonmutable vector
public:
    typedef _Vector_const_iterator<_Myvec> _Myiter;
    typedef random_access_iterator_tag iterator_category;
 
    typedef typename _Myvec::value_type value_type;
    typedef typename _Myvec::difference_type difference_type;
    typedef typename _Myvec::const_pointer pointer;
    typedef typename _Myvec::const_reference reference;
    typedef typename _Myvec::pointer _Tptr;
 
    _Vector_const_iterator()
        : _Ptr()
        {   // construct with null pointer
        }
 
    _Vector_const_iterator(_Tptr _Parg, const _Container_base *_Pvector)
        : _Ptr(_Parg)
        {   // construct with pointer _Parg
        this->_Adopt(_Pvector);
        }
 
    typedef pointer _Unchecked_type;
 
    _Myiter& _Rechecked(_Unchecked_type _Right)
        {   // reset from unchecked iterator
        this->_Ptr = (_Tptr)_Right;
        return (*this);
        }
 
    _Unchecked_type _Unchecked() const
        {   // make an unchecked iterator
        return (_Unchecked_type(this->_Ptr));
        }
 
    reference operator*() const
        {   // return designated object
 #if _ITERATOR_DEBUG_LEVEL == 2
        if (this->_Getcont() == 0
            || this->_Ptr == 0
            || this->_Ptr < ((_Myvec *)this->_Getcont())->_Myfirst
            || ((_Myvec *)this->_Getcont())->_Mylast <= this->_Ptr)
            {   // report error
            _DEBUG_ERROR("vector iterator not dereferencable");
            _SCL_SECURE_OUT_OF_RANGE;
            }
 
 #elif _ITERATOR_DEBUG_LEVEL == 1
        _SCL_SECURE_VALIDATE(this->_Getcont() != 0);
        _SCL_SECURE_VALIDATE_RANGE(
            this->_Ptr != _Tptr()
            && ((_Myvec *)this->_Getcont())->_Myfirst <= this->_Ptr
            && this->_Ptr < ((_Myvec *)this->_Getcont())->_Mylast);
 #endif /* _ITERATOR_DEBUG_LEVEL */
 
        _Analysis_assume_(this->_Ptr != _Tptr());
 
        return (*this->_Ptr);
        }
 
    pointer operator->() const
        {   // return pointer to class object
        return (_STD pointer_traits<pointer>::pointer_to(**this));
        }
 
    _Myiter& operator++()
        {   // preincrement
 #if _ITERATOR_DEBUG_LEVEL == 2
        if (this->_Getcont() == 0
            || this->_Ptr == 0
            || ((_Myvec *)this->_Getcont())->_Mylast <= this->_Ptr)
            {   // report error
            _DEBUG_ERROR("vector iterator not incrementable");
            _SCL_SECURE_OUT_OF_RANGE;
            }
 
 #elif _ITERATOR_DEBUG_LEVEL == 1
        _SCL_SECURE_VALIDATE(this->_Getcont() != 0);
        _SCL_SECURE_VALIDATE_RANGE(
            this->_Ptr != _Tptr()
            && this->_Ptr < ((_Myvec *)this->_Getcont())->_Mylast);
 #endif /* _ITERATOR_DEBUG_LEVEL */
 
        ++this->_Ptr;
        return (*this);
        }
 
    _Myiter operator++(int)
        {   // postincrement
        _Myiter _Tmp = *this;
        ++*this;
        return (_Tmp);
        }
 
    _Myiter& operator--()
        {   // predecrement
 #if _ITERATOR_DEBUG_LEVEL == 2
        if (this->_Getcont() == 0
            || this->_Ptr == 0
            || this->_Ptr <= ((_Myvec *)this->_Getcont())->_Myfirst)
            {   // report error
            _DEBUG_ERROR("vector iterator not decrementable");
            _SCL_SECURE_OUT_OF_RANGE;
            }
 
 #elif _ITERATOR_DEBUG_LEVEL == 1
        _SCL_SECURE_VALIDATE(this->_Getcont() != 0);
        _SCL_SECURE_VALIDATE_RANGE(
            this->_Ptr != _Tptr()
            && ((_Myvec *)this->_Getcont())->_Myfirst < this->_Ptr);
 #endif /* _ITERATOR_DEBUG_LEVEL */
 
        --this->_Ptr;
        return (*this);
        }
 
    _Myiter operator--(int)
        {   // postdecrement
        _Myiter _Tmp = *this;
        --*this;
        return (_Tmp);
        }
 
    _Myiter& operator+=(difference_type _Off)
        {   // increment by integer
 #if _ITERATOR_DEBUG_LEVEL == 2
        if (this->_Getcont() == 0
            || this->_Ptr + _Off < ((_Myvec *)this->_Getcont())->_Myfirst
            || ((_Myvec *)this->_Getcont())->_Mylast < this->_Ptr + _Off)
            {   // report error
            _DEBUG_ERROR("vector iterator + offset out of range");
            _SCL_SECURE_OUT_OF_RANGE;
            }
 
 #elif _ITERATOR_DEBUG_LEVEL == 1
        _SCL_SECURE_VALIDATE(this->_Getcont() != 0);
        _SCL_SECURE_VALIDATE_RANGE(
            ((_Myvec *)this->_Getcont())->_Myfirst <= this->_Ptr + _Off
            && this->_Ptr + _Off <= ((_Myvec *)this->_Getcont())->_Mylast);
 #endif /* _ITERATOR_DEBUG_LEVEL */
 
        _Ptr += _Off;
        return (*this);
        }
 
    _Myiter operator+(difference_type _Off) const
        {   // return this + integer
        _Myiter _Tmp = *this;
        return (_Tmp += _Off);
        }
 
    _Myiter& operator-=(difference_type _Off)
        {   // decrement by integer
        return (*this += -_Off);
        }
 
    _Myiter operator-(difference_type _Off) const
        {   // return this - integer
        _Myiter _Tmp = *this;
        return (_Tmp -= _Off);
        }
 
    difference_type operator-(const _Myiter& _Right) const
        {   // return difference of iterators
        _Compat(_Right);
        return (this->_Ptr - _Right._Ptr);
        }
 
    reference operator[](difference_type _Off) const
        {   // subscript
        return (*(*this + _Off));
        }
 
    bool operator==(const _Myiter& _Right) const
        {   // test for iterator equality
        _Compat(_Right);
        return (this->_Ptr == _Right._Ptr);
        }
 
    bool operator!=(const _Myiter& _Right) const
        {   // test for iterator inequality
        return (!(*this == _Right));
        }
 
    bool operator<(const _Myiter& _Right) const
        {   // test if this < _Right
        _Compat(_Right);
        return (this->_Ptr < _Right._Ptr);
        }
 
    bool operator>(const _Myiter& _Right) const
        {   // test if this > _Right
        return (_Right < *this);
        }
 
    bool operator<=(const _Myiter& _Right) const
        {   // test if this <= _Right
        return (!(_Right < *this));
        }
 
    bool operator>=(const _Myiter& _Right) const
        {   // test if this >= _Right
        return (!(*this < _Right));
        }
 
 #if _ITERATOR_DEBUG_LEVEL == 2
    void _Compat(const _Myiter& _Right) const
        {   // test for compatible iterator pair
        if (this->_Getcont() == 0
            || this->_Getcont() != _Right._Getcont())
            {   // report error
            _DEBUG_ERROR("vector iterators incompatible");
            _SCL_SECURE_INVALID_ARGUMENT;
            }
        }
 
 #elif _ITERATOR_DEBUG_LEVEL == 1
    void _Compat(const _Myiter& _Right) const
        {   // test for compatible iterator pair
        _SCL_SECURE_VALIDATE(this->_Getcont() != 0);
        _SCL_SECURE_VALIDATE_RANGE(this->_Getcont() == _Right._Getcont());
        }
 
 #else /* _ITERATOR_DEBUG_LEVEL == 0 */
    void _Compat(const _Myiter&) const
        {   // test for compatible iterator pair
        }
 #endif /* _ITERATOR_DEBUG_LEVEL */
 
    _Tptr _Ptr; // pointer to element in vector
    };
 
template<class _Myvec> inline
    typename _Vector_const_iterator<_Myvec>::_Unchecked_type
        _Unchecked(_Vector_const_iterator<_Myvec> _Iter)
    {   // convert to unchecked
    return (_Iter._Unchecked());
    }
 
template<class _Myvec> inline
    _Vector_const_iterator<_Myvec>&
        _Rechecked(_Vector_const_iterator<_Myvec>& _Iter,
            typename _Vector_const_iterator<_Myvec>
                ::_Unchecked_type _Right)
    {   // convert to checked
    return (_Iter._Rechecked(_Right));
    }
 
template<class _Myvec> inline
    _Vector_const_iterator<_Myvec> operator+(
        typename _Vector_const_iterator<_Myvec>::difference_type _Off,
        _Vector_const_iterator<_Myvec> _Next)
    {   // add offset to iterator
    return (_Next += _Off);
    }
 
        // TEMPLATE CLASS _Vector_iterator
template<class _Myvec>
    class _Vector_iterator
        : public _Vector_const_iterator<_Myvec>
    {   // iterator for mutable vector
public:
    typedef _Vector_iterator<_Myvec> _Myiter;
    typedef _Vector_const_iterator<_Myvec> _Mybase;
    typedef random_access_iterator_tag iterator_category;
 
    typedef typename _Myvec::value_type value_type;
    typedef typename _Myvec::difference_type difference_type;
    typedef typename _Myvec::pointer pointer;
    typedef typename _Myvec::reference reference;
 
    _Vector_iterator()
        {   // construct with null vector pointer
        }
 
    _Vector_iterator(pointer _Parg, const _Container_base *_Pvector)
        : _Mybase(_Parg, _Pvector)
        {   // construct with pointer _Parg
        }
 
    typedef pointer _Unchecked_type;
 
    _Myiter& _Rechecked(_Unchecked_type _Right)
        {   // reset from unchecked iterator
        this->_Ptr = _Right;
        return (*this);
        }
 
    _Unchecked_type _Unchecked() const
        {   // make an unchecked iterator
        return (_Unchecked_type(this->_Ptr));
        }
 
    reference operator*() const
        {   // return designated object
        return ((reference)**(_Mybase *)this);
        }
 
    pointer operator->() const
        {   // return pointer to class object
        return (_STD pointer_traits<pointer>::pointer_to(**this));
        }
 
    _Myiter& operator++()
        {   // preincrement
        ++*(_Mybase *)this;
        return (*this);
        }
 
    _Myiter operator++(int)
        {   // postincrement
        _Myiter _Tmp = *this;
        ++*this;
        return (_Tmp);
        }
 
    _Myiter& operator--()
        {   // predecrement
        --*(_Mybase *)this;
        return (*this);
        }
 
    _Myiter operator--(int)
        {   // postdecrement
        _Myiter _Tmp = *this;
        --*this;
        return (_Tmp);
        }
 
    _Myiter& operator+=(difference_type _Off)
        {   // increment by integer
        *(_Mybase *)this += _Off;
        return (*this);
        }
 
    _Myiter operator+(difference_type _Off) const
        {   // return this + integer
        _Myiter _Tmp = *this;
        return (_Tmp += _Off);
        }
 
    _Myiter& operator-=(difference_type _Off)
        {   // decrement by integer
        return (*this += -_Off);
        }
 
    _Myiter operator-(difference_type _Off) const
        {   // return this - integer
        _Myiter _Tmp = *this;
        return (_Tmp -= _Off);
        }
 
    difference_type operator-(const _Mybase& _Right) const
        {   // return difference of iterators
        return (*(_Mybase *)this - _Right);
        }
 
    reference operator[](difference_type _Off) const
        {   // subscript
        return (*(*this + _Off));
        }
    };
 
template<class _Myvec> inline
    typename _Vector_iterator<_Myvec>::_Unchecked_type
        _Unchecked(_Vector_iterator<_Myvec> _Iter)
    {   // convert to unchecked
    return (_Iter._Unchecked());
    }
 
template<class _Myvec> inline
    _Vector_iterator<_Myvec>&
        _Rechecked(_Vector_iterator<_Myvec>& _Iter,
            typename _Vector_iterator<_Myvec>
                ::_Unchecked_type _Right)
    {   // convert to checked
    return (_Iter._Rechecked(_Right));
    }
 
template<class _Myvec> inline
    _Vector_iterator<_Myvec> operator+(
        typename _Vector_iterator<_Myvec>::difference_type _Off,
        _Vector_iterator<_Myvec> _Next)
    {   // add offset to iterator
    return (_Next += _Off);
    }
 
        // vector TYPE WRAPPERS
template<class _Value_type,
    class _Size_type,
    class _Difference_type,
    class _Pointer,
    class _Const_pointer,
    class _Reference,
    class _Const_reference>
    struct _Vec_iter_types
    {   // wraps types needed by iterators
    typedef _Value_type value_type;
    typedef _Size_type size_type;
    typedef _Difference_type difference_type;
    typedef _Pointer pointer;
    typedef _Const_pointer const_pointer;
    typedef _Reference reference;
    typedef _Const_reference const_reference;
    };
 
template<class _Ty,
    class _Alloc0>
    struct _Vec_base_types
    {   // types needed for a container base
    typedef _Alloc0 _Alloc;
    typedef _Vec_base_types<_Ty, _Alloc> _Myt;
 
 #if _HAS_CPP0X
    typedef _Wrap_alloc<_Alloc> _Alty0;
    typedef typename _Alty0::template rebind<_Ty>::other _Alty;
 
 #else /* _HAS_CPP0X */
    typedef typename _Alloc::template rebind<_Ty>::other _Alty;
 #endif /* _HAS_CPP0X */
 
    typedef typename _Alty::pointer _Tptr;
    typedef typename _Alty::template rebind<_Tptr>::other _Alpty;
 
    typedef typename _If<_Is_simple_alloc<_Alty>::value,
        _Simple_types<typename _Alty::value_type>,
        _Vec_iter_types<typename _Alty::value_type,
            typename _Alty::size_type,
            typename _Alty::difference_type,
            typename _Alty::pointer,
            typename _Alty::const_pointer,
            typename _Alty::reference,
            typename _Alty::const_reference> >::type
        _Val_types;
    };
 
        // TEMPLATE CLASS _Vector_val
template<class _Val_types>
    class _Vector_val
        : public _Container_base
    {   // base class for vector to hold data
public:
    typedef _Vector_val<_Val_types> _Myt;
 
    typedef typename _Val_types::value_type value_type;
    typedef typename _Val_types::size_type size_type;
    typedef typename _Val_types::difference_type difference_type;
    typedef typename _Val_types::pointer pointer;
    typedef typename _Val_types::const_pointer const_pointer;
    typedef typename _Val_types::reference reference;
    typedef typename _Val_types::const_reference const_reference;
 
    typedef _Vector_iterator<_Myt> iterator;
    typedef _Vector_const_iterator<_Myt> const_iterator;
 
    _Vector_val()
        {   // initialize values
        _Myfirst = pointer();
        _Mylast = pointer();
        _Myend = pointer();
        }
 
    pointer _Myfirst;   // pointer to beginning of array
    pointer _Mylast;    // pointer to current end of sequence
    pointer _Myend; // pointer to end of array
    };
 
        // TEMPLATE CLASS _Vector_alloc
template<bool _Al_has_storage,
    class _Alloc_types>
    class _Vector_alloc
        : public _Vector_val<typename _Alloc_types::_Val_types>
    {   // base class for vector to hold allocator with storage
public:
    typedef _Vector_alloc<_Al_has_storage, _Alloc_types> _Myt;
    typedef typename _Alloc_types::_Alloc _Alloc;
 
    typedef typename _Alloc_types::_Alty _Alty;
 
 #if _ITERATOR_DEBUG_LEVEL == 0
    _Vector_alloc(const _Alloc& _Al = _Alloc())
        : _Alval(_Al)
        {   // construct allocator from _Al
        }
 
    void _Change_alloc(const _Alty& _Al)
        {   // replace old allocator
        _Alval = _Al;
        }
 
    void _Swap_alloc(_Myt& _Right)
        {   // swap allocators
        _Swap_adl(this->_Alval, _Right._Alval);
        }
 
 #else /* _ITERATOR_DEBUG_LEVEL == 0 */
    _Vector_alloc(const _Alty& _Al = _Alty())
        : _Alval(_Al)
        {   // construct allocator from _Al
        _Alloc_proxy();
        }
 
    ~_Vector_alloc() _NOEXCEPT
        {   // destroy proxy
        _Free_proxy();
        }
 
    void _Change_alloc(const _Alty& _Al)
        {   // replace old allocator
        _Free_proxy();
        _Alval = _Al;
        _Alloc_proxy();
        }
 
    void _Swap_alloc(_Myt& _Right)
        {   // swap allocators
        _Swap_adl(_Alval, _Right._Alval);
        _Swap_adl(this->_Myproxy, _Right._Myproxy);
        }
 
    void _Alloc_proxy()
        {   // construct proxy from _Alval
        typename _Alloc::template rebind<_Container_proxy>::other
            _Alproxy(_Alval);
        this->_Myproxy = _Alproxy.allocate(1);
        _Alproxy.construct(this->_Myproxy, _Container_proxy());
        this->_Myproxy->_Mycont = this;
        }
 
    void _Free_proxy()
        {   // destroy proxy
        typename _Alloc::template rebind<_Container_proxy>::other
            _Alproxy(_Alval);
        this->_Orphan_all();
        _Alproxy.destroy(this->_Myproxy);
        _Alproxy.deallocate(this->_Myproxy, 1);
        this->_Myproxy = 0;
        }
 #endif /* _ITERATOR_DEBUG_LEVEL == 0 */
 
    _Alty& _Getal()
        {   // get reference to allocator
        return (_Alval);
        }
 
    const _Alty& _Getal() const
        {   // get reference to allocator
        return (_Alval);
        }
 
    _Alty _Alval;   // allocator object for values
    };
 
template<class _Alloc_types>
    class _Vector_alloc<false, _Alloc_types>
        : public _Vector_val<typename _Alloc_types::_Val_types>
    {   // base class for vector to hold allocator with no storage
public:
    typedef _Vector_alloc<false, _Alloc_types> _Myt;
    typedef typename _Alloc_types::_Alloc _Alloc;
 
    typedef typename _Alloc_types::_Alty _Alty;
 
 #if _ITERATOR_DEBUG_LEVEL == 0
    _Vector_alloc(const _Alloc& = _Alloc())
        {   // construct allocator from _Al
        }
 
    void _Change_alloc(const _Alty&)
        {   // replace old allocator
        }
 
    void _Swap_alloc(_Myt&)
        {   // swap allocators
        }
 
 #else /* _ITERATOR_DEBUG_LEVEL == 0 */
    _Vector_alloc(const _Alloc& = _Alloc())
        {   // construct allocator from _Al
        _Alloc_proxy();
        }
 
    ~_Vector_alloc() _NOEXCEPT
        {   // destroy proxy
        _Free_proxy();
        }
 
    void _Change_alloc(const _Alty&)
        {   // replace old allocator
        }
 
    void _Swap_alloc(_Myt& _Right)
        {   // swap allocators
        _Swap_adl(this->_Myproxy, _Right._Myproxy);
        }
 
    void _Alloc_proxy()
        {   // construct proxy from _Alval
        typename _Alloc::template rebind<_Container_proxy>::other
            _Alproxy;
        this->_Myproxy = _Alproxy.allocate(1);
        _Alproxy.construct(this->_Myproxy, _Container_proxy());
        this->_Myproxy->_Mycont = this;
        }
 
    void _Free_proxy()
        {   // destroy proxy
        typename _Alloc::template rebind<_Container_proxy>::other
            _Alproxy;
        this->_Orphan_all();
        _Alproxy.destroy(this->_Myproxy);
        _Alproxy.deallocate(this->_Myproxy, 1);
        this->_Myproxy = 0;
        }
 #endif /* _ITERATOR_DEBUG_LEVEL == 0 */
 
    _Alty _Getal() const
        {   // get reference to allocator
        return (_Alty());
        }
    };
 
        // TEMPLATE CLASS vector
template<class _Ty,
    class _Alloc = allocator<_Ty> >
    class vector
        : public _Vector_alloc<!is_empty<_Alloc>::value,
            _Vec_base_types<_Ty, _Alloc> >
    {   // varying size array of values
public:
    typedef vector<_Ty, _Alloc> _Myt;
    typedef _Vector_alloc<!is_empty<_Alloc>::value,
        _Vec_base_types<_Ty, _Alloc> > _Mybase;
    typedef _Alloc allocator_type;
 
    typedef typename _Mybase::_Alty _Alty;
 
    typedef typename _Mybase::value_type value_type;
    typedef typename _Mybase::size_type size_type;
    typedef typename _Mybase::difference_type difference_type;
    typedef typename _Mybase::pointer pointer;
    typedef typename _Mybase::const_pointer const_pointer;
    typedef typename _Mybase::reference reference;
    typedef typename _Mybase::const_reference const_reference;
 
 #define _VICONT(it)    it._Getcont()
 #define _VIPTR(it) (it)._Ptr
 
    typedef typename _Mybase::iterator iterator;
    typedef typename _Mybase::const_iterator const_iterator;
 
    typedef _STD reverse_iterator<iterator> reverse_iterator;
    typedef _STD reverse_iterator<const_iterator> const_reverse_iterator;
 
    vector()
        : _Mybase()
        {   // construct empty vector
        }
 
    explicit vector(const _Alloc& _Al)
        : _Mybase(_Al)
        {   // construct empty vector, allocator
        }
 
    explicit vector(size_type _Count)
        : _Mybase()
        {   // construct from _Count * value_type()
        resize(_Count);
        }
 
    vector(size_type _Count, const value_type& _Val)
        : _Mybase()
        {   // construct from _Count * _Val
        _Construct_n(_Count, _STD addressof(_Val));
        }
 
    vector(size_type _Count, const value_type& _Val, const _Alloc& _Al)
        : _Mybase(_Al)
        {   // construct from _Count * _Val, allocator
        _Construct_n(_Count, _STD addressof(_Val));
        }
 
    vector(const _Myt& _Right)
 
 #if _HAS_CPP0X
        : _Mybase(_Right._Getal().select_on_container_copy_construction())
 
 #else /* _HAS_CPP0X */
        : _Mybase(_Right._Getal())
 #endif /* _HAS_CPP0X */
 
        {   // construct by copying _Right
        if (_Buy(_Right.size()))
            _TRY_BEGIN
            this->_Mylast = _Ucopy(_Right.begin(), _Right.end(),
                this->_Myfirst);
            _CATCH_ALL
            _Tidy();
            _RERAISE;
            _CATCH_END
        }
 
    vector(const _Myt& _Right, const _Alloc& _Al)
        : _Mybase(_Al)
        {   // construct by copying _Right, allocator
        if (_Buy(_Right.size()))
            _TRY_BEGIN
            this->_Mylast = _Ucopy(_Right.begin(), _Right.end(),
                this->_Myfirst);
            _CATCH_ALL
            _Tidy();
            _RERAISE;
            _CATCH_END
        }
 
    template<class _Iter>
        vector(_Iter _First, _Iter _Last,
            typename enable_if<_Is_iterator<_Iter>::value,
                void>:: type ** = 0)
        : _Mybase()
        {   // construct from [_First, _Last)
        _Construct(_First, _Last);
        }
 
    template<class _Iter>
        vector(_Iter _First, _Iter _Last, const _Alloc& _Al,
            typename enable_if<_Is_iterator<_Iter>::value,
                void>:: type ** = 0)
        : _Mybase(_Al)
        {   // construct from [_First, _Last) with allocator
        _Construct(_First, _Last);
        }
 
    template<class _Iter>
        void _Construct(_Iter _First, _Iter _Last)
        {   // initialize with [_First, _Last), input iterators
        _TRY_BEGIN
        insert(begin(), _First, _Last);
        _CATCH_ALL
        _Tidy();
        _RERAISE;
        _CATCH_END
        }
 
    void _Construct_n(size_type _Count, const value_type *_Pval)
        {   // construct from _Count * *_Pval
        if (_Buy(_Count))
            {   // nonzero, fill it
            _TRY_BEGIN
            this->_Mylast = _Ufill(this->_Myfirst, _Count, _Pval);
            _CATCH_ALL
            _Tidy();
            _RERAISE;
            _CATCH_END
            }
        }
 
    vector(_Myt&& _Right)
        : _Mybase(_Right._Getal())
        {   // construct by moving _Right
        _Assign_rv(_STD forward<_Myt>(_Right));
        }
 
    vector(_Myt&& _Right, const _Alloc& _Al)
        : _Mybase(_Al)
        {   // construct by moving _Right, allocator
        if (this->_Getal() != _Right._Getal())
            assign(_STD make_move_iterator(_Right.begin()),
                _STD make_move_iterator(_Right.end()));
        else
            _Assign_rv(_STD forward<_Myt>(_Right));
        }
 
    _Myt& operator=(_Myt&& _Right)
        {   // assign by moving _Right
        if (this != &_Right)
            {   // different, assign it
            _Tidy();
 
 #if _HAS_CPP0X
            if (this->_Getal() != _Right._Getal()
                && _Alty::propagate_on_container_move_assignment::value)
                this->_Change_alloc(_Right._Getal());
 #endif /* _HAS_CPP0X */
 
            if (this->_Getal() != _Right._Getal())
                assign(_STD make_move_iterator(_Right.begin()),
                    _STD make_move_iterator(_Right.end()));
            else
                _Assign_rv(_STD forward<_Myt>(_Right));
            }
        return (*this);
        }
 
    void _Assign_rv(_Myt&& _Right)
        {   // assign by moving _Right
        this->_Swap_all((_Myt&)_Right);
        this->_Myfirst = _Right._Myfirst;
        this->_Mylast = _Right._Mylast;
        this->_Myend = _Right._Myend;
 
        _Right._Myfirst = pointer();
        _Right._Mylast = pointer();
        _Right._Myend = pointer();
        }
 
    void push_back(value_type&& _Val)
        {   // insert by moving into element at end
        if (_Inside(_STD addressof(_Val)))
            {   // push back an element
            size_type _Idx = _STD addressof(_Val) - this->_Myfirst;
            if (this->_Mylast == this->_Myend)
                _Reserve(1);
            _Orphan_range(this->_Mylast, this->_Mylast);
            this->_Getal().construct(this->_Mylast,
                _STD forward<value_type>(this->_Myfirst[_Idx]));
            ++this->_Mylast;
            }
        else
            {   // push back a non-element
            if (this->_Mylast == this->_Myend)
                _Reserve(1);
            _Orphan_range(this->_Mylast, this->_Mylast);
            this->_Getal().construct(this->_Mylast,
                _STD forward<value_type>(_Val));
            ++this->_Mylast;
            }
        }
 
    iterator insert(const_iterator _Where, _Ty&& _Val)
        {   // insert by moving _Val at _Where
        return (emplace(_Where, _STD move(_Val)));
        }
 
#define _VECTOR_EMPLACE( \
    TEMPLATE_LIST, PADDING_LIST, LIST, COMMA, X1, X2, X3, X4) \
    TEMPLATE_LIST(_CLASS_TYPE) \
        void emplace_back(LIST(_TYPE_REFREF_ARG)) \
        {   /* insert by moving into element at end */ \
        if (this->_Mylast == this->_Myend) \
            _Reserve(1); \
        _Orphan_range(this->_Mylast, this->_Mylast); \
        this->_Getal().construct(this->_Mylast COMMA LIST(_FORWARD_ARG)); \
        ++this->_Mylast; \
        } \
    TEMPLATE_LIST(_CLASS_TYPE) \
        iterator emplace(const_iterator _Where \
            COMMA LIST(_TYPE_REFREF_ARG)) \
        {   /* insert by moving _Val at _Where */ \
        size_type _Off = _VIPTR(_Where) - this->_Myfirst; \
        _VECTOR_EMPLACE_CHECK \
        emplace_back(LIST(_FORWARD_ARG)); \
        _STD rotate(begin() + _Off, end() - 1, end()); \
        return (begin() + _Off); \
        }
 
 #if _ITERATOR_DEBUG_LEVEL == 2
#define _VECTOR_EMPLACE_CHECK \
        if (size() < _Off) \
            _DEBUG_ERROR("vector emplace iterator outside range");
 
 #else /* _ITERATOR_DEBUG_LEVEL == 2 */
#define _VECTOR_EMPLACE_CHECK
 #endif /* _ITERATOR_DEBUG_LEVEL == 2 */
 
_VARIADIC_EXPAND_0X(_VECTOR_EMPLACE, , , , )
#undef _VECTOR_EMPLACE_CHECK
#undef _VECTOR_EMPLACE
 
    ~vector() _NOEXCEPT
        {   // destroy the object
        _Tidy();
        }
 
    _Myt& operator=(const _Myt& _Right)
        {   // assign _Right
        if (this != &_Right)
            {   // different, assign it
 #if _HAS_CPP0X
            if (this->_Getal() != _Right._Getal()
                && _Alty::propagate_on_container_copy_assignment::value)
                {   // change allocator before copying
                _Tidy();
                this->_Change_alloc(_Right._Getal());
                }
 #endif /* _HAS_CPP0X */
 
            this->_Orphan_all();
 
            if (_Right.empty())
                clear();    // new sequence empty, erase existing sequence
            else if (_Right.size() <= size())
                {   // enough elements, copy new and destroy old
                pointer _Ptr = _Copy_impl(_Right._Myfirst,
                    _Right._Mylast, this->_Myfirst);    // copy new
                _Destroy(_Ptr, this->_Mylast);  // destroy old
                this->_Mylast = this->_Myfirst + _Right.size();
                }
            else if (_Right.size() <= capacity())
                {   // enough room, copy and construct new
                pointer _Ptr = _Right._Myfirst + size();
                _Copy_impl(_Right._Myfirst,
                    _Ptr, this->_Myfirst);
                this->_Mylast = _Ucopy(_Ptr, _Right._Mylast, this->_Mylast);
                }
            else
                {   // not enough room, allocate new array and construct new
                if (this->_Myfirst != pointer())
                    {   // discard old array
                    _Destroy(this->_Myfirst, this->_Mylast);
                    this->_Getal().deallocate(this->_Myfirst,
                        this->_Myend - this->_Myfirst);
                    }
                if (_Buy(_Right.size()))
                    _TRY_BEGIN
                    this->_Mylast = _Ucopy(_Right._Myfirst, _Right._Mylast,
                        this->_Myfirst);
                    _CATCH_ALL
                    _Tidy();
                    _RERAISE;
                    _CATCH_END
                }
            }
        return (*this);
        }
 
    void reserve(size_type _Count)
        {   // determine new minimum length of allocated storage
        if (capacity() < _Count)
            {   // something to do, check and reallocate
            if (max_size() < _Count)
                _Xlen();
            _Reallocate(_Count);
            }
        }
 
    size_type capacity() const _NOEXCEPT
        {   // return current length of allocated storage
        return (this->_Myend - this->_Myfirst);
        }
 
    size_type _Unused_capacity() const _NOEXCEPT
        {   // micro-optimization for capacity() - size()
        return (this->_Myend - this->_Mylast);
        }
 
    size_type _Has_unused_capacity() const _NOEXCEPT
        {   // micro-optimization for capacity() != size()
        return (this->_Myend != this->_Mylast);
        }
 
    iterator begin() _NOEXCEPT
        {   // return iterator for beginning of mutable sequence
        return (iterator(this->_Myfirst, this));
        }
 
    const_iterator begin() const _NOEXCEPT
        {   // return iterator for beginning of nonmutable sequence
        return (const_iterator(this->_Myfirst, this));
        }
 
    iterator end() _NOEXCEPT
        {   // return iterator for end of mutable sequence
        return (iterator(this->_Mylast, this));
        }
 
    const_iterator end() const _NOEXCEPT
        {   // return iterator for end of nonmutable sequence
        return (const_iterator(this->_Mylast, this));
        }
 
    iterator _Make_iter(const_iterator _Where) const
        {   // make iterator from const_iterator
        return (iterator(_Where._Ptr, this));
        }
 
    reverse_iterator rbegin() _NOEXCEPT
        {   // return iterator for beginning of reversed mutable sequence
        return (reverse_iterator(end()));
        }
 
    const_reverse_iterator rbegin() const _NOEXCEPT
        {   // return iterator for beginning of reversed nonmutable sequence
        return (const_reverse_iterator(end()));
        }
 
    reverse_iterator rend() _NOEXCEPT
        {   // return iterator for end of reversed mutable sequence
        return (reverse_iterator(begin()));
        }
 
    const_reverse_iterator rend() const _NOEXCEPT
        {   // return iterator for end of reversed nonmutable sequence
        return (const_reverse_iterator(begin()));
        }
 
 #if _HAS_CPP0X
    const_iterator cbegin() const _NOEXCEPT
        {   // return iterator for beginning of nonmutable sequence
        return (((const _Myt *)this)->begin());
        }
 
    const_iterator cend() const _NOEXCEPT
        {   // return iterator for end of nonmutable sequence
        return (((const _Myt *)this)->end());
        }
 
    const_reverse_iterator crbegin() const _NOEXCEPT
        {   // return iterator for beginning of reversed nonmutable sequence
        return (((const _Myt *)this)->rbegin());
        }
 
    const_reverse_iterator crend() const _NOEXCEPT
        {   // return iterator for end of reversed nonmutable sequence
        return (((const _Myt *)this)->rend());
        }
 
    void shrink_to_fit()
        {   // reduce capacity
        if (_Has_unused_capacity())
            {   // worth shrinking, do it
            if (empty())
                _Tidy();
            else
                _Reallocate(size());
            }
        }
 #endif /* _HAS_CPP0X */
 
    void resize(size_type _Newsize)
        {   // determine new length, padding as needed
        if (_Newsize < size())
            erase(begin() + _Newsize, end());
        else if (size() < _Newsize)
            {   // pad as needed
            _Alty _Alval(this->_Getal());
            _Reserve(_Newsize - size());
            _TRY_BEGIN
            _Uninitialized_default_fill_n(this->_Mylast, _Newsize - size(),
                _Alval);
            _CATCH_ALL
            _Tidy();
            _RERAISE;
            _CATCH_END
            this->_Mylast += _Newsize - size();
            }
        }
 
    void resize(size_type _Newsize, const value_type& _Val)
        {   // determine new length, padding with _Val elements as needed
        if (_Newsize < size())
            erase(begin() + _Newsize, end());
        else if (size() < _Newsize)
            _Insert_n(end(), _Newsize - size(), _Val);
        }
 
    size_type size() const _NOEXCEPT
        {   // return length of sequence
        return (this->_Mylast - this->_Myfirst);
        }
 
    size_type max_size() const _NOEXCEPT
        {   // return maximum possible length of sequence
        return (this->_Getal().max_size());
        }
 
    bool empty() const _NOEXCEPT
        {   // test if sequence is empty
        return (this->_Myfirst == this->_Mylast);
        }
 
    _Alloc get_allocator() const _NOEXCEPT
        {   // return allocator object for values
        return (this->_Getal());
        }
 
    const_reference at(size_type _Pos) const
        {   // subscript nonmutable sequence with checking
        if (size() <= _Pos)
            _Xran();
        return (*(this->_Myfirst + _Pos));
        }
 
    reference at(size_type _Pos)
        {   // subscript mutable sequence with checking
        if (size() <= _Pos)
            _Xran();
        return (*(this->_Myfirst + _Pos));
        }
 
    const_reference operator[](size_type _Pos) const
        {   // subscript nonmutable sequence
 #if _ITERATOR_DEBUG_LEVEL == 2
        if (size() <= _Pos)
            {   // report error
            _DEBUG_ERROR("vector subscript out of range");
            _SCL_SECURE_OUT_OF_RANGE;
            }
 
 #elif _ITERATOR_DEBUG_LEVEL == 1
        _SCL_SECURE_VALIDATE_RANGE(_Pos < size());
 #endif /* _ITERATOR_DEBUG_LEVEL */
 
        return (*(this->_Myfirst + _Pos));
        }
 
    reference operator[](size_type _Pos)
        {   // subscript mutable sequence
 #if _ITERATOR_DEBUG_LEVEL == 2
        if (size() <= _Pos)
            {   // report error
            _DEBUG_ERROR("vector subscript out of range");
            _SCL_SECURE_OUT_OF_RANGE;
            }
 
 #elif _ITERATOR_DEBUG_LEVEL == 1
        _SCL_SECURE_VALIDATE_RANGE(_Pos < size());
 #endif /* _ITERATOR_DEBUG_LEVEL */
 
        return (*(this->_Myfirst + _Pos));
        }
 
 #if _HAS_CPP0X
    pointer data() _NOEXCEPT
        {   // return address of first element
        return (this->_Myfirst);
        }
 
    const_pointer data() const _NOEXCEPT
        {   // return address of first element
        return (this->_Myfirst);
        }
 #endif /* _HAS_CPP0X */
 
    reference front()
        {   // return first element of mutable sequence
        return (*begin());
        }
 
    const_reference front() const
        {   // return first element of nonmutable sequence
        return (*begin());
        }
 
    reference back()
        {   // return last element of mutable sequence
        return (*(end() - 1));
        }
 
    const_reference back() const
        {   // return last element of nonmutable sequence
        return (*(end() - 1));
        }
 
    void push_back(const value_type& _Val)
        {   // insert element at end
        if (_Inside(_STD addressof(_Val)))
            {   // push back an element
            size_type _Idx = _STD addressof(_Val) - this->_Myfirst;
            if (this->_Mylast == this->_Myend)
                _Reserve(1);
            _Orphan_range(this->_Mylast, this->_Mylast);
            this->_Getal().construct(this->_Mylast,
                this->_Myfirst[_Idx]);
            ++this->_Mylast;
            }
        else
            {   // push back a non-element
            if (this->_Mylast == this->_Myend)
                _Reserve(1);
            _Orphan_range(this->_Mylast, this->_Mylast);
            this->_Getal().construct(this->_Mylast,
                _Val);
            ++this->_Mylast;
            }
        }
 
 #if _ITERATOR_DEBUG_LEVEL == 2
    void pop_back()
        {   // erase element at end
        if (empty())
            _DEBUG_ERROR("vector empty before pop");
        else
            {   // erase last element
            _Orphan_range(this->_Mylast - 1, this->_Mylast);
            this->_Getal().destroy(this->_Mylast - 1);
            --this->_Mylast;
            }
        }
 
 #else /* _ITERATOR_DEBUG_LEVEL == 2 */
    void pop_back()
        {   // erase element at end
        if (!empty())
            {   // erase last element
            this->_Getal().destroy(this->_Mylast - 1);
            --this->_Mylast;
            }
        }
 #endif /* _ITERATOR_DEBUG_LEVEL == 2 */
 
    template<class _Iter>
        typename enable_if<_Is_iterator<_Iter>::value,
            void>::type
        assign(_Iter _First, _Iter _Last)
        {   // assign [_First, _Last), input iterators
        erase(begin(), end());
        insert(begin(), _First, _Last);
        }
 
    void assign(size_type _Count, const value_type& _Val)
        {   // assign _Count * _Val
        _Assign_n(_Count, _Val);
        }
 
    iterator insert(const_iterator _Where, const _Ty& _Val)
        {   // insert _Val at _Where
        return (_Insert_n(_Where, (size_type)1, _Val));
        }
 
    iterator insert(const_iterator _Where, size_type _Count,
        const _Ty& _Val)
        {   // insert _Count * _Val at _Where
        return (_Insert_n(_Where, _Count, _Val));
        }
 
    template<class _Iter>
        typename enable_if<_Is_iterator<_Iter>::value,
            iterator>::type
        insert(const_iterator _Where, _Iter _First, _Iter _Last)
        {   // insert [_First, _Last) at _Where
        size_type _Off = _VIPTR(_Where) - this->_Myfirst;
        _Insert(_Where, _First, _Last, _Iter_cat(_First));
        return (begin() + _Off);
        }
 
    template<class _Iter>
        void _Insert(const_iterator _Where, _Iter _First, _Iter _Last,
            input_iterator_tag)
        {   // insert [_First, _Last) at _Where, input iterators
        size_type _Off = _VIPTR(_Where) - this->_Myfirst;
 
 #if _ITERATOR_DEBUG_LEVEL == 2
        if (size() < _Off)
            _DEBUG_ERROR("vector insert iterator outside range");
 #endif /* _ITERATOR_DEBUG_LEVEL == 2 */
 
        if (_First != _Last)
            {   // worth doing, gather at end and rotate into place
            size_type _Oldsize = size();
 
            _TRY_BEGIN
            for (; _First != _Last; ++_First)
                push_back(*_First); // append
 
            _CATCH_ALL
            erase(begin() + _Oldsize, end());
            _RERAISE;
            _CATCH_END
 
            _STD rotate(begin() + _Off, begin() + _Oldsize, end());
            }
        }
 
    template<class _Iter>
        void _Insert(const_iterator _Where, _Iter _First, _Iter _Last,
            forward_iterator_tag)
        {   // insert [_First, _Last) at _Where, forward iterators
 #if _ITERATOR_DEBUG_LEVEL == 2
        if (_VICONT(_Where) != this
            || _VIPTR(_Where) < this->_Myfirst
            || this->_Mylast < _VIPTR(_Where))
            _DEBUG_ERROR("vector insert iterator outside range");
        _DEBUG_RANGE(_First, _Last);
 #endif /* _ITERATOR_DEBUG_LEVEL == 2 */
 
        size_type _Count = 0;
        _Distance(_First, _Last, _Count);
 
        if (_Count == 0)
            ;
        else if (_Unused_capacity() < _Count)
            {   // not enough room, reallocate
            if (max_size() - size() < _Count)
                _Xlen();    // result too long
 
            size_type _Capacity = _Grow_to(size() + _Count);
            pointer _Newvec = this->_Getal().allocate(_Capacity);
            pointer _Ptr = _Newvec;
 
            _TRY_BEGIN
            _Ptr = _Umove(this->_Myfirst, _VIPTR(_Where),
                _Newvec);   // copy prefix
            _Ptr = _Ucopy(_First, _Last, _Ptr); // add new stuff
            _Umove(_VIPTR(_Where), this->_Mylast,
                _Ptr);  // copy suffix
            _CATCH_ALL
            _Destroy(_Newvec, _Ptr);
            this->_Getal().deallocate(_Newvec, _Capacity);
            _RERAISE;
            _CATCH_END
 
            _Count += size();
            if (this->_Myfirst != pointer())
                {   // destroy and deallocate old array
                _Destroy(this->_Myfirst, this->_Mylast);
                this->_Getal().deallocate(this->_Myfirst,
                    this->_Myend - this->_Myfirst);
                }
 
            this->_Orphan_all();
            this->_Myend = _Newvec + _Capacity;
            this->_Mylast = _Newvec + _Count;
            this->_Myfirst = _Newvec;
            }
        else
            {   // new stuff fits, append and rotate into place
            _Ucopy(_First, _Last, this->_Mylast);
            _STD rotate(_VIPTR(_Where), this->_Mylast,
                this->_Mylast + _Count);
            this->_Mylast += _Count;
            _Orphan_range(_VIPTR(_Where), this->_Mylast);
            }
        }
 
 #if _ITERATOR_DEBUG_LEVEL == 2
    iterator erase(const_iterator _Where)
        {   // erase element at where
        if (_VICONT(_Where) != this
            || _VIPTR(_Where) < this->_Myfirst
            || this->_Mylast <= _VIPTR(_Where))
            _DEBUG_ERROR("vector erase iterator outside range");
        _Move(_VIPTR(_Where) + 1, this->_Mylast, _VIPTR(_Where));
        _Destroy(this->_Mylast - 1, this->_Mylast);
        _Orphan_range(_VIPTR(_Where), this->_Mylast);
        --this->_Mylast;
        return (_Make_iter(_Where));
        }
 
 #else /* _ITERATOR_DEBUG_LEVEL == 2 */
    iterator erase(const_iterator _Where)
        {   // erase element at where
        _Move(_VIPTR(_Where) + 1, this->_Mylast,
            _VIPTR(_Where));
        _Destroy(this->_Mylast - 1, this->_Mylast);
        --this->_Mylast;
        return (_Make_iter(_Where));
        }
 #endif /* _ITERATOR_DEBUG_LEVEL == 2 */
 
    iterator erase(const_iterator _First_arg,
        const_iterator _Last_arg)
        {   // erase [_First, _Last)
        if (_First_arg == begin() && _Last_arg == end())
            clear();
        else if (_First_arg != _Last_arg)
            {   // clear partial
            iterator _First = _Make_iter(_First_arg);
            iterator _Last = _Make_iter(_Last_arg);
 
            if (_First != _Last)
                {   // worth doing, copy down over hole
 #if _ITERATOR_DEBUG_LEVEL == 2
                if (_Last < _First || _VICONT(_First) != this
                    || _VIPTR(_First) < this->_Myfirst
                    || this->_Mylast < _VIPTR(_Last))
                    _DEBUG_ERROR("vector erase iterator outside range");
                pointer _Ptr = _Move(_VIPTR(_Last), this->_Mylast,
                    _VIPTR(_First));
                _Orphan_range(_VIPTR(_First), this->_Mylast);
 
 #else /* _ITERATOR_DEBUG_LEVEL == 2 */
                pointer _Ptr = _Move(_VIPTR(_Last), this->_Mylast,
                    _VIPTR(_First));
 #endif /* _ITERATOR_DEBUG_LEVEL == 2 */
 
                _Destroy(_Ptr, this->_Mylast);
                this->_Mylast = _Ptr;
                }
            }
        return (_Make_iter(_First_arg));
        }
 
    void clear() _NOEXCEPT
        {   // erase all
        this->_Orphan_all();
        _Destroy(this->_Myfirst, this->_Mylast);
        this->_Mylast = this->_Myfirst;
        }
 
    void swap(_Myt& _Right)
        {   // exchange contents with _Right
        if (this == &_Right)
            ;   // same object, do nothing
        else if (this->_Getal() == _Right._Getal())
            {   // same allocator, swap control information
            this->_Swap_all(_Right);
            _Swap_adl(this->_Myfirst, _Right._Myfirst);
            _Swap_adl(this->_Mylast, _Right._Mylast);
            _Swap_adl(this->_Myend, _Right._Myend);
            }
 
 #if _HAS_CPP0X
        else if (_Alty::propagate_on_container_swap::value)
            {   // swap allocators and control information
            this->_Swap_alloc(_Right);
            _Swap_adl(this->_Myfirst, _Right._Myfirst);
            _Swap_adl(this->_Mylast, _Right._Mylast);
            _Swap_adl(this->_Myend, _Right._Myend);
            }
 #endif /* _HAS_CPP0X */
 
        else
            {   // different allocator, do multiple moves
            _Myt _Ts = _Move(*this);
 
            *this = _Move(_Right);
            _Right = _Move(_Ts);
            }
        }
 
protected:
    void _Assign_n(size_type _Count, const value_type& _Val)
        {   // assign _Count * _Val
        value_type _Tmp = _Val; // in case _Val is in sequence
        erase(begin(), end());
        insert(begin(), _Count, _Tmp);
        }
 
    bool _Buy(size_type _Capacity)
        {   // allocate array with _Capacity elements
        this->_Myfirst = pointer();
        this->_Mylast = pointer();
        this->_Myend = pointer();
 
        if (_Capacity == 0)
            return (false);
        else if (max_size() < _Capacity)
            _Xlen();    // result too long
        else
            {   // nonempty array, allocate storage
            this->_Myfirst = this->_Getal().allocate(_Capacity);
            this->_Mylast = this->_Myfirst;
            this->_Myend = this->_Myfirst + _Capacity;
            }
        return (true);
        }
 
    void _Destroy(pointer _First, pointer _Last)
        {   // destroy [_First, _Last) using allocator
        _Alty _Alval(this->_Getal());
        _Destroy_range(_First, _Last, _Alval);
        }
 
    size_type _Grow_to(size_type _Count) const
        {   // grow by 50% or at least to _Count
        size_type _Capacity = capacity();
 
        _Capacity = max_size() - _Capacity / 2 < _Capacity
            ? 0 : _Capacity + _Capacity / 2;    // try to grow by 50%
        if (_Capacity < _Count)
            _Capacity = _Count;
        return (_Capacity);
        }
 
    bool _Inside(const value_type *_Ptr) const
        {   // test if _Ptr points inside vector
        return (_Ptr < this->_Mylast && this->_Myfirst <= _Ptr);
        }
 
    void _Reallocate(size_type _Count)
        {   // move to array of exactly _Count elements
        pointer _Ptr = this->_Getal().allocate(_Count);
 
        _TRY_BEGIN
        _Umove(this->_Myfirst, this->_Mylast, _Ptr);
        _CATCH_ALL
        this->_Getal().deallocate(_Ptr, _Count);
        _RERAISE;
        _CATCH_END
 
        size_type _Size = size();
        if (this->_Myfirst != pointer())
            {   // destroy and deallocate old array
            _Destroy(this->_Myfirst, this->_Mylast);
            this->_Getal().deallocate(this->_Myfirst,
                this->_Myend - this->_Myfirst);
            }
 
        this->_Orphan_all();
        this->_Myend = _Ptr + _Count;
        this->_Mylast = _Ptr + _Size;
        this->_Myfirst = _Ptr;
        }
 
    void _Reserve(size_type _Count)
        {   // ensure room for _Count new elements, grow exponentially
        if (_Unused_capacity() < _Count)
            {   // need more room, try to get it
            if (max_size() - size() < _Count)
                _Xlen();
            _Reallocate(_Grow_to(size() + _Count));
            }
        }
 
    void _Tidy()
        {   // free all storage
        if (this->_Myfirst != pointer())
            {   // something to free, destroy and deallocate it
            this->_Orphan_all();
            _Destroy(this->_Myfirst, this->_Mylast);
            this->_Getal().deallocate(this->_Myfirst,
                this->_Myend - this->_Myfirst);
            this->_Myfirst = pointer();
            this->_Mylast = pointer();
            this->_Myend = pointer();
            }
        }
 
    template<class _Iter>
        pointer _Ucopy(_Iter _First, _Iter _Last, pointer _Ptr)
        {   // copy initializing [_First, _Last), using allocator
        _Alty _Alval(this->_Getal());
        return (_Uninitialized_copy(_First, _Last,
            _Ptr, _Alval));
        }
 
    template<class _Iter>
        pointer _Umove(_Iter _First, _Iter _Last, pointer _Ptr)
        {   // move initializing [_First, _Last), using allocator
        _Alty _Alval(this->_Getal());
        return (_Uninitialized_move(_First, _Last,
            _Ptr, _Alval));
        }
 
    iterator _Insert_n(const_iterator _Where,
        size_type _Count, const value_type& _Val)
        {   // insert _Count * _Val at _Where
 #if _ITERATOR_DEBUG_LEVEL == 2
        if (_VICONT(_Where) != this
            || _VIPTR(_Where) < this->_Myfirst
            || this->_Mylast < _VIPTR(_Where))
            _DEBUG_ERROR("vector insert iterator outside range");
 #endif /* _ITERATOR_DEBUG_LEVEL == 2 */
 
        size_type _Off = _VIPTR(_Where) - this->_Myfirst;
        if (_Count == 0)
            ;
        else if (_Unused_capacity() < _Count)
            {   // not enough room, reallocate
            if (max_size() - size() < _Count)
                _Xlen();    // result too long
 
            size_type _Capacity = _Grow_to(size() + _Count);
            pointer _Newvec = this->_Getal().allocate(_Capacity);
            size_type _Whereoff = _VIPTR(_Where) - this->_Myfirst;
            int _Ncopied = 0;
 
            _TRY_BEGIN
            _Ufill(_Newvec + _Whereoff, _Count,
                _STD addressof(_Val));  // add new stuff
            ++_Ncopied;
            _Umove(this->_Myfirst, _VIPTR(_Where),
                _Newvec);   // copy prefix
            ++_Ncopied;
            _Umove(_VIPTR(_Where), this->_Mylast,
                _Newvec + (_Whereoff + _Count));    // copy suffix
            _CATCH_ALL
            if (1 < _Ncopied)
                _Destroy(_Newvec, _Newvec + _Whereoff);
            if (0 < _Ncopied)
                _Destroy(_Newvec + _Whereoff, _Newvec + _Whereoff + _Count);
            this->_Getal().deallocate(_Newvec, _Capacity);
            _RERAISE;
            _CATCH_END
 
            _Count += size();
            if (this->_Myfirst != pointer())
                {   // destroy and deallocate old array
                _Destroy(this->_Myfirst, this->_Mylast);
                this->_Getal().deallocate(this->_Myfirst,
                    this->_Myend - this->_Myfirst);
                }
 
            this->_Orphan_all();
            this->_Myend = _Newvec + _Capacity;
            this->_Mylast = _Newvec + _Count;
            this->_Myfirst = _Newvec;
            }
        else if ((size_type)(this->_Mylast - _VIPTR(_Where))
            < _Count)
            {   // new stuff spills off end
            value_type _Tmp = _Val; // in case _Val is in sequence
 
            _Umove(_VIPTR(_Where), this->_Mylast,
                _VIPTR(_Where) + _Count);   // copy suffix
 
            _TRY_BEGIN
            _Ufill(this->_Mylast,
                _Count - (this->_Mylast - _VIPTR(_Where)),
                _STD addressof(_Tmp));  // insert new stuff off end
            _CATCH_ALL
            _Destroy(_VIPTR(_Where) + _Count,
                this->_Mylast + _Count);
            _RERAISE;
            _CATCH_END
 
            this->_Mylast += _Count;
            _Orphan_range(_VIPTR(_Where), this->_Mylast);
            _STD fill(_VIPTR(_Where), this->_Mylast - _Count,
                _Tmp);  // insert up to old end
            }
        else
            {   // new stuff can all be assigned
            value_type _Tmp = _Val; // in case _Val is in sequence
 
            pointer _Oldend = this->_Mylast;
            this->_Mylast = _Umove(_Oldend - _Count, _Oldend,
                this->_Mylast); // copy suffix
 
            _Orphan_range(_VIPTR(_Where), this->_Mylast);
            _Copy_backward(_VIPTR(_Where), _Oldend - _Count,
                _Oldend);   // copy hole
            _STD fill(_VIPTR(_Where),
                _VIPTR(_Where) + _Count, _Tmp); // insert into hole
            }
        return (begin() + _Off);
        }
 
    pointer _Ufill(pointer _Ptr, size_type _Count, const value_type *_Pval)
        {   // copy initializing _Count * _Val, using allocator
        _Alty _Alval(this->_Getal());
        _Uninitialized_fill_n(_Ptr, _Count, _Pval, _Alval);
        return (_Ptr + _Count);
        }
 
    __declspec(noreturn) void _Xlen() const
        {   // report a length_error
        _Xlength_error("vector<T> too long");
        }
 
    __declspec(noreturn) void _Xran() const
        {   // report an out_of_range error
        _Xout_of_range("invalid vector<T> subscript");
        }
 
 #if _VECTOR_ORPHAN_RANGE
    void _Orphan_range(pointer _First, pointer _Last) const
        {   // orphan iterators within specified (inclusive) range
        _Lockit _Lock(_LOCK_DEBUG);
        const_iterator **_Pnext = (const_iterator **)this->_Getpfirst();
        if (_Pnext != 0)
            while (*_Pnext != 0)
                if ((*_Pnext)->_Ptr < _First || _Last < (*_Pnext)->_Ptr)
                    _Pnext = (const_iterator **)(*_Pnext)->_Getpnext();
                else
                    {   // orphan the iterator
                    (*_Pnext)->_Clrcont();
                    *_Pnext = *(const_iterator **)(*_Pnext)->_Getpnext();
                    }
        }
 
 #else /* _VECTOR_ORPHAN_RANGE */
    void _Orphan_range(pointer, pointer) const
        {   // orphan iterators within specified (inclusive) range
        }
 #endif /* _VECTOR_ORPHAN_RANGE */
    };
 
        // vector TEMPLATE OPERATORS
 
template<class _Ty,
    class _Alloc> inline
    void swap(vector<_Ty, _Alloc>& _Left, vector<_Ty, _Alloc>& _Right)
    {   // swap _Left and _Right vectors
    _Left.swap(_Right);
    }
 
template<class _Ty,
    class _Alloc> inline
    bool operator==(const vector<_Ty, _Alloc>& _Left,
        const vector<_Ty, _Alloc>& _Right)
    {   // test for vector equality
    return (_Left.size() == _Right.size()
        && equal(_Left.begin(), _Left.end(), _Right.begin()));
    }
 
template<class _Ty,
    class _Alloc> inline
    bool operator!=(const vector<_Ty, _Alloc>& _Left,
        const vector<_Ty, _Alloc>& _Right)
    {   // test for vector inequality
    return (!(_Left == _Right));
    }
 
template<class _Ty,
    class _Alloc> inline
    bool operator<(const vector<_Ty, _Alloc>& _Left,
        const vector<_Ty, _Alloc>& _Right)
    {   // test if _Left < _Right for vectors
    return (lexicographical_compare(_Left.begin(), _Left.end(),
        _Right.begin(), _Right.end()));
    }
 
template<class _Ty,
    class _Alloc> inline
    bool operator>(const vector<_Ty, _Alloc>& _Left,
        const vector<_Ty, _Alloc>& _Right)
    {   // test if _Left > _Right for vectors
    return (_Right < _Left);
    }
 
template<class _Ty,
    class _Alloc> inline
    bool operator<=(const vector<_Ty, _Alloc>& _Left,
        const vector<_Ty, _Alloc>& _Right)
    {   // test if _Left <= _Right for vectors
    return (!(_Right < _Left));
    }
 
template<class _Ty,
    class _Alloc> inline
    bool operator>=(const vector<_Ty, _Alloc>& _Left,
        const vector<_Ty, _Alloc>& _Right)
    {   // test if _Left >= _Right for vectors
    return (!(_Left < _Right));
    }
 
//
// TEMPLATE CLASS vector<bool, Alloc> AND FRIENDS
//
typedef unsigned int _Vbase;    // word type for vector<bool> representation
const int _VBITS = 8 * sizeof (_Vbase); // at least CHAR_BITS bits per word
 
        // CLASS _Vb_iter_base
template<class _Alloc>
    class _Vb_iter_base
        : public _Iterator012<random_access_iterator_tag,
            _Bool,
            typename _Alloc::difference_type,
            bool *,
            bool,
            _Iterator_base>
    {   // store information common to reference and iterators
public:
    typedef typename _Alloc::size_type _Sizet;
    typedef vector<_Bool, _Alloc> _Mycont;
 
    _Vb_iter_base()
        : _Myptr(0), _Myoff(0)
        {   // construct with null pointer
        }
 
    _Vb_iter_base(const _Vbase *_Ptr, _Sizet _Off,
        const _Container_base *_Mypvbool)
        : _Myptr(_Ptr), _Myoff(_Off)
        {   // construct with offset and pointer
        this->_Adopt(_Mypvbool);
        }
 
    int _Valid(_Sizet _Inc) const
        {   // test for valid incremented offset
 #if _ITERATOR_DEBUG_LEVEL == 2
        _Sizet _Mysize = ((_Mycont *)this->_Getcont())->_Mysize;
 
        _Inc += _Myoff;
        _Inc += _VBITS * (_Myptr
            - (((_Mycont *)this->_Getcont())->_Myvec)._Myfirst);
        return (_Inc < _Mysize ? -1 : _Inc == _Mysize ? 0 : +1);
 
 #else /* _ITERATOR_DEBUG_LEVEL == 2 */
 
        return (-1);
 #endif /* _ITERATOR_DEBUG_LEVEL == 2 */
        }
 
    const _Vbase *_Myptr;
    _Sizet _Myoff;
    };
 
        // CLASS _Vb_reference
template<class _Alloc>
    class _Vb_reference
        : public _Vb_iter_base<_Alloc>
    {   // reference to a bit within a base word
    typedef _Vb_iter_base<_Alloc> _Mybase;
    typedef _Vb_reference<_Alloc> _Mytype;
 
    _Vb_reference()
        {   // construct with null pointer (private)
        }
 
public:
    _Vb_reference(const _Mybase& _Right)
        : _Mybase(_Right._Myptr, _Right._Myoff, _Right._Getcont())
        {   // construct with base
        }
 
    _Mytype& operator=(const _Mytype& _Right)
        {   // assign _Vb_reference _Right to bit
        return (*this = bool(_Right));
        }
 
    _Mytype& operator=(bool _Val)
        {   // assign _Val to bit
        if (_Val)
            *(_Vbase *)_Getptr() |= _Mask();
        else
            *(_Vbase *)_Getptr() &= (~_Mask()); // STET
        return (*this);
        }
 
    void flip()
        {   // toggle the bit
        *(_Vbase *)_Getptr() ^= _Mask();
        }
 
    operator bool() const
        {   // test if bit is set
        return ((*_Getptr() & _Mask()) != 0);
        }
 
    const _Vbase *_Getptr() const
        {   // get pointer to base word
 #if _ITERATOR_DEBUG_LEVEL == 2
        if (this->_Getcont() == 0
            || this->_Myptr == 0
            || 0 <= this->_Valid(0))
            {   // report error
            _DEBUG_ERROR("vector<bool> iterator not dereferencable");
            _SCL_SECURE_OUT_OF_RANGE;
            }
 
 #elif _ITERATOR_DEBUG_LEVEL == 1
        _SCL_SECURE_VALIDATE(this->_Getcont() != 0 && this->_Myptr != 0);
        _SCL_SECURE_VALIDATE_RANGE(this->_Valid(0) < 0);
 #endif /* _ITERATOR_DEBUG_LEVEL */
 
        return (this->_Myptr);
        }
 
protected:
    _Vbase _Mask() const
        {   // convert offset to mask
        return ((_Vbase)(1 << this->_Myoff));
        }
    };
 
template<class _Alloc> inline
    void swap(_Vb_reference<_Alloc> _Left,
        _Vb_reference<_Alloc> _Right)
    {   // swap _Left and _Right vector<bool> elements
    bool _Val = _Left;  // NOT _STD swap
    _Left = _Right;
    _Right = _Val;
    }
 
        // CLASS _Vb_const_iterator
template<class _Alloc>
    class _Vb_const_iterator
        : public _Vb_iter_base<_Alloc>
    {   // iterator for nonmutable vector<bool>
public:
    typedef _Vb_iter_base<_Alloc> _Mybase;
    typedef _Vb_const_iterator<_Alloc> _Mytype;
 
    typedef _Vb_reference<_Alloc> _Reft;
    typedef bool const_reference;
 
    typedef random_access_iterator_tag iterator_category;
    typedef _Bool value_type;
    typedef typename _Alloc::size_type size_type;
    typedef typename _Alloc::difference_type difference_type;
    typedef const_reference *pointer;
    typedef const_reference reference;
 
    _Vb_const_iterator()
        {   // construct with null reference
        }
 
    _Vb_const_iterator(const _Vbase *_Ptr, const _Container_base *_Mypvbool)
        : _Mybase(_Ptr, 0, _Mypvbool)
        {   // construct with offset and pointer
        }
 
    const_reference operator*() const
        {   // return (reference to) designated object
        return (_Reft(*this));
        }
 
    _Mytype& operator++()
        {   // preincrement
        _Inc();
        return (*this);
        }
 
    _Mytype operator++(int)
        {   // postincrement
        _Mytype _Tmp = *this;
        ++*this;
        return (_Tmp);
        }
 
    _Mytype& operator--()
        {   // predecrement
        _Dec();
        return (*this);
        }
 
    _Mytype operator--(int)
        {   // postdecrement
        _Mytype _Tmp = *this;
        --*this;
        return (_Tmp);
        }
 
    _Mytype& operator+=(difference_type _Off)
        {   // increment by integer
        if (_Off < 0 && this->_Myoff < 0 - (size_type)_Off)
            {   /* add negative increment */
            this->_Myoff += _Off;
            this->_Myptr -= 1 + ((size_type)(-1) - this->_Myoff) / _VBITS;
            this->_Myoff %= _VBITS;
            }
        else
            {   /* add non-negative increment */
            this->_Myoff += _Off;
            this->_Myptr += this->_Myoff / _VBITS;
            this->_Myoff %= _VBITS;
            }
        return (*this);
        }
 
    _Mytype operator+(difference_type _Off) const
        {   // return this + integer
        _Mytype _Tmp = *this;
        return (_Tmp += _Off);
        }
 
    _Mytype& operator-=(difference_type _Off)
        {   // decrement by integer
        return (*this += -_Off);
        }
 
    _Mytype operator-(difference_type _Off) const
        {   // return this - integer
        _Mytype _Tmp = *this;
        return (_Tmp -= _Off);
        }
 
    difference_type operator-(
        const _Mytype& _Right) const
        {   // return difference of iterators
        _Compat(_Right);
        return (_VBITS * (this->_Myptr - _Right._Myptr)
            + (difference_type)this->_Myoff
            - (difference_type)_Right._Myoff);
        }
 
    const_reference operator[](difference_type _Off) const
        {   // subscript
        return (*(*this + _Off));
        }
 
    bool operator==(const _Mytype& _Right) const
        {   // test for iterator equality
        _Compat(_Right);
        return (this->_Myptr == _Right._Myptr
            && this->_Myoff == _Right._Myoff);
        }
 
    bool operator!=(const _Mytype& _Right) const
        {   // test for iterator inequality
        return (!(*this == _Right));
        }
 
    bool operator<(const _Mytype& _Right) const
        {   // test if this < _Right
        _Compat(_Right);
        return (this->_Myptr < _Right._Myptr
            || this->_Myptr == _Right._Myptr
                && this->_Myoff < _Right._Myoff);
        }
 
    bool operator>(const _Mytype& _Right) const
        {   // test if this > _Right
        return (_Right < *this);
        }
 
    bool operator<=(const _Mytype& _Right) const
        {   // test if this <= _Right
        return (!(_Right < *this));
        }
 
    bool operator>=(const _Mytype& _Right) const
        {   // test if this >= _Right
        return (!(*this < _Right));
        }
 
 #if _ITERATOR_DEBUG_LEVEL == 2
    void _Compat(const _Mytype& _Right) const
        {   // test for compatible iterator pair
        if (this->_Getcont() == 0
            || this->_Getcont() != _Right._Getcont())
            _DEBUG_ERROR("vector<bool> iterators incompatible");
        }
 
 #elif _ITERATOR_DEBUG_LEVEL == 1
    void _Compat(const _Mytype& _Right) const
        {   // test for compatible iterator pair
        _SCL_SECURE_VALIDATE(this->_Getcont() != 0);
        _SCL_SECURE_VALIDATE_RANGE(this->_Getcont() == _Right._Getcont());
        }
 
 #else /* _ITERATOR_DEBUG_LEVEL == 0 */
    void _Compat(const _Mytype&) const
        {   // test for compatible iterator pair
        }
 #endif /* _ITERATOR_DEBUG_LEVEL */
 
    void _Dec()
        {   // decrement bit position
        if (this->_Myoff != 0)
            --this->_Myoff;
        else
            {   // move to previous word
 #if _ITERATOR_DEBUG_LEVEL == 2
            if (this->_Getcont() == 0 || 0 < this->_Valid((size_type)-1))
                {   // report error
                _DEBUG_ERROR("vector<bool> iterator not decrementable");
                _SCL_SECURE_OUT_OF_RANGE;
                }
 
 #elif _ITERATOR_DEBUG_LEVEL == 1
            _SCL_SECURE_VALIDATE(this->_Getcont() != 0);
            _SCL_SECURE_VALIDATE_RANGE(this->_Valid((size_type)-1) <= 0);
 #endif /* _ITERATOR_DEBUG_LEVEL */
 
            this->_Myoff = _VBITS - 1;
            --this->_Myptr;
            }
        }
 
    void _Inc()
        {   // increment bit position
        if (this->_Myoff < _VBITS - 1)
            ++this->_Myoff;
        else
            {   // move to next word
 #if _ITERATOR_DEBUG_LEVEL == 2
            if (this->_Getcont() == 0 || 0 < this->_Valid(1))
                {   // report error
                _DEBUG_ERROR("vector<bool> iterator not incrementable");
                _SCL_SECURE_OUT_OF_RANGE;
                }
 
 #elif _ITERATOR_DEBUG_LEVEL == 1
            _SCL_SECURE_VALIDATE(this->_Getcont() != 0);
            _SCL_SECURE_VALIDATE_RANGE(this->_Valid(1) <= 0);
 #endif /* _ITERATOR_DEBUG_LEVEL */
 
            this->_Myoff = 0;
            ++this->_Myptr;
            }
        }
    };
 
template<class _Alloc> inline
    _Vb_const_iterator<_Alloc> operator+(
        typename _Alloc::difference_type _Off,
        _Vb_const_iterator<_Alloc> _Right)
        {   // return _Right + integer
        return (_Right += _Off);
        }
 
template<class _Alloc>
    struct _Is_checked_helper<_Vb_const_iterator<_Alloc> >
        : public true_type
    {   // mark _Vb_const_iterator as checked
    };
 
    // CLASS _Vb_iterator
template<class _Alloc>
    class _Vb_iterator
        : public _Vb_const_iterator<_Alloc>
    {   // iterator for mutable vector<bool>
public:
    typedef _Vb_const_iterator<_Alloc> _Mybase;
    typedef _Vb_iterator<_Alloc> _Mytype;
 
    typedef _Vb_reference<_Alloc> _Reft;
    typedef bool const_reference;
 
    typedef random_access_iterator_tag iterator_category;
    typedef _Bool value_type;
    typedef typename _Alloc::size_type size_type;
    typedef typename _Alloc::difference_type difference_type;
    typedef _Reft *pointer;
    typedef _Reft reference;
 
    _Vb_iterator()
        {   // construct with null reference
        }
 
    _Vb_iterator(_Vbase *_Ptr, _Container_base *_Mypvbool)
        : _Mybase(_Ptr, _Mypvbool)
        {   // construct with offset and pointer
        }
 
    reference operator*() const
        {   // return (reference to) designated object
        return (_Reft(*this));
        }
 
    _Mytype& operator++()
        {   // preincrement
        ++*(_Mybase *)this;
        return (*this);
        }
 
    _Mytype operator++(int)
        {   // postincrement
        _Mytype _Tmp = *this;
        ++*this;
        return (_Tmp);
        }
 
    _Mytype& operator--()
        {   // predecrement
        --*(_Mybase *)this;
        return (*this);
        }
 
    _Mytype operator--(int)
        {   // postdecrement
        _Mytype _Tmp = *this;
        --*this;
        return (_Tmp);
        }
 
    _Mytype& operator+=(difference_type _Off)
        {   // increment by integer
        *(_Mybase *)this += _Off;
        return (*this);
        }
 
    _Mytype operator+(difference_type _Off) const
        {   // return this + integer
        _Mytype _Tmp = *this;
        return (_Tmp += _Off);
        }
 
    _Mytype& operator-=(difference_type _Off)
        {   // decrement by integer
        return (*this += -_Off);
        }
 
    _Mytype operator-(difference_type _Off) const
        {   // return this - integer
        _Mytype _Tmp = *this;
        return (_Tmp -= _Off);
        }
 
    difference_type operator-(const _Mybase& _Right) const
        {   // return difference of iterators
        return (*(_Mybase *)this - _Right);
        }
 
    reference operator[](difference_type _Off) const
        {   // subscript
        return (*(*this + _Off));
        }
    };
 
template<class _Alloc> inline
    _Vb_iterator<_Alloc> operator+(typename _Alloc::difference_type _Off,
        _Vb_iterator<_Alloc> _Right)
        {   // return _Right + integer
        return (_Right += _Off);
        }
 
template<class _Alloc>
    struct _Is_checked_helper<_Vb_iterator<_Alloc> >
        : public true_type
    {   // mark _Vb_iterator as checked
    };
 
        // TEMPLATE CLASS _Vb_val
template<class _Alloc>
    class _Vb_val
        : public _Container_base
    {   // base class for vector<bool> to hold data
public:
    typedef _STD vector<_Vbase, _Alloc> _Vectype;
    typedef typename _Vectype::_Alty _Alty;
    typedef typename _Alty::size_type size_type;
 
    _Vb_val(size_type _Count, const bool& _Val, const _Alloc& _Al = _Alloc())
        : _Myvec(_Nw(_Count), (_Vbase)(_Val ? -1 : 0), _Al)
        {   // construct _Count * _Val elements with allocator _Al
        _Alloc_proxy();
        _Mysize = 0;
        }
 
    _Vb_val(const _Vb_val& _Right)
        : _Myvec(_Right._Myvec),
            _Mysize(_Right._Mysize)
        {   // copy construct
        _Alloc_proxy();
        }
 
    _Vb_val(const _Vb_val& _Right, const _Alloc& _Al)
        : _Myvec(_Right._Myvec, _Al),
            _Mysize(_Right._Mysize)
        {   // copy construct, allocator
        _Alloc_proxy();
        }
 
    _Vb_val(_Vb_val&& _Right)
        : _Myvec(_STD forward<_Vectype>(_Right._Myvec)),
            _Mysize(_Right._Mysize)
        {   // move construct
        _Right._Mysize = 0;
        _Alloc_proxy();
        }
 
    _Vb_val(_Vb_val&& _Right, const _Alloc& _Al)
        : _Myvec(_STD forward<_Vectype>(_Right._Myvec), _Al),
            _Mysize(_Right._Mysize)
        {   // move construct, allocator
        _Right._Mysize = 0;
        _Alloc_proxy();
        }
 
    ~_Vb_val() _NOEXCEPT
        {   // destroy proxy
        _Free_proxy();
        }
 
 #if _ITERATOR_DEBUG_LEVEL == 0
    void _Swap_alloc(_Vb_val&)
        {   // do nothing
        }
 
    void _Alloc_proxy()
        {   // do nothing
        }
 
    void _Free_proxy()
        {   // do nothing
        }
 
 #else /* _ITERATOR_DEBUG_LEVEL == 0 */
    void _Swap_alloc(_Vb_val& _Right)
        {   // swap proxies to follow allocators in vector
        _Swap_adl(this->_Myproxy, _Right._Myproxy);
        }
 
    void _Alloc_proxy()
        {   // allocate a proxy
        typename _Alloc::template rebind<_Container_proxy>::other
            _Alproxy(_Myvec.get_allocator());
        this->_Myproxy = _Alproxy.allocate(1);
        _Alproxy.construct(this->_Myproxy, _Container_proxy());
        this->_Myproxy->_Mycont = this;
        }
 
    void _Free_proxy()
        {   // destroy proxy
        typename _Alloc::template rebind<_Container_proxy>::other
            _Alproxy(_Myvec.get_allocator());
        this->_Orphan_all();
        _Alproxy.destroy(this->_Myproxy);
        _Alproxy.deallocate(this->_Myproxy, 1);
        this->_Myproxy = 0;
        }
 #endif /* _ITERATOR_DEBUG_LEVEL == 0 */
 
    static size_type _Nw(size_type _Count)
        {   // return number of base words from number of bits
        return ((_Count + _VBITS - 1) / _VBITS);
        }
 
    _Vectype _Myvec;    // base vector of words
    typename _Alty::size_type _Mysize;  // current length of sequence
    };
 
        // CLASS vector<bool>
 
template<class _Alloc>
    class vector<_Bool, _Alloc>
        : public _Vb_val<_Alloc>
    {   // varying size array of bits
public:
    typedef _STD vector<_Bool, _Alloc> _Myt;
    typedef _Vb_val<_Alloc> _Mybase;
    typedef typename _Mybase::_Alty _Alty;
    typedef typename _Mybase::_Vectype _Vectype;
 
    typedef typename _Alty::size_type size_type;
    typedef typename _Alty::difference_type _Dift;
    typedef _Dift difference_type;
    typedef _Bool _Ty;
    typedef _Alloc allocator_type;
 
    typedef _Vb_reference<_Alty> reference;
    typedef bool const_reference;
    typedef bool value_type;
 
    typedef reference _Reft;
    typedef _Vb_const_iterator<_Alty> const_iterator;
    typedef _Vb_iterator<_Alty> iterator;
 
    typedef iterator pointer;
    typedef const_iterator const_pointer;
    typedef _STD reverse_iterator<iterator> reverse_iterator;
    typedef _STD reverse_iterator<const_iterator> const_reverse_iterator;
 
    static const int _VBITS = _STD _VBITS;
 
    enum {_EEN_VBITS = _VBITS}; // helper for expression evaluator
 
    vector()
        : _Mybase(0, false)
        {   // construct empty vector
        }
 
    explicit vector(const _Alloc& _Al)
        : _Mybase(0, false, _Al)
        {   // construct empty vector, allocator
        }
 
    explicit vector(size_type _Count, const bool& _Val = false)
        : _Mybase(_Count, _Val)
        {   // construct from _Count * _Val
        _Trim(_Count);
        }
 
    vector(size_type _Count, const bool& _Val, const _Alloc& _Al)
        : _Mybase(_Count, _Val, _Al)
        {   // construct from _Count * _Val, allocator
        _Trim(_Count);
        }
 
    vector(const _Myt& _Right)
        : _Mybase(_Right)
        {   // construct by copying _Right
        }
 
    vector(const _Myt& _Right, const _Alloc& _Al)
        : _Mybase(_Right, _Al)
        {   // construct by copying _Right, allocator
        }
 
    template<class _Iter>
        vector(_Iter _First, _Iter _Last,
            typename enable_if<_Is_iterator<_Iter>::value,
                void>:: type ** = 0)
        : _Mybase(0, false)
        {   // construct from [_First, _Last)
        _BConstruct(_First, _Last);
        }
 
    template<class _Iter>
        vector(_Iter _First, _Iter _Last, const _Alloc& _Al,
            typename enable_if<_Is_iterator<_Iter>::value,
                void>:: type ** = 0)
        : _Mybase(0, false, _Al)
        {   // construct from [_First, _Last), allocator
        _BConstruct(_First, _Last);
        }
 
    template<class _Iter>
        void _BConstruct(_Iter _First, _Iter _Last)
        {   // initialize from [_First, _Last), input iterators
        insert(begin(), _First, _Last);
        }
 
    vector(_Myt&& _Right)
        : _Mybase(_STD forward<_Myt>(_Right))
        {   // move construct by moving _Right
        }
 
    vector(_Myt&& _Right, const _Alloc& _Al)
        : _Mybase(_STD forward<_Myt>(_Right), _Al)
        {   // move construct by moving _Right, allocator
        }
 
    _Myt& operator=(_Myt&& _Right)
        {   // assign by moving _Right
        if (this != &_Right)
            {   // different, assign it
            clear();
 
 #if _HAS_CPP0X
            if (this->get_allocator() != _Right.get_allocator()
                && _Alty::propagate_on_container_move_assignment::value)
                {   // assign vector, dumping proxy
                this->_Free_proxy();
                this->_Myvec = _STD move(_Right._Myvec);
                this->_Alloc_proxy();
                }
            else
                this->_Myvec = _STD move(_Right._Myvec);
 
 #else /* _HAS_CPP0X */
            this->_Myvec = _STD move(_Right._Myvec);
 #endif /* _HAS_CPP0X */
 
            this->_Mysize = _Right._Mysize;
            _Right._Mysize = 0;
            }
        return (*this);
        }
 
    ~vector() _NOEXCEPT
        {   // destroy the object
        this->_Mysize = 0;
        }
 
    _Myt& operator=(const _Myt& _Right)
        {   // assign from _Right
        this->_Mysize = _Right._Mysize;
        this->_Myvec = _Right._Myvec;
        return (*this);
        }
 
    void reserve(size_type _Count)
        {   // determine new minimum length of allocated storage
        this->_Myvec.reserve(this->_Nw(_Count));
        }
 
    size_type capacity() const
        {   // return current length of allocated storage
        return (this->_Myvec.capacity() * _VBITS);
        }
 
    iterator begin()
        {   // return iterator for beginning of mutable sequence
        return (iterator((_Vbase *)this->_Myvec._Myfirst, this));
        }
 
    const_iterator begin() const
        {   // return iterator for beginning of nonmutable sequence
        return (const_iterator((_Vbase *)this->_Myvec._Myfirst, this));
        }
 
    iterator end()
        {   // return iterator for end of mutable sequence
        iterator _Tmp = begin();
        if (0 < this->_Mysize)
            _Tmp += this->_Mysize;
        return (_Tmp);
        }
 
    const_iterator end() const
        {   // return iterator for end of nonmutable sequence
        const_iterator _Tmp = begin();
        if (0 < this->_Mysize)
            _Tmp += this->_Mysize;
        return (_Tmp);
        }
 
 #if _HAS_CPP0X
    const_iterator cbegin() const
        {   // return iterator for beginning of nonmutable sequence
        return (((const _Myt *)this)->begin());
        }
 
    const_iterator cend() const
        {   // return iterator for end of nonmutable sequence
        return (((const _Myt *)this)->end());
        }
 
    const_reverse_iterator crbegin() const
        {   // return iterator for beginning of reversed nonmutable sequence
        return (((const _Myt *)this)->rbegin());
        }
 
    const_reverse_iterator crend() const
        {   // return iterator for end of reversed nonmutable sequence
        return (((const _Myt *)this)->rend());
        }
 
    void shrink_to_fit()
        {   // reduce capacity
        if (this->_Myvec._Has_unused_capacity())
            {   // worth shrinking, do it
            _Myt _Tmp(*this);
            swap(_Tmp);
            }
        }
 #endif /* _HAS_CPP0X */
 
    iterator _Make_iter(const_iterator _Where)
        {   // make iterator from const_iterator
        iterator _Tmp = begin();
        if (0 < this->_Mysize)
            _Tmp += _Where - begin();
        return (_Tmp);
        }
 
    reverse_iterator rbegin()
        {   // return iterator for beginning of reversed mutable sequence
        return (reverse_iterator(end()));
        }
 
    const_reverse_iterator rbegin() const
        {   // return iterator for beginning of reversed nonmutable sequence
        return (const_reverse_iterator(end()));
        }
 
    reverse_iterator rend()
        {   // return iterator for end of reversed mutable sequence
        return (reverse_iterator(begin()));
        }
 
    const_reverse_iterator rend() const
        {   // return iterator for end of reversed nonmutable sequence
        return (const_reverse_iterator(begin()));
        }
 
    void resize(size_type _Newsize, bool _Val = false)
        {   // determine new length, padding with _Val elements as needed
        if (size() < _Newsize)
            _Insert_n(end(), _Newsize - size(), _Val);
        else if (_Newsize < size())
            erase(begin() + _Newsize, end());
        }
 
    size_type size() const
        {   // return length of sequence
        return (this->_Mysize);
        }
 
    size_type max_size() const
        {   // return maximum possible length of sequence
        const size_type _Maxsize = this->_Myvec.max_size();
        return (_Maxsize < (size_type)(-1) / _VBITS
            ? _Maxsize * _VBITS : (size_type)(-1));
        }
 
    bool empty() const
        {   // test if sequence is empty
        return (size() == 0);
        }
 
    _Alloc get_allocator() const
        {   // return allocator object for values
        return (this->_Myvec.get_allocator());
        }
 
    const_reference at(size_type _Off) const
        {   // subscript nonmutable sequence with checking
        if (size() <= _Off)
            _Xran();
        return (*(begin() + _Off));
        }
 
    reference at(size_type _Off)
        {   // subscript mutable sequence with checking
        if (size() <= _Off)
            _Xran();
        return (*(begin() + _Off));
        }
 
    const_reference operator[](size_type _Off) const
        {   // subscript nonmutable sequence
        return (*(begin() + _Off));
        }
 
    reference operator[](size_type _Off)
        {   // subscript mutable sequence
        return (*(begin() + _Off));
        }
 
    reference front()
        {   // return first element of mutable sequence
        return (*begin());
        }
 
    const_reference front() const
        {   // return first element of nonmutable sequence
        return (*begin());
        }
 
    reference back()
        {   // return last element of mutable sequence
        return (*(end() - 1));
        }
 
    const_reference back() const
        {   // return last element of nonmutable sequence
        return (*(end() - 1));
        }
 
    void push_back(const bool& _Val)
        {   // insert element at end
        insert(end(), _Val);
        }
 
    void pop_back()
        {   // erase element at end
        if (!empty())
            erase(end() - 1);
        }
 
    template<class _Iter>
        typename enable_if<_Is_iterator<_Iter>::value,
            void>::type
        assign(_Iter _First, _Iter _Last)
        {   // assign [_First, _Last), input iterators
        erase(begin(), end());
        insert(begin(), _First, _Last);
        }
 
    void assign(size_type _Count, const bool& _Val)
        {   // assign _Count * _Val
        _Assign_n(_Count, _Val);
        }
 
    iterator insert(const_iterator _Where, const bool& _Val)
        {   // insert _Val at _Where
        return (_Insert_n(_Where, (size_type)1, _Val));
        }
 
    iterator insert(const_iterator _Where, size_type _Count,
        const bool& _Val)
        {   // insert _Count * _Val at _Where
        return (_Insert_n(_Where, _Count, _Val));
        }
 
    template<class _Iter>
        typename enable_if<_Is_iterator<_Iter>::value,
            iterator>::type
        insert(const_iterator _Where, _Iter _First, _Iter _Last)
        {   // insert [_First, _Last) at _Where
        size_type _Off = _Where - begin();
        _Insert(_Where, _First, _Last, _Iter_cat(_First));
        return (begin() + _Off);
        }
 
    template<class _Iter>
        void _Insert(const_iterator _Where, _Iter _First, _Iter _Last,
            input_iterator_tag)
        {   // insert [_First, _Last) at _Where, input iterators
        size_type _Off = _Where - begin();
 
        for (; _First != _Last; ++_First, ++_Off)
            insert(begin() + _Off, *_First);
        }
 
    template<class _Iter>
        void _Insert(const_iterator _Where,
            _Iter _First, _Iter _Last,
            forward_iterator_tag)
        {   // insert [_First, _Last) at _Where, forward iterators
        _DEBUG_RANGE(_First, _Last);
        size_type _Count = 0;
        _Distance(_First, _Last, _Count);
 
        size_type _Off = _Insert_x(_Where, _Count);
        _STD copy(_First, _Last, begin() + _Off);
        }
 
    iterator erase(const_iterator _Where_arg)
        {   // erase element at _Where
        iterator _Where = _Make_iter(_Where_arg);
        size_type _Off = _Where - begin();
 
 #if _ITERATOR_DEBUG_LEVEL == 2
        if (end() <= _Where)
            _DEBUG_ERROR("vector<bool> erase iterator outside range");
        _STD copy(_Where + 1, end(), _Where);
        _Orphan_range(_Off, this->_Mysize);
 
 #else /* _ITERATOR_DEBUG_LEVEL == 2 */
        _STD copy(_Where + 1, end(), _Where);
 #endif /* _ITERATOR_DEBUG_LEVEL == 2 */
 
        _Trim(this->_Mysize - 1);
        return (begin() + _Off);
        }
 
    iterator erase(const_iterator _First_arg, const_iterator _Last_arg)
        {   // erase [_First, _Last)
        iterator _First = _Make_iter(_First_arg);
        iterator _Last = _Make_iter(_Last_arg);
        size_type _Off = _First - begin();
 
        if (_First != _Last)
            {   // worth doing, copy down over hole
 #if _ITERATOR_DEBUG_LEVEL == 2
            if (_Last < _First || end() < _Last)
                _DEBUG_ERROR("vector<bool> erase iterator outside range");
            iterator _Next = _STD copy(_Last, end(), _First);
            size_type _Newsize = _Next - begin();
            _Orphan_range(_Newsize, this->_Mysize);
            _Trim(_Newsize);
 
 #else /* _ITERATOR_DEBUG_LEVEL == 2 */
            iterator _Next = _STD copy(_Last, end(), _First);
            _Trim(_Next - begin());
 #endif /* _ITERATOR_DEBUG_LEVEL == 2 */
            }
        return (begin() + _Off);
        }
 
    void clear() _NOEXCEPT
        {   // erase all elements
        erase(begin(), end());
        }
 
    void flip()
        {   // toggle all elements
        for (typename _Vectype::iterator _Next = this->_Myvec.begin();
            _Next != this->_Myvec.end(); ++_Next)
            *_Next = (_Vbase)~*_Next;
        _Trim(this->_Mysize);
        }
 
    void swap(_Myt& _Right)
        {   // exchange contents with right
        if (this == &_Right)
            ;   // same object, do nothing
        else if (this->get_allocator() == _Right.get_allocator())
            {   // same allocator, swap control information
            this->_Swap_all(_Right);
            this->_Myvec.swap(_Right._Myvec);
            _STD swap(this->_Mysize, _Right._Mysize);
            }
 
 #if _HAS_CPP0X
        else if (_Alty::propagate_on_container_swap::value)
            {   // swap allocators and control information
            this->_Swap_alloc(_Right);
            this->_Myvec.swap(_Right._Myvec);
            _STD swap(this->_Mysize, _Right._Mysize);
            }
 #endif /* _HAS_CPP0X */
 
        else
            {   // different allocator, copy contents
            this->_Swap_all(_Right);
            this->_Myvec.swap(_Right._Myvec);
            _STD swap(this->_Mysize, _Right._Mysize);
            }
        }
 
    static void swap(reference _Left, reference _Right)
        {   // swap _Left and _Right vector<bool> elements
        bool _Val = _Left;  // NOT _STD swap
 
        _Left = _Right;
        _Right = _Val;
        }
 
 #if _HAS_CPP0X
    size_t hash() const
        {   // hash bits to size_t value by pseudorandomizing transform
        return (_Hash_seq((const unsigned char *)this->_Myvec.data(),
            this->_Myvec.size() * sizeof (_Vbase)));
        }
 #endif /* _HAS_CPP0X */
 
    void _Assign_n(size_type _Count, const bool& _Val)
        {   // assign _Count * _Val
        erase(begin(), end());
        _Insert_n(begin(), _Count, _Val);
        }
 
    iterator _Insert_n(const_iterator _Where,
        size_type _Count, const bool& _Val)
        {   // insert _Count * _Val at _Where
        size_type _Off = _Insert_x(_Where, _Count);
        _STD fill(begin() + _Off, begin() + (_Off + _Count), _Val);
        return (begin() + _Off);
        }
 
    size_type _Insert_x(const_iterator _Where, size_type _Count)
        {   // make room to insert _Count elements at _Where
        size_type _Off = _Where - begin();
 
 #if _ITERATOR_DEBUG_LEVEL == 2
        if (end() < _Where)
            _DEBUG_ERROR("vector<bool> insert iterator outside range");
        bool _Realloc = capacity() - size() < _Count;
 #endif /* _ITERATOR_DEBUG_LEVEL == 2 */
 
        if (_Count == 0)
            ;
        else if (max_size() - size() < _Count)
            _Xlen();    // result too long
        else
            {   // worth doing
            this->_Myvec.resize(this->_Nw(size() + _Count), 0);
            if (empty())
                this->_Mysize += _Count;
            else
                {   // make room and copy down suffix
                iterator _Oldend = end();
                this->_Mysize += _Count;
                _STD copy_backward(begin() + _Off, _Oldend, end());
                }
 
 #if _ITERATOR_DEBUG_LEVEL == 2
            _Orphan_range(_Realloc ? 0 : _Off, this->_Mysize);
 #endif /* _ITERATOR_DEBUG_LEVEL == 2 */
            }
        return (_Off);
        }
 
 #if _VECTOR_ORPHAN_RANGE
    void _Orphan_range(size_type _Offlo, size_type _Offhi) const
        {   // orphan iterators within specified (inclusive) range
        typedef _Vb_iter_base<_Alty> _Myiterbase;
 
        _Lockit _Lock(_LOCK_DEBUG);
        _Vbase *_Base = (_Vbase *)this->_Myvec._Myfirst;
 
        const_iterator **_Pnext = (const_iterator **)this->_Getpfirst();
        if (_Pnext != 0)
            while (*_Pnext != 0)
                {   // test offset from beginning of vector
                size_type _Off = _VBITS * ((*_Pnext)->_Myptr - _Base)
                    + (*_Pnext)->_Myoff;
                if (_Off < _Offlo || _Offhi < _Off)
                    _Pnext = (const_iterator **)(*_Pnext)->_Getpnext();
                else
                    {   // orphan the iterator
                    (*_Pnext)->_Clrcont();
                    *_Pnext = *(const_iterator **)(*_Pnext)->_Getpnext();
                    }
                }
        }
 
 #else /* _VECTOR_ORPHAN_RANGE */
    void _Orphan_range(size_type, size_type) const
        {   // orphan iterators within specified (inclusive) range
        }
 #endif /* _VECTOR_ORPHAN_RANGE */
 
    void _Trim(size_type _Size)
        {   // trim base vector to exact length in bits
        if (max_size() < _Size)
            _Xlen();    // result too long
        size_type _Words = this->_Nw(_Size);
 
        if (_Words < this->_Myvec.size())
            this->_Myvec.erase(this->_Myvec.begin() + _Words,
                this->_Myvec.end());
        this->_Mysize = _Size;
        _Size %= _VBITS;
        if (0 < _Size)
            this->_Myvec[_Words - 1] &= (_Vbase)((1 << _Size) - 1);
        }
 
    __declspec(noreturn) void _Xlen() const
        {   // report a length_error
        _Xlength_error("vector<bool> too long");
        }
 
    __declspec(noreturn) void _Xran() const
        {   // report an out_of_range error
        _Xout_of_range("invalid vector<bool> subscript");
        }
    };
 
template<class _Alloc> inline
    bool operator==(const vector<bool, _Alloc>& _Left,
        const vector<bool, _Alloc>& _Right)
    {   // test for vector equality
    return (_Left.size() == _Right.size()
        && equal(_Left._Myvec.begin(), _Left._Myvec.end(),
            _Right._Myvec.begin()));
    }
 
template<class _Alloc> inline
    bool operator!=(const vector<bool, _Alloc>& _Left,
        const vector<bool, _Alloc>& _Right)
    {   // test for vector inequality
    return (!(_Left == _Right));
    }
 
 #if _HAS_CPP0X
    // TEMPLATE STRUCT SPECIALIZATION hash
template<class _Alloc>
    struct hash<vector<_Bool, _Alloc> >
        : public unary_function<vector<_Bool, _Alloc>, size_t>
    {   // hash functor
    typedef vector<_Bool, _Alloc> _Kty;
 
    size_t operator()(const _Kty& _Keyval) const
        {   // hash _Keyval to size_t value by pseudorandomizing transform
        return (_Keyval.hash());
        }
    };
 #endif /* _HAS_CPP0X */
_STD_END
 
 #pragma pop_macro("new")
 #pragma warning(pop)
 #pragma pack(pop)
#endif /* RC_INVOKED */
#endif /* _VECTOR_ */
 
/*
 * This file is derived from software bearing the following
 * restrictions:
 *
 * 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) 1992-2012 by P.J. Plauger.  ALL RIGHTS RESERVED.
 * Consult your license regarding permissions and restrictions.
V6.00:0009 */
0
Эксперт по математике/физикеЭксперт С++
2049 / 1367 / 396
Регистрация: 16.05.2013
Сообщений: 3,508
Записей в блоге: 6
08.04.2014, 13:59 16
Лучший ответ Сообщение было отмечено StelSvip как решение

Решение

Попробуйте так:
Кликните здесь для просмотра всего текста
C++
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
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <iterator>
#include <iomanip>
#define BUF_SIZE 50
using std::cout;
using std::cin;
using std::endl;
using std::fstream;
using std::string;
using std::vector;
struct Request {
    char Surname[BUF_SIZE];
    char Destination[BUF_SIZE];
    char Date[BUF_SIZE];
    char FlightNumber[BUF_SIZE];
};
void OutputAll()
{
}
void getDeleteTicket()
{
}
//========================================================================//
//                      Точка входа                                       //
//========================================================================//
void GetAddTicket(Request&);
void Handler(vector<Request>&, int);
int Greeting();
int main()
{
    system("chcp 1251>0");
    fstream file;
    file.open("base.txt");
    if(!file) {
        std::cerr << "Error open file!" << endl;
        exit(1);
    }
    vector<Request> base;
    Request temp;
    vector<Request>::iterator baseIter = base.begin();
    while (!file.eof()) {
        file >> temp.Surname;
        file >> temp.Destination;
        file >> temp.Date;
        file >> temp.FlightNumber;
        base.push_back(temp);
    }
    file.close();
    cout.setf(std::ios::left);
 
    int action = Greeting();
    while(action != 5) {
        Handler(base, action);
        action = Greeting();
    }
    file.open("base.txt");
    baseIter = base.begin();
    vector<Request>::iterator base_end = base.end();
    while (baseIter != base_end) {
        temp = *baseIter;
        file << temp.Surname << endl;
        file << temp.Destination << endl;
        file << temp.Date << endl;
        file << temp.FlightNumber << endl;
        ++baseIter;
    }
    cout << baseIter - base.begin() << endl;
    file.close();
 
    system("pause");
    return 0;
}
void Handler(vector<Request>& base, int number)
{
    Request temp;
    switch(number)
    {
        case 1:
            system("cls");
            char ch;
            do {
                GetAddTicket(temp);
                base.push_back(temp);
                cout << "Продолжить(д/н)? ";
                cin >> ch;
                system("cls");
            } while (ch == 'д');
            break;
        case 2:
            system("cls");
            getDeleteTicket();
            break;
        case 3:
            system("cls");
            system("pause");
            break;
        case 4:
            system("cls");
            vector<Request>::iterator baseIter = base.begin();
            vector<Request>::iterator base_end = base.end();
            cout << "Вывод всех заявок" << endl;
            while (baseIter != base_end) {
                cout << "-------------------------------------------------" << endl;
                cout << std::setw(20) << "Фамилия И.О: "      << baseIter->Surname      << endl;
                cout << std::setw(20) << "Пункт назначения: " << baseIter->Destination  << endl;
                cout << std::setw(20) << "Дата вылета: "      << baseIter->Date         << endl;
                cout << std::setw(20) << "Номер рейса: "      << baseIter->FlightNumber << endl;
                ++baseIter;
            }
            system("pause");
            break;
    }
}
int Greeting()
{
    system("cls");
    cout << "\tПрограмма учета заявок на авиабилеты: " << endl
              << "-------------------------------------------------" << endl
              << "1. Добавление заявок в список. " << endl
              << "2. Удаление заявок." << endl
              << "3. Вывод заявок по заданному номеру рейсу дате вылета. " << endl
              << "4. Вывод всех заявок. " << endl
              << "5. Выход. " << endl
              << "Выберите действие: ";
 
    int number;
    cin >> number;
    return number;
}
void GetAddTicket(Request& request) {
    cout << "Добавление заявки в список. Шаг 1/4" << endl
         << "-------------------------------------------------" << endl
         << "Введите Фамилию И.О. пассажира: ";
    cin >> request.Surname;
    system("cls");
    cout << "Добавление заявки в список. Шаг 2/4" << endl
         << "-------------------------------------------------" << endl
         << "Введите Пункт назначения: ";
    cin >> request.Destination;
    system("cls");
    cout << "Добавление заявки в список. Шаг 3/4" << endl
         << "-------------------------------------------------" << endl
         << "Введите желаемую дату вылета: ";
    cin >> request.Date;
    system("cls");
    cout << "Добавление заявки в список. Шаг 4/4" << endl
         << "-------------------------------------------------" << endl
         << "Введите номер рейса: ";
    cin >> request.FlightNumber;
    system("cls");
    cout << "Запись успешно добавленна!\n";
}
1
0 / 0 / 0
Регистрация: 10.02.2014
Сообщений: 24
08.04.2014, 14:13  [ТС] 17
Ilot, Заработала. В файл добавляется, в столбик, т.е:
Фамилия
Пункт назнач.
дата
номер рейса.
Создается еще пустая запись. т.е пустые поля.
0
Эксперт по математике/физикеЭксперт С++
2049 / 1367 / 396
Регистрация: 16.05.2013
Сообщений: 3,508
Записей в блоге: 6
08.04.2014, 14:16 18
Исправить:
C++
1
2
3
4
        file << temp.Surname << endl;
        file << temp.Destination << endl;
        file << temp.Date << endl;
        file << temp.FlightNumber << endl;
на
C++
1
2
3
4
        file << temp.Surname;
        file << temp.Destination;
        file << temp.Date;
        file << temp.FlightNumber;
1
0 / 0 / 0
Регистрация: 10.02.2014
Сообщений: 24
08.04.2014, 14:22  [ТС] 19
Ilot, Спасибо Вам большое. Буду пытаться понять ее и доработать
0
08.04.2014, 14:22
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
08.04.2014, 14:22
Помогаю со студенческими работами здесь

Программа учета результатов игры в гольф
Напишите программу, которая запрашивает у пользователя 10 результатов игры в гольф, сохраняя их в...

Учет заявок
Здравствуйте. Задали курсовую, нужна помощь в некоторых моментах. Написать программу учета...

Программа учета заявок на авиабилеты
Написать программу учета заявок на авиабилеты. Каждая заявка содержит: пункт назначения, ФИО...

Программа для учета клиентов и заявок
помоги пожалуста, очень срочно, надо написать программу для учета заявок и клиентов, таблицы я...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
19
Ответ Создать тему
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2024, CyberForum.ru