… | |
… | |
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 | static void copy_higher (iterator dst, iterator src, size_type n, void (*op)(iterator, iterator) = cop_new) |
103 | // MUST copy forwards |
104 | { |
|
|
105 | if (is_simple_enough ()) |
|
|
106 | memmove (dst, src, sizeof (T) * n); |
|
|
107 | else |
|
|
108 | while (n--) |
|
|
109 | op (dst + n, src + n); |
|
|
110 | } |
|
|
111 | |
|
|
112 | template<class I> |
104 | template<class I> |
113 | static void copy (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) |
114 | { |
106 | { |
115 | while (n--) |
107 | while (n--) |
116 | op (dst++, src++); |
108 | op (dst++, src++); |
… | |
… | |
153 | dealloc (); |
145 | dealloc (); |
154 | buf = nbuf; |
146 | buf = nbuf; |
155 | } |
147 | } |
156 | |
148 | |
157 | construct (buf + sze, n); |
149 | construct (buf + sze, n); |
158 | copy_higher (buf + pos + n, buf + pos, sze - pos, cop_set); |
150 | |
159 | 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); |
160 | } |
159 | } |
161 | |
160 | |
162 | public: |
161 | public: |
163 | size_type capacity () const { return res; } |
162 | size_type capacity () const { return res; } |
164 | size_type size () const { return sze; } |
163 | size_type size () const { return sze; } |