Can now use alias for collapsing multiple fields in nested structs

ryuukk_ ryuukk.dev at gmail.com
Thu Jan 2 21:14:25 UTC 2025


On Thursday, 2 January 2025 at 19:08:06 UTC, Walter Bright wrote:
> On 1/2/2025 6:32 AM, Derek Fawcus wrote:
>> The closest native equivalent in D, would seem to be the 
>> following, making use of the new facility.
>> 
>> ```D
>> struct outer {
>>      int a;
>>      struct inner_ {
>>              int b;
>>              int c;
>>      }
>>      inner_ inner;
>>      int d;
>>      alias b = inner.b;
>>      alias c = inner.c;
>> };
>> ```
>> 
>> Or is there a nicer way to write that in D?
>
> ```
> struct outer {
>     int a;
>     struct {
>         int b;
>         int c;
>     }
>     int d;
> }
> ```

that's hard to learn, why is it possible to do `outter.b = 42`?

```
struct outer {
     int a;
     struct {
         int b;
         int c;
     } inner;
     int d;
}
```

now it is easier to learn, it is an anonymous struct called 
`inner`




More information about the Digitalmars-d mailing list