-
Notifications
You must be signed in to change notification settings - Fork 3k
/
ex13_49_String.h
38 lines (31 loc) · 769 Bytes
/
ex13_49_String.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
#ifndef CP5_STRING_H__
#define CP5_STRING_H__
#include <memory>
#ifndef _MSC_VER
#define NOEXCEPT noexcept
#else
#define NOEXCEPT
#endif
class String
{
public:
String() : String("") { }
String(const char *);
String(const String&);
String& operator=(const String&);
String(String &&) NOEXCEPT;
String& operator=(String&&)NOEXCEPT;
~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;
};
#endif