How can I remove elements from an std::set while iterating over it
My first attempt looks like:
set<T> s; for(set<T>::iterator iter = s.begin(); iter != s.end(); ++iter) { //Do some stuff if(/*some condition*/) s.erase(iter--); } But this is problematic if we want to remove the first element from the set because iter-- invalidates the iterator.
What's the standard way to do this?