-
Notifications
You must be signed in to change notification settings - Fork 246
/
13.55.cpp
94 lines (78 loc) · 2.2 KB
/
13.55.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
#include <iostream>
#include "StrBlob.h"
#include "StrBlobPtr.h"
void testStrBlob(StrBlob &sb) {
try {
sb.push_back("abc");
std::cout << "front: " << sb.front() << " back: " << sb.back() << std::endl;
sb.pop_back();
std::cout << "front: " << sb.front() << " back: " << sb.back() << std::endl;
sb.begin().deref() = "Change";
for (auto p = sb.begin(); ; p.inc())
std::cout << "deref: " << p.deref() << std::endl;
} catch (std::out_of_range err) {
std::cerr << err.what() << " out of range" << std::endl;
} catch (std::exception err) {
std::cerr << err.what() << std::endl;
}
}
void testStrBlob(const StrBlob &sb) {
try {
std::cout << "front: " << sb.front() << " back: " << sb.back() << std::endl;
} catch (std::out_of_range err) {
std::cerr << err.what() << " out of range" << std::endl;
} catch (std::exception err) {
std::cerr << err.what() << std::endl;
}
}
void testStrBlobPtr(StrBlobPtr &sbp) {
try {
sbp.deref() = "Change2";
for (auto p = sbp; ; p.inc())
std::cout << "deref: " << p.deref() << std::endl;
} catch (std::out_of_range err) {
std::cerr << err.what() << " out of range" << std::endl;
} catch (std::exception err) {
std::cerr << err.what() << std::endl;
}
}
int main() {
StrBlob sb1;
testStrBlob(sb1);
std::cout << std::endl;
StrBlob sb2{"Hello", "World"};
testStrBlob(sb2);
std::cout << std::endl;
StrBlob sb3{"ABC", "DEF"};
StrBlob sb4 = sb3;
sb4.push_back("GHI");
testStrBlob(sb3);
std::cout << std::endl;
testStrBlob(sb4);
std::cout << std::endl;
const StrBlob csb1;
testStrBlob(csb1);
std::cout << std::endl;
const StrBlob csb2{"This", "Blob"};
testStrBlob(csb2);
std::cout << std::endl;
testStrBlob({"ppp", "qqq"});
std::cout << std::endl;
//testStrBlob({"mm", 1}); // Error
StrBlobPtr sbp1;
testStrBlobPtr(sbp1);
std::cout << std::endl;
StrBlobPtr sbp2(sb1);
testStrBlobPtr(sbp2);
std::cout << std::endl;
StrBlobPtr sbp3(sb1, sb1.size());
testStrBlobPtr(sbp3);
std::cout << std::endl;
StrBlobPtr sbp4(sb2);
testStrBlobPtr(sbp4);
std::cout << std::endl;
StrBlobPtr sbp5(sb2, sb2.size());
testStrBlobPtr(sbp5);
std::cout << std::endl;
return 0;
}