void C_vector_any::_Clear(){ for(int i=used_size; i--; ) _Destruct(array + i*elem_size); used_size = 0; _Reserve(res_size); }
void emplace_back(_Valty&& _Val) { // insert element at end if (this->_Mylast == this->_Myend) _Reserve(1); _Orphan_range(this->_Mylast, this->_Mylast); _Cons_val(this->_Alval, this->_Mylast, _STD forward<_Valty>(_Val)); ++this->_Mylast; }
void resize(size_type _Newsize) { // determine new length, padding with _Ty() elements as needed if (_Newsize < size()) erase(begin() + _Newsize, end()); else if (size() < _Newsize) { // pad as needed _Reserve(_Newsize - size()); _Uninitialized_default_fill_n(this->_Mylast, _Newsize - size(), (_Ty *)0, this->_Alval); this->_Mylast += _Newsize - size(); } }
void C_vector_any::_CopyVector(const C_vector_any &v){ if(this==&v) return; _Clear(); int i = v.used_size; _Reserve(i); used_size = i; while(i--){ int offs = i*elem_size; _Construct(array+offs); _Copy(array+offs, v.array + offs); } }
void push_back(const _Ty& _Val) { // insert element at end if (_Inside(_STD addressof(_Val))) { // push back an element size_type _Idx = _STD addressof(_Val) - this->_Myfirst; if (this->_Mylast == this->_Myend) _Reserve(1); _Orphan_range(this->_Mylast, this->_Mylast); _Cons_val(this->_Alval, this->_Mylast, this->_Myfirst[_Idx]); ++this->_Mylast; } else { // push back a non-element if (this->_Mylast == this->_Myend) _Reserve(1); _Orphan_range(this->_Mylast, this->_Mylast); _Cons_val(this->_Alval, this->_Mylast, _Val); ++this->_Mylast; } }
void C_vector_any::_Resize(dword n, const void *val){ if(n<used_size){ byte *ptr = (byte*)_End(); for(int i=used_size-n; i--; ){ ptr -= elem_size; _Destruct(ptr); } used_size = n; }else{ _Reserve(n); while(used_size<n) _PushBack(val); } }
void C_vector_any::_Insert(dword dst_i, const void *src, dword num){ if(!num) return; assert(dst_i <= (dword)used_size); _Reserve(used_size+num); used_size += num; for(int i=used_size-num-dst_i; i--; ) MemCpy(_At(dst_i+num+i), _At(dst_i+i), elem_size); byte *dst = (byte*)_At(dst_i); for(dword i=0; i<num; i++, dst += elem_size, src = (byte*)src+elem_size){ _Construct(dst); _Copy(dst, src); } }