forked from jaege/Cpp-Primer-5th-Exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestStrVec.cpp
75 lines (62 loc) · 2.22 KB
/
TestStrVec.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
#include <iostream>
#include "StrVec.h"
void print(const StrVec &sv) {
std::cout << "<" << &sv << "> size: " << sv.size()
<< " capacity: " << sv.capacity() << " contents:";
for (const auto &s : sv)
std::cout << " <" << s << ">";
std::cout << std::endl;
}
int main() {
StrVec sv;
print(sv);
sv.push_back("s1"); print(sv);
sv.push_back("s2"); print(sv);
sv.push_back("s3"); print(sv);
sv.push_back("s4"); print(sv);
sv.push_back("s5"); print(sv);
{
StrVec sv2(sv); print(sv2);
sv2.push_back("s6"); print(sv); print(sv2);
sv.pop_back(); print(sv); print(sv2);
sv = std::move(sv2); print(sv); print(sv2);
}
sv.reserve(sv.capacity() / 2); print(sv);
sv.reserve(sv.capacity() * 2); print(sv);
sv.resize(sv.size() + 2); print(sv);
sv.resize(sv.size() + 2, "s7"); print(sv);
sv.resize(sv.size() - 2); print(sv);
sv.resize(sv.size() - 2, "s7"); print(sv);
sv = { "il1", "il2", "il3", "il4", "il5" }; print(sv);
StrVec sv2 { "il1", "il2", "il3", "il4", "il5" }; print(sv2);
StrVec sv3 = { "il1", "il2", "il3", "il4", "il5" }; print(sv3);
std::cout << (sv2 == sv3) << std::endl; // true
StrVec *p1 = &sv3, *p2 = &sv3;
std::cout << (*p1 == *p2) << std::endl; // true
std::cout << std::endl;
{
StrVec vs1{"a", "b", "c"};
StrVec vs2{"b", "b", "c"};
StrVec vs3{"a", "b", "d"};
StrVec vs4{"a", "b", "c", "a"};
StrVec vs5{"a0", "b", "c"};
StrVec vs6{"a", "c"};
StrVec vs7{"a", "b", "c"};
StrVec vs8{"a", "b"};
std::cout << (vs1 < vs2) << std::endl; // true
std::cout << (vs1 < vs3) << std::endl; // true
std::cout << (vs1 < vs4) << std::endl; // true
std::cout << (vs1 < vs5) << std::endl; // true
std::cout << (vs1 < vs6) << std::endl; // true
std::cout << (vs1 < vs7) << std::endl; // false
std::cout << (vs1 < vs8) << std::endl; // false
std::cout << (vs1 > vs2) << std::endl; // false
std::cout << (vs1 > vs3) << std::endl; // false
std::cout << (vs1 > vs4) << std::endl; // false
std::cout << (vs1 > vs5) << std::endl; // false
std::cout << (vs1 > vs6) << std::endl; // false
std::cout << (vs1 > vs7) << std::endl; // false
std::cout << (vs1 > vs8) << std::endl; // true
}
return 0;
}