M
moleskyca1
Hi,
I know if you call erase when you iterate through map you will crash.
Ex:
map<int,double> m;
// insert something
for ( map<int, double>::iterator i = m.begin(); i != m.end(); i++ )
if ( i->second < 0 ) m.erase(i);
This will crash because erase() will corrupt iterator. Now what I do I
insert key into list and erase each key. After first loop. Is there way
to do this erase in the same search loop?
I know if you call erase when you iterate through map you will crash.
Ex:
map<int,double> m;
// insert something
for ( map<int, double>::iterator i = m.begin(); i != m.end(); i++ )
if ( i->second < 0 ) m.erase(i);
This will crash because erase() will corrupt iterator. Now what I do I
insert key into list and erase each key. After first loop. Is there way
to do this erase in the same search loop?