Reputation: 688
How much it is safe to store and reuse the iterator values of map in another map?
map<BYTE,vector<connections*>*> mconnections1;//sorting connections based on device key.
for (map<Device*,vector<connections*>>::iterator it=m_eip.m_mvpConnections.begin(); it!=m_eip.m_mvpConnections.end(); ++it)
mConnections1[it->first->DEVICE_KEY]=&it->second;
for (map<BYTE,vector<connections*>*>::iterator it=mConnections1.begin(); it!=mConnections1.end(); ++it)
{
for(unsigned int i=0;i<it->second->size();i++) it->second->at(i)->Write(&fp);
}
Upvotes: 2
Views: 130
Reputation: 36379
The iterators returned by std::map
are invalidated by various operations, if you don't call these operations then you can store the iterators, if you do they will become invalid and using them will be undefined behaviour.
Read the documentation and look for words like "iterators invalidated" in the method descriptions.
Upvotes: 1