Dollar identifiers in code-generating constructs
Quirin Schroll
qs.il.paperinik at gmail.com
Thu Jul 4 11:13:47 UTC 2024
On Wednesday, 3 July 2024 at 13:34:11 UTC, monkyyy wrote:
> On Wednesday, 3 July 2024 at 10:25:14 UTC, Quirin Schroll wrote:
>> A dollar identifier is an
>> [*`Identifier`*](https://dlang.org/spec/lex.html#Identifier)
>> with a `$` at the end. In a code-generating construct
>> (mixed-in `mixin template` and `static foreach`/`static
>> foreach_reverse`) the `$` is replaced by a number.
>>
>> [...]
>
> is there a static foreach usecase where you cant use a index?
>
> ```d
> template innate(T,alias discirmintor){
> T innate;
> }
> static foreach(i,A;...){
> alias L(int i_:i)=innate(F!A,i);
> }
> ```
One can always use the index: `mixin("size_t l", cast(int)i, " =
...")`. This is a lot of boilerplate for something conceptually
simple.
More information about the dip.ideas
mailing list