[quote name='Yang G' timestamp='1306467591' post='4816284']
i think you'd better take a look at erase-remove idiom about vector.it's a efficient way to remove element in vector
erase-remove of a std::vector uses the swap and pop method, correct?
[/quote]
it's like that
template < class ForwardIterator, class T >
ForwardIterator remove ( ForwardIterator first, ForwardIterator last, const T& value )
{
ForwardIterator result = first;
for ( ; first != last; ++first)
if (!(*first == value))
*result++ = *first;
return result;
}
(from c++ library).
Note:
remove doesn't delete the element in the vector instead of overwriting the element like the code said.
so we must use erase to delete these elements who should be removed like that vec.erase(remove(first, end, value), end).
you can see these subjects in book named Effective STL