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

Jonathan M Davis jmdavisProg at gmx.com
Mon Jun 24 07:28:27 PDT 2013


On Monday, June 24, 2013 16:07:19 David wrote:
> I am getting lots of errors when compiling with -w:
> 
> // https://github.com/Dav1dde/gl3n/blob/master/gl3n/linalg.d#L144
>     this(T)(T vec) if(is_vector!T && is(T.vt : vt) && (T.dimension >=
> dimension)) {
>         vector = vec.vector[0..dimension];
>     }
> 
> this line produces following warning:
> 
> gl3n/linalg.d(144): Warning: explicit element-wise assignment
> (this.vector)[] = vec.vector[cast(ulong)0..cast(ulong)dimension] is
> better than this.vector = vec.vector[cast(ulong)0..cast(ulong)dimension]
> 
> 
> 
> Why does dmd produce this warning? (this is new in 2.063) Why is
> assigning elementwise better?

According to the changelog ( http://dlang.org/changelog.html ), it sounds like 
it's because doing an element-wise copy is "arbitrarily expensive" (probably 
meaning O(n) rather than O(1)), so it potentially gave the false impression of 
being a simple, cheap assignment if the slicing syntax wasn't used. But I 
don't know what exactly went into that decision beyond what's listed in the 
changelog.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list