T
Tescobar
Over one year ago somebody asked here: how to
remove selected elements from list
in a loop?. The answer was as follows:
for( it = l.begin(); it != l.end; ) {
if(...)
it = l.erase(it);
else
++it;
}
I use STL list, and I do the same like this:
for( it = l.begin(); it != l.end; ++it ) {
if(...) l.erase(it--);
}
Is that OK? Or does it depend on details
of the list implementation ??
Has it to be guaranteed that the operator --
is called before invalidation of the itarator?
regards -
O.C.
remove selected elements from list
in a loop?. The answer was as follows:
for( it = l.begin(); it != l.end; ) {
if(...)
it = l.erase(it);
else
++it;
}
I use STL list, and I do the same like this:
for( it = l.begin(); it != l.end; ++it ) {
if(...) l.erase(it--);
}
Is that OK? Or does it depend on details
of the list implementation ??
Has it to be guaranteed that the operator --
is called before invalidation of the itarator?
regards -
O.C.