Can now use alias for collapsing multiple fields in nested structs

Walter Bright newshound2 at digitalmars.com
Sat Dec 28 19:21:43 UTC 2024


It's commonplace in C and C++ to use something like:

```
#define ti t.i

s.ti
```
as a shortcut for cutting through layers of struct declarations. Now `alias` can 
do it, too!

This now works:

```
struct T {
     int k,i = 2;
}

struct S {
     int x;
     T t;
     alias ti = t.i;
}

void main() {
     T t = T(1, 2);
     S s;
     assert(s.ti == 2);
}
```

`alias` has evolved from simply `typedef` into quite the multi-tool!

https://github.com/dlang/dmd/pull/20611

Manu suggested this.


More information about the Digitalmars-d mailing list