-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
186 lines (129 loc) · 4.39 KB
/
main.cpp
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
#include "box_container.h"
#include <iostream>
using namespace std;
int main(void) {
BoxContainer<int> box1;
cout << box1 << endl;
cout << "--------------------------------" << endl;
BoxContainer box2{15};
cout << box2 << endl;
cout << "--------------------------------" << endl;
BoxContainer box3{1, 2, 3, 4, 5, 6, 7, 8, 9};
cout << box3 << endl;
cout << "--------------------------------" << endl;
BoxContainer box4{box3 + box3 + box2};
cout << box4 << endl;
cout << "--------------------------------" << endl;
BoxContainer box5{box4};
BoxContainer<int> box6;
box6 = box4;
cout << "--------------------------------" << endl;
BoxContainer<int> box7{};
box7 += box1;
cout << box7 << endl;
cout << "--------------------------------" << endl;
box3.removeItem(5);
cout << box3 << endl;
cout << "--------------------------------" << endl;
box3.addItem(5);
cout << box3 << endl;
cout << "--------------------------------" << endl;
box6.removeAll(5);
cout << box6 << endl;
box6.removeAll(5);
cout << box6 << endl;
box6.removeAll(3);
cout << box6 << endl;
cout << "--------------------------------" << endl;
box4 = box2 = box6;
cout << box6 << endl;
cout << box2 << endl;
cout << box4 << endl;
cout << "######################################" << endl;
cout << "######################################" << endl;
cout << "######################################" << endl;
BoxContainer<int> box8{15, 13, 2};
box8.at(2) = 19;
BoxContainer<int> box9{move(box8)};
cout << box8 << endl;
cout << box9 << endl;
cout << "--------------------------------" << endl;
BoxContainer<int> box10{};
box10 = move(box9);
cout << box8 << endl;
cout << box9 << endl;
cout << box10 << endl;
cout << "--------------------------------" << endl;
cout << "######################################" << endl;
cout << "######## work with iterators #########" << endl;
cout << "######################################" << endl;
for(const auto &i : box10) {
cout << i << endl;
}
cout << "--------------------------------" << endl;
BoxContainer box11{15, 31, 99};
const BoxContainer<int> box12{54, 51, 48, 22};
cout << "Forward iteration:" << endl;
for(auto it = box11.begin(); it != box11.end(); ++it) {
cout << *it << " ";
}
cout << endl;
cout << "Forward iteration:" << endl;
for(auto it = box11.cbegin(); it != box11.cend(); ++it) {
cout << *it << " ";
}
cout << endl;
cout << "Const forward iteration:" << endl;
for(auto it = box12.begin(); it != box12.end(); ++it) {
cout << *it << " ";
}
cout << endl;
cout << "Reverse iteration:" << endl;
for(auto it = box11.rbegin(); it != box11.rend(); ++it) {
cout << *it << " ";
}
cout << endl;
cout << "Const reverse iteration:" << endl;
for(auto it = box11.crbegin(); it != box11.crend(); ++it) {
cout << *it << " ";
}
cout << endl;
cout << "Const reverse iteration:" << endl;
for(auto it = box12.rbegin(); it != box12.rend(); ++it) {
cout << *it << " ";
}
cout << endl;
cout << "######################################" << endl;
cout << "######################################" << endl;
cout << "######################################" << endl;
BoxContainer box13{1, 5, 3, 1, 9};
cout << box13.front() << endl;
cout << box13.back() << endl;
box13.push_back(15);
cout << box13 << endl;
cout << box13.pop_back() << endl;
cout << box13 << endl;
box13.insert(box13.begin() + 2, 47);
cout << box13 << endl;
cout << "Empty: " << box13.empty() << endl;
box13.clear();
cout << "Empty: " << box13.empty() << endl;
cout << box13.data() << endl;
box13.push_back(15);
cout << box13.data()[0] << endl;
BoxContainer<int> box14{15, 13};
BoxContainer<int> box15{33, 15, 12};
cout << box14 << endl;
cout << box15 << endl;
box14.swap(box15);
cout << box14 << endl;
cout << box15 << endl;
cout << box14.contains(12) << endl;
cout << box14.contains(13) << endl;
// Ability to be used with STL containers
BoxContainer<int> box16{19, 33, 15, 16, 12};
cout << box16 << endl;
ranges::sort(box16);
cout << box16 << endl;
return 0;
}