I am using boost::unordered_map as follows
typedef boost::shared_ptr PtrWriter;
typedef std::list PtrLis
The erase() operation will invalidate the iterator. However, it also returns a valid iterator to the next element. So you can use something like the following:
for(auto it = instrMap.begin(); it != instrMap.end();)
{
auto key = it->first();
auto list& = it->second();
//Make some change to an element in list
if(list.empty())
{
it = instMap.erase(it);
}
else {
++it;
}
}