I would like to know if the ordering of the elements of a std::vector container is always preserved after erasing an arbitrary element (for example: push 0,1,2,3, erase 1, get 0,2,3).
问问题
775 次
I would like to know if the ordering of the elements of a std::vector container is always preserved after erasing an arbitrary element (for example: push 0,1,2,3, erase 1, get 0,2,3).
是的。还要注意复杂性(§ 23.3.6.5):
复杂度:T的析构函数被称为等于被擦除元素个数的次数,而T的移动赋值运算符被称为等于被擦除元素之后向量中元素个数的次数。
和迭代器失效:
效果:在擦除点或擦除点之后使迭代器和引用无效。
如果您不想通过标准查看这些细节并且没有信心,请查看此参考站点。