forked from Mooophy/Cpp-Primer
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ex14_07.h
34 lines (27 loc) · 789 Bytes
/
ex14_07.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
#ifndef CP5_CH14_EX07_H_
#define CP5_CH14_EX07_H_
#include <memory>
#include <iostream>
class String
{
friend std::ostream& operator<<(std::ostream&, const String&);
public:
String() : String("") { }
String(const char *);
String(const String&);
String& operator=(const String&);
~String();
const char *c_str() const { return elements; }
size_t size() const { return end - elements; }
size_t length() const { return end - elements - 1; }
private:
std::pair<char*, char*> alloc_n_copy(const char*, const char*);
void range_initializer(const char*, const char*);
void free();
private:
char *elements;
char *end;
std::allocator<char> alloc;
};
std::ostream& operator<<(std::ostream&, const String&);
#endif //CP5_CH14_EX07_H_