forked from jaege/Cpp-Primer-5th-Exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StrBlob.h
48 lines (35 loc) · 964 Bytes
/
StrBlob.h
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
#ifndef STRBLOB_H
#define STRBLOB_H
class StrBlobPtr;
class ConstStrBlobPtr;
#include <vector>
#include <string>
#include <initializer_list>
#include <memory>
class StrBlob {
friend class StrBlobPtr;
friend class ConstStrBlobPtr;
public:
typedef std::vector<std::string>::size_type size_type;
StrBlob();
StrBlob(std::initializer_list<std::string> il);
size_type size() const { return data->size(); }
bool empty() const { return data->empty(); }
void push_back(const std::string &s);
void pop_back();
std::string &front();
const std::string &front() const;
std::string &back();
const std::string &back() const;
StrBlobPtr begin();
StrBlobPtr end();
ConstStrBlobPtr cbegin() const;
ConstStrBlobPtr cend() const;
private:
std::shared_ptr<std::vector<std::string>> data;
void check(size_type pos, const std::string &msg) const;
};
inline void StrBlob::push_back(const std::string &s) {
data->push_back(s);
}
#endif