Sub*_*way 4 c++ containers iterator erase
在下面的循环中,我使用的是预先计算的结束迭代器:
std::list::iterator end = MyList.end();
for (std::list::iterator it = MyList.begin(); it != end ;)
it = MyList.erase(it);
Run Code Online (Sandbox Code Playgroud)
当擦除std :: list中的元素时,MyList.end()是否可以更改其值以便更新end != MyList.end()?
没有.
n3376 23.3.5.4
Run Code Online (Sandbox Code Playgroud)iterator erase(const_iterator position); iterator erase(const_iterator first, const_iterator last);效果:仅使迭代器和对已擦除元素的引用无效.
| 归档时间: |
|
| 查看次数: |
370 次 |
| 最近记录: |