.idup flawed?

Walter Bright newshound1 at digitalmars.com
Thu Jun 21 10:47:09 PDT 2007


Xinok wrote:
> .idup creates an invariant copy of an array. According to this page:
> http://digitalmars.com/d/const.html
> 
> "One is that constant data really is constant. It never changes. It's 
> different enough that it needs a different name. In D, this kind of 
> constant is called an invariant."
> 
> 
> So if you have an invariant array, you expect that it's data will never 
> change.
> 
> This is not always the case if you have an array of classes. Classes are 
> pointers, and when you use the .idup property, it only creates invariant 
> copies of the pointers, and not the objects themselves. This means that 
> the objects are still mutable and the data can change, which is not the 
> intended behavior of invariant.

I think you might have found a fatal flaw in .idup. Aggh!



More information about the Digitalmars-d mailing list