Question about iterator management in sw/source/core/fields/cellfml.cxx

Stephan Bergmann sbergman at
Fri Feb 3 08:21:00 PST 2012

On 02/03/2012 04:18 PM, Michael Stahl wrote:
> On 03/02/12 14:01, Stephan Bergmann wrote:
>> The "standard idiom" is
>>     for (iterator i = m.begin(); i != m.end();) {
>>       if (doErase) {
>>         m.erase(i++);
>>       } else {
>>         ++i;
>>       }
>>     }
> but doesn't that have the same problem? "i" is incremented only after
> the erase is complete, when "i" is already invalid.

No, i is incremented before calling erase in the above code.

>> The text you cite is about vector, for which *all* iterators into a
>> vector are invalidated upon an erase.
> i think i read this "invalidate from position to end" in the SGI
> documentation as well; does the actual standard give implementations
> more freedom here?

Oh yes, vector erase only invalidates all the iterators after the point 
of erase, not each and every iterator into the vector (i.e., it may not 
reallocate the shrunk array to a smaller memory area).  Sorry for the 


More information about the LibreOffice mailing list