June 25, 2013 Re: Warning: explicit element-wise assignment (this.vector)[] = vec.vector[cast(ulong)0..cast(ulong)dimension] | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | On 06/24/2013 05:16 PM, Ali Çehreli wrote: > 2) Mixing static array and dynamic array on both sides of = is disallowed: > da[] = sa[]; // ditto > da = sa[]; // ditto And I didn't mean that those two have the same meaning. The former is "copy all elements", and the latter is "refer to all of sa's elements". Ali | |||
June 25, 2013 Re: Warning: explicit element-wise assignment (this.vector)[] = vec.vector[cast(ulong)0..cast(ulong)dimension] | ||||
|---|---|---|---|---|
| ||||
Posted in reply to bearophile | 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.
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply