Jump to content
  • Advertisement
Sign in to follow this  
guangwang1983

Boost unordered_map problem

This topic is 3012 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
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!