for(boost::unordered_map::iterator it = map.begin();it != map.end();)
{
if (it.second != 10)
{
map.erase(it);
}
else
{
++it;
}
}
Boost unordered_map problem
Hi everyone,
I am having a prolem erasing item from Boosst unordered_map using an iterator. The code is as following
I run above code with one element in the map. When that element is erased from the map. i can see my map size is 0, but the iterator doesnt equal to end. So in the next loop, it will try erase an invalid iterator from an empty map, which causes the app to crash. I understand it might be something to do with unordered_map not being a sequenced structure, but what should I do to fix the problem?
Thanks a lot in advance.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement