Can now use alias for collapsing multiple fields in nested structs

bauss jacobbauss at gmail.com
Sat Dec 28 20:01:50 UTC 2024


On Saturday, 28 December 2024 at 19:21:43 UTC, Walter Bright 
wrote:
> 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.

Amazing!


More information about the Digitalmars-d mailing list