|
20 | 20 |
|
21 | 21 | class String
|
22 | 22 | {
|
23 |
| - friend std::ostream& operator<<(std::ostream&, const String&); |
24 |
| - friend std::istream& operator>>(std::istream&, String&); |
25 |
| - friend bool operator==(const String&, const String&); |
26 |
| - friend bool operator!=(const String&, const String&); |
27 |
| - friend bool operator< (const String&, const String&); |
28 |
| - friend bool operator> (const String&, const String&); |
29 |
| - friend bool operator<=(const String&, const String&); |
30 |
| - friend bool operator>=(const String&, const String&); |
| 23 | + friend std::ostream& operator<<(std::ostream&, const String&); |
| 24 | + friend std::istream& operator>>(std::istream&, String&); |
| 25 | + friend bool operator==(const String&, const String&); |
| 26 | + friend bool operator!=(const String&, const String&); |
| 27 | + friend bool operator< (const String&, const String&); |
| 28 | + friend bool operator> (const String&, const String&); |
| 29 | + friend bool operator<=(const String&, const String&); |
| 30 | + friend bool operator>=(const String&, const String&); |
31 | 31 |
|
32 | 32 | public:
|
33 |
| - String() : String("") {} |
34 |
| - String(const char *); |
35 |
| - String(const String&); |
36 |
| - String& operator=(const String&); |
37 |
| - String(String &&) NOEXCEPT; |
38 |
| - String& operator=(String&&) NOEXCEPT; |
39 |
| - ~String(); |
| 33 | + String() : String("") {} |
| 34 | + String(const char *); |
| 35 | + String(const String&); |
| 36 | + String& operator=(const String&); |
| 37 | + String(String &&) NOEXCEPT; |
| 38 | + String& operator=(String&&)NOEXCEPT; |
| 39 | + ~String(); |
40 | 40 |
|
41 |
| - void push_back(const char); |
| 41 | + void push_back(const char); |
42 | 42 |
|
43 |
| - char* begin() const { return elements; } |
44 |
| - char* end() const { return last_elem; } |
| 43 | + char* begin() const { return elements; } |
| 44 | + char* end() const { return last_elem; } |
45 | 45 |
|
46 |
| - const char *c_str() const { return elements; } |
47 |
| - size_t size() const { return last_elem - elements; } |
48 |
| - size_t length() const { return size(); } |
49 |
| - size_t capacity() const { return cap - elements; } |
| 46 | + const char *c_str() const { return elements; } |
| 47 | + size_t size() const { return last_elem - elements; } |
| 48 | + size_t length() const { return size(); } |
| 49 | + size_t capacity() const { return cap - elements; } |
50 | 50 |
|
51 |
| - void reserve(size_t); |
52 |
| - void resize(size_t); |
53 |
| - void resize(size_t, char); |
| 51 | + void reserve(size_t); |
| 52 | + void resize(size_t); |
| 53 | + void resize(size_t, char); |
54 | 54 |
|
55 | 55 | private:
|
56 |
| - std::pair<char*, char*> alloc_n_copy(const char*, const char*); |
57 |
| - void range_initializer(const char*, const char*); |
58 |
| - void free(); |
59 |
| - void reallocate(); |
60 |
| - void alloc_n_move(size_t new_cap); |
61 |
| - void chk_n_alloc() { if (first_free == cap) reallocate(); } |
| 56 | + std::pair<char*, char*> alloc_n_copy(const char*, const char*); |
| 57 | + void range_initializer(const char*, const char*); |
| 58 | + void free(); |
| 59 | + void reallocate(); |
| 60 | + void alloc_n_move(size_t new_cap); |
| 61 | + void chk_n_alloc() { if (first_free == cap) reallocate(); } |
62 | 62 |
|
63 | 63 | private:
|
64 |
| - char *elements; |
65 |
| - char *last_elem; |
66 |
| - char *first_free; |
67 |
| - char *cap; |
68 |
| - std::allocator<char> alloc; |
| 64 | + char *elements; |
| 65 | + char *last_elem; |
| 66 | + char *first_free; |
| 67 | + char *cap; |
| 68 | + std::allocator<char> alloc; |
69 | 69 | };
|
70 | 70 |
|
71 | 71 | std::ostream& operator<<(std::ostream&, const String&);
|
|
0 commit comments