reflection based on my experience so far on compile-time meta-programming in D as a novice user: the problems
Sebastiaan Koppe
mail at skoppe.eu
Mon Sep 14 12:32:35 UTC 2020
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;
}
More information about the Digitalmars-d
mailing list