Z
zl2k
hi, there
Here is what I want to do: I have a set of objects. I need to iterate
each of them to ask if it needs to be eliminated. If yes, I'll erase
it from the set. I don't know which needs to be erased before I touch
it.
std::set<Obj> objs;
....
for (auto obj_iterator = objs.begin(); obj_iterator != objs.end(); +
+obj_iterator){
if (obj_iterator.do_you_want_to_be_erased() == true){
objs.erase(*obj_iterator);
}
}
Now I have the trouble since the iterator is destroyed after the first
erase. What is the proper way to do the job? Thanks.
zl2k
Here is what I want to do: I have a set of objects. I need to iterate
each of them to ask if it needs to be eliminated. If yes, I'll erase
it from the set. I don't know which needs to be erased before I touch
it.
std::set<Obj> objs;
....
for (auto obj_iterator = objs.begin(); obj_iterator != objs.end(); +
+obj_iterator){
if (obj_iterator.do_you_want_to_be_erased() == true){
objs.erase(*obj_iterator);
}
}
Now I have the trouble since the iterator is destroyed after the first
erase. What is the proper way to do the job? Thanks.
zl2k