reflection based on my experience so far on compile-time meta-programming in D as a novice user: the problems
FeepingCreature
feepingcreature at gmail.com
Mon Sep 14 15:38:07 UTC 2020
On Monday, 14 September 2020 at 12:32:35 UTC, Sebastiaan Koppe
wrote:
> On Monday, 14 September 2020 at 10:54:07 UTC, Paul Backus wrote:
>> Don't overthink it:
>>
>> string generate(string typeName)() {
>> return "%s bla;".format(typeName);
>> }
>>
>> void main() {
>> mixin(generate!"int");
>> bla = 5;
>> }
>
> The implied restriction was that the generate function takes a
> type as its template argument, and then generates a string
> containing a valid D statement with said type.
>
> But fear not:
>
> ----
>
> string generate(string typeName)() {
> return "%s bla;".format(typeName);
> }
>
> void bla(T)() {
> mixin(generate!(T.stringof));
> bla = 5;
> }
You mean:
mixin(generate!"T").
"token" :)
More information about the Digitalmars-d
mailing list