mixin identifiers concept
Atila Neves
atila.neves at gmail.com
Mon Feb 7 17:41:07 UTC 2022
On Monday, 31 January 2022 at 20:45:53 UTC, Paul Backus wrote:
> 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.
mixin(`string file_`, name, ` = readText("`, name, `.txt");`);
More information about the Digitalmars-d
mailing list