Allow designated initialization of struct

ryuukk_ ryuukk.dev at gmail.com
Sat Aug 31 06:54:56 UTC 2024


On Friday, 30 August 2024 at 19:37:22 UTC, Steven Schveighoffer 
wrote:
> On Friday, 30 August 2024 at 16:02:38 UTC, ryuukk_ wrote:
>> This should be allowed:
>>
>> ```D
>> struct Data
>> {
>>     int a;
>>     int b;
>>     int c;
>>     @disable this();
>> }
>>
>> my_fun( Data { c: 1 } );
>> ```
>
>
> I'm not understanding the `@disable this()`
>
> Without that, this works:
>
> ```d
> struct Data
> {
>     int a;
>     int b;
>     int c;
> }
>
> void my_fun(Data data) {}
>
> void main()
> {
>     my_fun( Data (c: 1 ) );
> }
> ```
>
> I tried making Data also have a ctor with all defaults, but it 
> doesn't like that.
>
> -Steve

brackets vs parenthesis, no ctor

it's popular among C and newest languages (the irony), data first

D lags behind, as usual

```
     state.pip = sg_make_pipeline(&(sg_pipeline_desc){
         .layout = {
             /* test to provide buffer stride, but no attr offsets 
*/
             .buffers[0].stride = 28,
             .attrs = {
                 [ATTR_vs_position].format = 
SG_VERTEXFORMAT_FLOAT3,
                 [ATTR_vs_color0].format   = SG_VERTEXFORMAT_FLOAT4
             }
         },
         .shader = shd,
         .index_type = SG_INDEXTYPE_UINT16,
         .cull_mode = SG_CULLMODE_BACK,
         .depth = {
             .write_enabled = true,
             .compare = SG_COMPAREFUNC_LESS_EQUAL,
         },
         .label = "cube-pipeline"
     });

```




More information about the dip.ideas mailing list