STL图迭代器可以通过递增超出边界吗? [英] Can an STL map iterator go out of bounds through incrementing?

查看:126
本文介绍了STL图迭代器可以通过递增超出边界吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于关联容器,++运算符是否可以在集合末尾发送迭代器?

For associative containers, can the ++ operator send an iterator past the end of a collection?

示例:

map<UINT32, UINT32> new_map;
new_map[0] = 0;
new_map[1] = 1;

map<UINT32, UINT32> new_iter = new_map.begin();

++new_iter;
++new_iter;
++new_iter;
++new_iter;
++new_iter;
++new_iter;
++new_iter;

结束时,new_iter == new_map.end在很大的未知?

At the end of this, does new_iter == new_map.end(), or does it end up in the great unknown?

注意:我知道这是搞砸了,而不是做事的方式。我正在处理一些WTF公司代码。

Note: I know this is messed up and not the way to do things. I'm working around some WTF corporate code.

推荐答案

如果增加结束迭代器,结果是未定义的行为。

If you increment the end iterator, the result is undefined behavior. So, it could remain end, or go off the end, or email your grandmother a link to goatse.

另请参见: http:// stackoverflow。 com / questions / 1057724 / what-if-i-increment-an-iterator-by-2-when-it-points-onto-the-last-element-of-a-ve

这篇关于STL图迭代器可以通过递增超出边界吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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