Skip to content

Commit 9eccc57

Browse files
author
Jaege
committedFeb 24, 2016
Add soultions to second half of exercises in chapter 14.
1 parent b02929b commit 9eccc57

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+3244
-5
lines changed
 

‎README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,11 @@ This repo is the solutions to exercises in book [_C++ Primer_ (5th Edition)](htt
132132

133133
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10
134134
--:|--:|--:|--:|--:|--:|--:|--:|--:|--:
135-
[1](ch14/14.1.cpp)|[2](ch14/14.2.cpp)|[3](ch14/14.3.cpp)|[4](ch14/14.4.cpp)|[5](ch14/14.5.cpp)|[6](ch14/14.6.cpp)|[7](ch14/14.7.cpp)|[8](ch14/14.8.cpp)|[9](ch14/14.9.cpp)|[10](ch14/14.10.cpp)|
136-
[11](ch14/14.11.cpp)|[12](ch14/14.12.cpp)|[13](ch14/14.13.cpp)|[14](ch14/14.14.cpp)|[15](ch14/14.15.cpp)|[16](ch14/14.16.cpp)|[17](ch14/14.17.cpp)|[18](ch14/14.18.cpp)|[19](ch14/14.19.cpp)|[20](ch14/14.20.cpp)|
137-
[21](ch14/14.21.cpp)|[22](ch14/14.22.cpp)|[23](ch14/14.23.cpp)|[24](ch14/14.24.cpp)|[25](ch14/14.25.cpp)|[26](ch14/14.26.cpp)|[27](ch14/14.27.cpp)|[28](ch14/14.28.cpp)|[29](ch14/14.29.cpp)|[30](ch14/14.30.cpp)|
138-
[31](ch14/14.31.cpp)|[32](ch14/14.32.cpp)|[33](ch14/14.33.cpp)|[34](ch14/14.34.cpp)|[35](ch14/14.35.cpp)|[36](ch14/14.36.cpp)|[37](ch14/14.37.cpp)|[38](ch14/14.38.cpp)|[39](ch14/14.39.cpp)|[40](ch14/14.40.cpp)|
139-
[41](ch14/14.41.cpp)|[42](ch14/14.42.cpp)|[43](ch14/14.43.cpp)|[44](ch14/14.44.cpp)|[45](ch14/14.45.cpp)|[46](ch14/14.46.cpp)|[47](ch14/14.47.cpp)|[48](ch14/14.48.cpp)|[49](ch14/14.49.cpp)|[50](ch14/14.50.cpp)|
135+
[1](ch14/14.1.md)|[2](ch14/14.2.cpp)|[3](ch14/14.3.md)|[4](ch14/14.4.md)|[5](ch14/14.5.md)|[6](ch14/14.6.cpp)|[7](ch14/14.7)|[8](ch14/14.8.md)|[9](ch14/14.9.cpp)|[10](ch14/14.10.md)|
136+
[11](ch14/14.11.md)|[12](ch14/14.12.md)|[13](ch14/14.13.cpp)|[14](ch14/14.14.md)|[15](ch14/14.15.md)|[16](ch14/14.16)|[17](ch14/14.17.md)|[18](ch14/14.18)|[19](ch14/14.19.md)|[20](ch14/14.20.md)|
137+
[21](ch14/14.21.cpp)|[22](ch14/14.22.cpp)|[23](ch14/14.23)|[24](ch14/14.24.md)|[25](ch14/14.25.md)|[26](ch14/14.26)|[27](ch14/14.27)|[28](ch14/14.28)|[29](ch14/14.29.md)|[30](ch14/14.30)|
138+
[31](ch14/14.31.md)|[32](ch14/14.32)|[33](ch14/14.33.md)|[34](ch14/14.34.cpp)|[35](ch14/14.35.cpp)|[36](ch14/14.36.md)|[37](ch14/14.37.cpp)|[38](ch14/14.38.cpp)|[39](ch14/14.39.cpp)|[40](ch14/14.40.cpp)|
139+
[41](ch14/14.41.md)|[42](ch14/14.42.cpp)|[43](ch14/14.43.cpp)|[44](ch14/14.44.cpp)|[45](ch14/14.45.cpp)|[46](ch14/14.46.md)|[47](ch14/14.47.md)|[48](ch14/14.48.md)|[49](ch14/14.49.md)|[50](ch14/14.50.cpp)|
140140
[51](ch14/14.51.cpp)|[52](ch14/14.52.cpp)|[53](ch14/14.53.cpp)
141141

142142
<!---

‎ch14/14.27/ConstStrBlobPtr.cpp

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#include "ConstStrBlobPtr.h"
2+
#include "StrBlob.h"
3+
4+
ConstStrBlobPtr::ConstStrBlobPtr() : wptr(), curr(0) {}
5+
ConstStrBlobPtr::ConstStrBlobPtr(const StrBlob &sb, size_type pos)
6+
: wptr(sb.data), curr(pos) {}
7+
8+
std::shared_ptr<std::vector<std::string>>
9+
ConstStrBlobPtr::check(size_type pos, const std::string &msg) const {
10+
auto ret = wptr.lock();
11+
if (!ret)
12+
throw std::runtime_error("unbound ConstStrBlobPtr");
13+
if (pos >= ret->size())
14+
throw std::out_of_range(msg);
15+
return ret;
16+
}
17+
18+
const std::string &ConstStrBlobPtr::deref() const {
19+
auto sp = check(curr, "deference past end of ConstStrBlobPtr");
20+
return (*sp)[curr];
21+
}
22+
23+
//ConstStrBlobPtr &ConstStrBlobPtr::inc() {
24+
// check(curr, "increment past end of ConstStrBlobPtr");
25+
// ++curr;
26+
// return *this;
27+
//}
28+
29+
ConstStrBlobPtr &ConstStrBlobPtr::operator++() {
30+
check(curr, "increment past end of ConstStrBlobPtr");
31+
++curr;
32+
return *this;
33+
}
34+
35+
ConstStrBlobPtr ConstStrBlobPtr::operator++(int) {
36+
auto ret = *this;
37+
++*this;
38+
return ret;
39+
}
40+
41+
ConstStrBlobPtr &ConstStrBlobPtr::operator--() {
42+
--curr;
43+
check(curr, "decrement past begin of ConstStrBlobPtr");
44+
return *this;
45+
}
46+
47+
ConstStrBlobPtr ConstStrBlobPtr::operator--(int) {
48+
auto ret = *this;
49+
--*this;
50+
return ret;
51+
}
52+
53+
bool operator==(const ConstStrBlobPtr &lhs, const ConstStrBlobPtr &rhs) {
54+
// compare identity
55+
return lhs.wptr.lock() == rhs.wptr.lock() && lhs.curr == rhs.curr;
56+
}
57+
58+
bool operator!=(const ConstStrBlobPtr &lhs, const ConstStrBlobPtr &rhs) {
59+
return !(lhs == rhs);
60+
}
61+
62+
bool operator<(const ConstStrBlobPtr &lhs, const ConstStrBlobPtr &rhs) {
63+
return lhs.wptr.lock() == rhs.wptr.lock() && lhs.curr < rhs.curr;
64+
}
65+
66+
bool operator>(const ConstStrBlobPtr &lhs, const ConstStrBlobPtr &rhs) {
67+
return rhs < lhs;
68+
}
69+
70+
bool operator<=(const ConstStrBlobPtr &lhs, const ConstStrBlobPtr &rhs) {
71+
return !(lhs > rhs);
72+
}
73+
74+
bool operator>=(const ConstStrBlobPtr &lhs, const ConstStrBlobPtr &rhs) {
75+
return !(lhs < rhs);
76+
}

0 commit comments

Comments
 (0)
Please sign in to comment.