Re: Strange std::remove behaviour

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Victor Bazarov (v.Abazarov_at_comAcast.net)
Date: 12/09/04


Date: Thu, 09 Dec 2004 11:49:03 -0500

uvts_cvs@yahoo.com wrote:
> std::vector<int> v(1, 0);
> std::remove (v.begin(), v.end(), 0);
>
> After executing this two lines of code (compiled with VC7.1) v.size()
> returns 1. Isn't that strange?
> Am I missing something?

'remove' doesn't truly remove, it actually rearranges the elements
and returns the iterator which you then can pass to 'erase' if you
do need the elements removed. RTFMSDN, especially the sample program.

V



Relevant Pages