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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
| void resize(size_type _N, const _Ty& _X = _Ty()) {if (size() < _N) insert(end(), _N - size(), _X); else if (_N < size()) erase(begin() + _N, end()); } size_type size() const {return (_First == 0 ? 0 : _Last - _First); }
bool empty() const {return (size() == 0); }
reference operator[](size_type _P) {return (*(begin() + _P)); }
void push_back(const _Ty& _X) {insert(end(), _X); } void pop_back() {erase(end() - 1); }
iterator insert(iterator _P, const _Ty& _X = _Ty()) {size_type _O = _P - begin(); insert(_P, 1, _X); return (begin() + _O); } void insert(iterator _P, size_type _M, const _Ty& _X) {if (_End - _Last < _M) {size_type _N = size() + (_M < size() ? size() : _M); iterator _S = allocator.allocate(_N, (void *)0); iterator _Q = _Ucopy(_First, _P, _S); _Ufill(_Q, _M, _X); _Ucopy(_P, _Last, _Q + _M); _Destroy(_First, _Last); allocator.deallocate(_First, _End - _First); _End = _S + _N; _Last = _S + size() + _M; _First = _S; } else if (_Last - _P < _M) {_Ucopy(_P, _Last, _P + _M); _Ufill(_Last, _M - (_Last - _P), _X); fill(_P, _Last, _X); _Last += _M; } else if (0 < _M) {_Ucopy(_Last - _M, _Last, _Last); copy_backward(_P, _Last - _M, _Last); fill(_P, _P + _M, _X); _Last += _M; }} void insert(iterator _P, _It _F, _It _L) {size_type _M = 0; _Distance(_F, _L, _M); if (_End - _Last < _M) {size_type _N = size() + (_M < size() ? size() : _M); iterator _S = allocator.allocate(_N, (void *)0); iterator _Q = _Ucopy(_First, _P, _S); _Q = _Ucopy(_F, _L, _Q); _Ucopy(_P, _Last, _Q); _Destroy(_First, _Last); allocator.deallocate(_First, _End - _First); _End = _S + _N; _Last = _S + size() + _M; _First = _S; } else if (_Last - _P < _M) {_Ucopy(_P, _Last, _P + _M); _Ucopy(_F + (_Last - _P), _L, _Last); copy(_F, _F + (_Last - _P), _P); _Last += _M; } else if (0 < _M) {_Ucopy(_Last - _M, _Last, _Last); copy_backward(_P, _Last - _M, _Last); copy(_F, _L, _P); _Last += _M; }} iterator erase(iterator _P) {copy(_P + 1, end(), _P); _Destroy(_Last - 1, _Last); --_Last; return (_P); } iterator erase(iterator _F, iterator _L) {iterator _S = copy(_L, end(), _F); _Destroy(_S, end()); _Last = _S; return (_F); } void clear() {erase(begin(), end()); }
protected: void _Destroy(iterator _F, iterator _L) {for (; _F != _L; ++_F) allocator.destroy(_F); } iterator _Ucopy(const_iterator _F, const_iterator _L, iterator _P) {for (; _F != _L; ++_P, ++_F) allocator.construct(_P, *_F); return (_P); } void _Ufill(iterator _F, size_type _N, const _Ty &_X) {for (; 0 < _N; --_N, ++_F) allocator.construct(_F, _X); } void _Xran() const {_THROW(out_of_range, "invalid vector<T> subscript"); }
size_type capacity() const {return (_First == 0 ? 0 : _End - _First); }
|