Warning: explicit element-wise assignment (this.vector)[] = vec.vector[cast(ulong)0..cast(ulong)dimension]
Ali Çehreli
acehreli at yahoo.com
Mon Jun 24 15:44:40 PDT 2013
On 06/24/2013 03:12 PM, bearophile wrote:
> Ali Çehreli:
>
>> So, the following two have the same effect:
>>
>> vector = vec.vector[0..dimension];
>>
>> vector[] = vec.vector[0..dimension];
>
> The first syntax will be deprecated and later it will become an error.
I am confused. Even if the right-hand expression were a fixed-length
array? If so, then we wouldn't speak of their being value types. (?)
a = b; // should be fine
Otherwise, fixed-length arrays would become weird types that cannot be
used in assignment operations.
I just read the change log. Either it is incorrect or the change is
implemented inccorrectly because it is supposed to be about the
right-hand side. So, OP's code is correct after all.
Here is the excerpt from the change log:
<excerpt>
Array copy operations now always require using the slice syntax:
The right-hand-side of an array copy operation now requires using the
slice syntax:
void main()
{
int[][2] x;
int[] y;
int[] z;
x[] = z; // copies z (pointer + length) 2 times to x
y[] = z; // copies each element of z into y (compiler emits warning)
}
If the user intended to write such code they must use the slice syntax
for both the source and target arrays:
void main()
{
int[][2] x;
int[] y;
int[] z;
y[] = z[]; // copies each element of z into y (no warnings)
}
Rationale:
The compiler will emit a warning to make the user aware that the copy
operation is arbitrarily expensive.
</excerpt>
Ali
More information about the Digitalmars-d-learn
mailing list