一.vector
所有读操作、swap、std::swap:都不会引起迭代器失效...
clear、operator=、assign:都会引起全部变量迭代器失效
reserve、shrink_to_fit:如果capacity的大小被改变了,则引起全部变量迭代器失效
erase:被删除的变量以及其后面的变量包括end()都迭代器失效
push_back、emplace_back:假如capacity的大小被改变,则引起全部变量迭代器失效。否则只是end()迭代器失效
insert、emplace、resize:假如capacity的大小被改变,则引起全部变量迭代器失效。否则只是在插入位置后面的变量迭代器失效
pop_back:被删除的变量以及end()迭代器失效
二.deque(没有发生删除且只插入在末尾,指针和引用不失效)
All read only operations | Never |
, | The past-the-end iterator may be invalidated (implementation defined) |
, , , , , , , | Always |
If erasing at begin - only erased elements If erasing at end - only erased elements and the past-the-end iterator Otherwise - all iterators are invalidated (including the past-the-end iterator). | |
If the new size is smaller than the old one : only erased elements and the past-the-end iterator If the new size is bigger than the old one : all iterators are invalidated Otherwise - none iterators are invalidated. | |
Only to the element erased | |
Only to the element erased and the past-the-end iterator |
Invalidation notes
-
- When inserting at either end of the deque, references are not invalidated by and .
- , , and do not invalidate any references to elements of the deque.
- When erasing at either end of the deque, references to non-erased elements are not invalidated by , and .
- A call to with a smaller size does not invalidate any references to non-erased elements.
- A call to with a bigger size does not invalidate any references to elements of the deque.