… | |
… | |
98 | template<class I> |
98 | template<class I> |
99 | static void cop_new (iterator a, I b) { new (a) T (*b); } |
99 | static void cop_new (iterator a, I b) { new (a) T (*b); } |
100 | template<class I> |
100 | template<class I> |
101 | static void cop_set (iterator a, I b) { *a = *b ; } |
101 | static void cop_set (iterator a, I b) { *a = *b ; } |
102 | |
102 | |
|
|
103 | // MUST copy forwards |
103 | template<class I> |
104 | template<class I> |
104 | static void copy_lower (iterator dst, I src, size_type n, void (*op)(iterator, I ) = cop_new) |
105 | static void copy (iterator dst, I src, size_type n, void (*op)(iterator, I) = cop_new) |
105 | { |
106 | { |
106 | while (n--) |
107 | while (n--) |
107 | op (dst++, src++); |
108 | op (dst++, src++); |
108 | } |
|
|
109 | |
|
|
110 | static void copy_lower (iterator dst, iterator src, size_type n, void (*op)(iterator, iterator) = cop_new) |
|
|
111 | { |
|
|
112 | if (is_simple_enough ()) |
|
|
113 | memmove (dst, src, sizeof (T) * n); |
|
|
114 | else |
|
|
115 | copy_lower<iterator> (dst, src, n, cop_new); |
|
|
116 | } |
|
|
117 | |
|
|
118 | static void copy_higher (iterator dst, iterator src, size_type n, void (*op)(iterator, iterator) = cop_new) |
|
|
119 | { |
|
|
120 | if (is_simple_enough ()) |
|
|
121 | memmove (dst, src, sizeof (T) * n); |
|
|
122 | else |
|
|
123 | while (n--) |
|
|
124 | op (dst + n, src + n); |
|
|
125 | } |
|
|
126 | |
|
|
127 | template<class I> |
|
|
128 | static void copy (iterator dst, I src, size_type n, void (*op)(iterator, I) = cop_new) |
|
|
129 | { |
|
|
130 | copy_lower<I> (dst, src, n, op); |
|
|
131 | } |
109 | } |
132 | |
110 | |
133 | static void copy (iterator dst, iterator src, size_type n, void (*op)(iterator, iterator) = cop_new) |
111 | static void copy (iterator dst, iterator src, size_type n, void (*op)(iterator, iterator) = cop_new) |
134 | { |
112 | { |
135 | if (is_simple_enough ()) |
113 | if (is_simple_enough ()) |
… | |
… | |
167 | dealloc (); |
145 | dealloc (); |
168 | buf = nbuf; |
146 | buf = nbuf; |
169 | } |
147 | } |
170 | |
148 | |
171 | construct (buf + sze, n); |
149 | construct (buf + sze, n); |
172 | copy_higher (buf + pos + n, buf + pos, sze - pos, cop_set); |
150 | |
173 | sze += n; |
151 | sze += n; |
|
|
152 | |
|
|
153 | iterator src = buf + pos; |
|
|
154 | if (is_simple_enough ()) |
|
|
155 | memmove (src + n, src, sizeof (T) * n); |
|
|
156 | else |
|
|
157 | for (size_type i = n; i--; ) |
|
|
158 | op (src + n + i, src + i); |
174 | } |
159 | } |
175 | |
160 | |
176 | public: |
161 | public: |
177 | size_type capacity () const { return res; } |
162 | size_type capacity () const { return res; } |
178 | size_type size () const { return sze; } |
163 | size_type size () const { return sze; } |
… | |
… | |
338 | |
323 | |
339 | void erase (iterator first, iterator last) |
324 | void erase (iterator first, iterator last) |
340 | { |
325 | { |
341 | size_t n = last - first; |
326 | size_t n = last - first; |
342 | |
327 | |
343 | copy_lower (last, first, end () - last, cop_set); |
328 | if (is_simple_enough ()) |
|
|
329 | memmove (first, last, sizeof (T) * n); |
|
|
330 | else |
|
|
331 | copy<iterator> (first, last, n, cop_new); |
|
|
332 | |
344 | sze -= n; |
333 | sze -= n; |
345 | destruct (buf + sze, n); |
334 | destruct (buf + sze, n); |
346 | } |
335 | } |
347 | |
336 | |
348 | void erase (iterator pos) |
337 | void erase (iterator pos) |