Question about iterator management in sw/source/core/fields/cellfml.cxx
Michael Stahl
mstahl at redhat.com
Fri Feb 3 08:31:46 PST 2012
On 03/02/12 17:21, Stephan Bergmann wrote:
> 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.
ah, that's surprising.
see, that is why i almost always write the i++ as an extra statement,
i'm never quite exactly sure what it does, and when :)
More information about the LibreOffice
mailing list