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

Ali Çehreli acehreli at yahoo.com
Mon Jun 24 17:16:28 PDT 2013


On 06/24/2013 04:11 PM, bearophile wrote:

> Currently this code gives no warnings:
>
> void main() {
>      int[3] a, b;
>      a = b;
> }
>
> This topic is discussed a little in Issue 7444.

   http://d.puremagic.com/issues/show_bug.cgi?id=7444#c3

Summary:

1) Single element on the right-hand side is disallowed unless lhs is 
"all elements". One must write the following ("sa" is static array and 
"da" is dynamic array):

   sa[] = e;
   da[] = e;

2) Mixing static array and dynamic array on both sides of = is disallowed:

   sa[] = da[];   // fine: both dynamic arrays
   da[] = sa[];   // ditto
   da   = sa[];   // ditto
   sa[] = da;     // ditto

Ali



More information about the Digitalmars-d-learn mailing list