C++ bad-mouthing

Mirko Zeibig mirko-lists at zeibig.net
Mon Jan 19 05:20:52 EST 2004


Rainer Deyke said the following on 01/16/2004 07:23 PM:
> beliavsky at aol.com wrote:
> 
>>What is so dangerous about the STL in C++?
> 
> 
> One thing is that iterators can get invalidated when the container is
> modified.

Hm, I think there are similar problems in Python:
--- snip ---
adict = {'foo': 'bar', 'spam': 'ham'}

for key in adict: # has to be adict.keys()
   del adict[key]
--- snap ---

This snippet leads to a RuntimeError but the first item will be gone.

Of course, you may use the "older" syntax in this case. ".keys()" will 
generate the list of keys once in advance, while the upper example will 
call next() each time AFAIK.

Regards
Mirko
-- 



More information about the Python-list mailing list