Re: vector.erase(iterator iter) will change "iter" or not?
In message
<c69c72bd-a326-4bc5-b1ef-4dd03288d4f4@i29g2000prf.googlegroups.com>,
thomas <FreshThomas@gmail.com> writes
>
>> (And the higher-level answer to his question is that he should probably
>> be using std::remove anyway:
>>
>> s.erase(remove(s.begin(), s.end(), 3), s.end());
>
>What's this?
It's a C++ STL idiom.
>will "s.erase()" get all the elements after "3" removed?
No. It erases everything in the range defined by the _two_ iterators
being passed to it. And remove() copies the non-3 elements down to the
beginning of s, returning an iterator to the first element beyond them.
If you don't know this stuff, you'd do better to read a good book than
ask random questions here.
--
Richard Herring
|