发现元素何时插入到std :: map中 [英] discover when the element is inserted to the std::map

查看:111
本文介绍了发现元素何时插入到std :: map中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序是插入(使用[]操作符])一些数据[地址]到std :: map。我可以跟踪137个元素的插入。它们都插入了有效的值。



在某些阶段,我迭代映射并尝试使用值[addresses]
我在开始迭代地图之前设置断点。
当我在调试器中检查映射时,我仍然看到137个元素。但是当我迭代它,直到



iterator! end 我发现地图有138个值 - 最后一个是非法的。



我需要找到一种方法来检测最后

解决方案

p>你可以尝试在 std :: map的插入函数中放置条件断点



),适当的位置是行755( std :: map :: insert )和行767( std :: map :: operator [ ] )的C:\Program文件(x86)\Microsoft Visual Studio 10.0 \VC\include\xtree



可以在 _Mysize == 137 的每个断点上添加一个条件以捕获插入,从而将映射大小增加到138。



最可能的罪魁祸首可能是 operator [] ,因为很容易将此错误地认为是访问者。


My program is inserting (with [] operator]) some data[addresses] into the std::map. I can track inserting of 137 elements.They all are inserted with valid values.

In some stage I iterate the map and try to do some manipulation with the values[addresses] I`ve set a breakpoint right before I start to iterate the map. When I check the map in debugger I still see 137 elements.But when I iterate it until the

iterator != map.end I discover ,that the map has 138 values - the last one is illegal.

I need to find a way to detect when this last problematic value is inserted.I use VS 2010.

Thank you

解决方案

You could try placing conditional breakpoints in the insertion functions of std::map

For me (using VC10), the appropriate places are line 755 (for std::map::insert) and line 767 (for std::map::operator[]) of C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xtree

You can add a condition on each breakpoint of _Mysize == 137 to catch the insertion which increases the map size to 138.

The most likely culprit is probably the operator[] since it's easy to mistakenly think of this as an accessor only.

这篇关于发现元素何时插入到std :: map中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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