是C ++迭代器“安全”吗? [英] Are C++ iterators "safe"?

查看:174
本文介绍了是C ++迭代器“安全”吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了C ++列表迭代器的文档,但无法弄清楚一件事:C ++迭代器是否安全?我的意思是,一旦到达列表中最后一个元素,它是否停止递增?

I have read the documentation for C++ list iterators, but couldn't figure out one thing: are C++ iterators "safe"? I mean, does it stop incrementing once it reaches the last existing element in a list?

[]'

推荐答案

不,他们不是安全的意思。可以增加迭代器超过结束。对于标准库中的所有迭代器,这将导致未定义的行为。你可以定义自己的迭代器,如果你想要的话,它会以安全的方式表现。

No, they're not "safe" in that sense. It is possible to increment an iterator past the end. For all the iterators in the standard library doing this will result in undefined behaviour. You could define your own iterators that do behave in a safe way instead if you wanted to.

这篇关于是C ++迭代器“安全”吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆