std::vector< foo > myvec;for( std::vector< foo >::iterator i = myvec.begin(); i != myvec.end(); ){ if( !i->active() ) i = myvec.erase(i); else ++i;}
erase removes the element, and for a vector will preserve order and copy all the other elements up one. A list on the other hand would just pop the element out of the list without having to copy anything.
Your other option is to make a predicate function for std::remove_if along with std::erase
bool isInActive( const foo &f ){ return !f.Active();}myvec.erase( std::remove_if( myvec.begin(), myvec.end(), isInActive ), myvec.end() );
remove_if does your swap-to-end trick for all values that isInActive returns true. Then it gives you an iterator to the begining of the segment to erase.