Warning: explicit element-wise assignment (this.vector)[] = vec.vector[cast(ulong)0..cast(ulong)dimension]

David d at dav1d.de
Tue Jun 25 00:13:14 PDT 2013


Am 24.06.2013 22:50, schrieb bearophile:
> David:
> 
>> What kind of bugs does it avoid?
>> I can't think of a single bug which could happen...
>> (Ranges/Lengths are checked at runtime...)
> 
> Some reasons:
> - Syntax uniformity: similar behaviours should look similar. This is a
> general rule of language design, that avoids troubles you don't even
> know. All array ops use [], so it's right for vector assignment to use
> them.
> - The second rule is that in a language as D we want to denote different
> code complexities with different code. This is the reason given in the
> Changelog, and it explains while length and walkLength have different
> names.
> In past you were not able to tell from a look at the syntax what's
> happening:
> 
> void main() {
>     int[][3] x;
>     int[]    y;
>     int[]    z;
> 
>     x[] = z; // copies just the z pointer
>     y[] = z; // copies the elements in z
> }
> 
> 
> More details:
> http://d.puremagic.com/issues/show_bug.cgi?id=7444
> Coming from this older:
> http://d.puremagic.com/issues/show_bug.cgi?id=3971
> 
> You are welcome,
> bearophile

This really sucks...
I guess I can workaround it with a "static" foreach and do an
elementwise copy.
Thanks for the explanation.


More information about the Digitalmars-d-learn mailing list