开发者

Is it safe to store pointer of STL list iterator?

开发者 https://www.devze.com 2023-04-13 10:07 出处:网络
I know any insert or remove operations of STL list never invalidate their iterator. However, I\'m not sure whether list still preserves iterator itself or not.

I know any insert or remove operations of STL list never invalidate their iterator. However, I'm not sure whether list still preserves iterator itself or not.

So, can I store pointer of list iter开发者_Python百科ator and use it later?


For an std::list:

In case of Insertion,
All iterators and references unaffected [23.2.2.3/1]

In case of Erase,
Only the iterators and references to the erased element get invalidated [23.2.2.3/3]

So, Its safe as long as you erase an element and don't use its stored Iterator.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号