关于 vector push_back 实现

void StrVec::reallocate()
{
    auto newcapacity=size()?2*size():1;
    auto newdata=alloc.allocate(newcapacity);
    auto dest=newdata;
    auto elem=elements;
    for(size_t i=0;i!=size();i++)
    {
        alloc.construct(dest++,std::move(*elem++));

    }
    free();
    elements=newdata;
    first_free=dest;
    cap=elements+newcapacity;
}


你可能感兴趣的:(关于 vector push_back 实现)