Sign in to follow this  

Boost unordered_map problem

This topic is 2795 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everyone, I am having a prolem erasing item from Boosst unordered_map using an iterator. The code is as following

for(boost::unordered_map::iterator it = map.begin();it != map.end();)
{
    if (it.second != 10)
    {
        map.erase(it);
    }
    else
    {
        ++it;
    }
}



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.

Share this post


Link to post
Share on other sites

This topic is 2795 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this