| 277 | Alloc _allocator; |
| 278 | |
| 279 | void expand() |
| 280 | { |
| 281 | int size = _end - _first; |
| 282 | T *ptmp = _allocator.allocate(2 * size); // 分配 2*size 大小内存 |
| 283 | int len = _last - _first; |
| 284 | for (int i = 0; i < size; ++ i) { // 构造 size 个有效的T对象 |
| 285 | _allocator.construct(ptmp + i, _first[i]); |
| 286 | } |
| 287 | |
| 288 | // 先析构再free |
| 289 | for (T *p = _first; p != _last; ++ p) { |
| 290 | _allocator.destroy(p); |
| 291 | } |
| 292 | _allocator.deallocate(_first); |
| 293 | _first = ptmp; |
| 294 | _last = _first + size; |
| 295 | _end = _first + 2 * size; |
| 296 | } |
| 297 | }; |
| 298 | |
| 299 | /* 测试类 */ |
nothing calls this directly
no test coverage detected