Is "auto t=T();" not the same as "T t;"?

Ali Çehreli acehreli at yahoo.com
Tue Oct 25 18:01:15 UTC 2022


On 10/25/22 10:54, Salih Dincer wrote:

 > So I don't understand why it causes problems with
 > dynamic arrays!  So why is there nothing wrong with the static array in
 > the example below?

The same rules as other uses of dynamic arrays...

 >      //A[] a = [A.init];/*

In that case, there is a single instance of [A.init]. All A.a members 
point to it through their .ptr .length members.

 >      A[1] a = [A.init];//*/

In that case, there is still a single instance of [A.init], which gets 
copied to each A.a member because static arrays don't have .ptr to point 
to any member. Static arrays are "just elements side by side."

In other words, there is no option but to copy to static arrays; they 
can't point to elements and they don't have any problem in this case.

Ali



More information about the Digitalmars-d-learn mailing list