![](/img/trans.png)
[英]Why does std::vector::insert invalidate all iterators after the insertion point
[英]std::deque : What does “insertion and deletion of elements may invalidate iterators” mean?
我正在閱讀有關std :: deque容器的內容,文檔說明了這一點
在std :: deque中插入和刪除元素可能會使其所有迭代器無效
以下是我對上述陳述的理解版本,如果我誤解了陳述或遺漏了某些內容,請告訴我
請考慮以下代碼
std::deque<int> s;
s.push_back(12);
auto i = s.begin();
s.push_front(45);//After pushing 45 at the back now `i` may be invalid.
這種理解是否正確?
你是對的。 例如之后
std::deque<int> s;
s.push_back(12);
auto i = s.begin();
s.push_front(45)
調用*i
是未定義的行為。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.