Assigning a static array

bearophile bearophileHUGS at lycos.com
Thu Apr 18 14:49:47 PDT 2013


Jonathan M Davis:

> I could see an argument that it should have to be
>
> a = b[];
>
> so that the slicing is explicit instead of just
>
> a = b;
>
> where it's implicit, but AFAIK, that's not currently required.

It's currently a warning, and it will be required.

--------------------------

Ali Çehreli:

> There is a similar problem with the automatically generated 
> array arguments.
>
> The following constructor takes any number of ints that come in 
> array form:
>
> import std.stdio;
>
> struct S
> {
>     int[] a;
>
>     this(int[] args...)
>     {
>         a = args;
>     }
>
>     void foo()
>     {
>         writeln(a);
>     }
> }
>
> void main()
> {
>     S[] a;
>
>     foreach (i; 0 .. 2) {
>         a ~= S(i, i, i);  // <-- WARNING temporary array

This is a known problem, I have put it in Bugzilla since lot of 
time and it seems there are various persons that agree with me 
and you on it. So hopefully this source of bugs will be removed, 
allocating that data on the heap.

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list