要素を削除しても(他の)iteratorはvalidだろうから、
set<T> source;
stack<set<T>::iterator> removes;
for ( set<T>::iterator iter = source.begin();
iter != source.end(); ++iter ) {
if ( これはいらない(*iter) )
removes.push(iter);
}
while ( !removes.empty() ) {
source.erase(removed.top());
removes.pop();
}
枠-1 cppll-1012
[ISO/IEC 14882:1998 23.1.2の8]
The insert members shall not affect the validity of iterators and
references to the container, and the erase members shall invalidate only
iterators and references to the erased elements.