[C++-sig] Re: Support for Indexing and Iteration Safety
Mike Rovner
mike at bindkey.com
Thu May 29 22:44:09 CEST 2003
> >>> x = foo[10].bar
> >>> del foo[10] # erase the 10th item
> >>> print x
What about having x a weak reference which del will reset to None.
> >>> x = foo[10]
> >>> foo[10] = y
> >>> print x, y
>
> Now you'll see that x and y are always identical, because x
> refers to the place in the array where you've written the
> value of y.
It's ok, because Python have explicit copy semantics
The list isn't the only model.
> 4. Similar problem with exposed iterators:
> change out from under you. The above could lead to a crash
> or bogus results.
bogus results are ok because it's the same as in Python - changing a list
under loop can lead to skiping an element or visiting it twice.
> know how many people care.
I think if it will put some restriction on usage it is ok with me.
Mike
More information about the Cplusplus-sig
mailing list