mixin identifiers concept

Paul Backus snarwin at gmail.com
Mon Jan 31 20:45:53 UTC 2022

On Monday, 31 January 2022 at 07:19:49 UTC, bauss wrote:
> I believe a DIP would be necessary, but to be honest I don't 
> see a reason for this.
> You can just do this which isn't really much less readable.
> ```d
>     static foreach (name; ["boo", "foo"])
>     {
>         mixin(`string file_%1$s = 
> readText("%1$s.txt");`.format(name));
>     }
>     writeln(file_boo);
>     writeln(file_foo);
> ```

Using `std.format` for this incurs a substantial compile-time 
performance penalty--dozens of templates must be instantiated, 
memory must be allocated for CTFE, the format string must be 
validated, etc. If the mixin is inside a template which is itself 
instantiated many times, this overhead can really add up.

More information about the Digitalmars-d mailing list