Is it possible to use tokens as template parameters?
Tejas
notrealemail at gmail.com
Sat Aug 14 12:19:59 UTC 2021
On Saturday, 14 August 2021 at 11:23:12 UTC, rempas wrote:
> Is it possible to do something like that?
>
> ```
> mixin template lel(alias N, alias V) {
> auto N = V;
> }
>
> void main() {
> mixin lel!(name, "Hmmmm");
> }
> ```
>
> In this case, it would (if it was possible) get replaced with:
> `auto name = "Hmmmm";`
> Is there something I'm missing?
You have to use mixins to achieve the desired effect.
```d
mixin template lel(T, string N, string V) {
mixin(T.stringof ~ " " ~N ~ " = " ~ V ~ ";");
}
import std;
void main(){
mixin lel!(string, "name", ` "hmmmm" `);
writeln(name);
}
}
```
More information about the Digitalmars-d
mailing list