BCC wrote:
Here's the entire replacement I'd recommend (untested):
int high_cutoff = 10;
vector<CUnit>::reverse_iterator it;
for (it = good_list.rbegin(); it != good_list.rend(); ) {
if (it->GetCutoff() >= high_cutoff) {
it = good_list.erase(it);
}
else {
++it;
}
}
Makes sense.... but one problem is that erase() returns an iterator, not a
reverse_iterator...
Oh, yeah...
Well, that was kind of dumb, actually. You don't even *want* the
iterator returned by erase of you are going backward. Make them forward
iterators instead - there's no obvious reason to go backward.
On the other hand, if there *is* a reason that you need to go backward,
which just isn't apparent to me, then you can do something like this:
vector<CUnit>::reverse_iterator tmp = it;
++tmp;
good_list.erase(it);
it = tmp;
inside the 'if' block.
Another alternative is to use algorithms. std::remove_if should work, I
think. But remember that it doesn't really remove anything, it just
shuffles the "removed" elements to the end for you to erase().
-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.