initializing struct containing user defined type

Ali Çehreli acehreli at yahoo.com
Fri Feb 18 21:14:47 UTC 2022


On 2/18/22 12:16, Salih Dincer wrote:

 >    // x.writeln(y); // 2.087
 >    "D Compiler v".writeln(__VERSION__/1000.0);
 > ```
 > I'm using v2.087 but because of @disable this line doesn't work: ```//
 > x.writeln(y); // 2.087```
 >
 > Why? Can you give an explanation for this?

This is not related to struct initialization. The issue can be reduced 
to the following:

struct S {
   @disable this(this);
}

void foo(S s) {
}

void main() {
   auto s = S();
   foo(s);
}

Error: struct `deneme.S` is not copyable because it has a disabled postblit

foo takes by-value but S disables copying. The same thing happens with 
your example inside a Phobos function:

     void write(S...)(S args)
     {
     // ...
         foreach (arg; args)
         // ...
     }

foreach iterates the arguments by-value there. Same issue.

Ali



More information about the Digitalmars-d-learn mailing list