This code was taking a copy of every element in a set in order to iterate
through them while removing elements from the underlying set. However, this is
not necessary. This change replaces this code with the standard pattern for
deleting elements while iterating over a set.
using std::ios;
using std::ofstream;
using std::set;
-using std::vector;
using std::list;
#ifndef RECTANGLE_OVERLAP_LOGGING
//erase(doomed);
}
void Blocks::cleanup() {
- vector<Block*> b_copy(begin(),end());
- for(vector<Block*>::iterator i=b_copy.begin();i!=b_copy.end();i++) {
+ for (auto i = begin(); i != end();) {
Block *b=*i;
if(b->deleted) {
- erase(b);
+ i = erase(i);
delete b;
+ } else {
+ ++i;
}
}
}