Why does this mixin fail to compile?

drug007 drug2004 at bk.ru
Mon Jul 1 12:43:01 UTC 2024


On 01.07.2024 15:26, ryuukk_ wrote:
> Ok, i'll just do it and benchmark at the end
> 
> Another question:
> 
> 
> Why doesn't this work?:
> 

I'm pretty sure your code does not work the way you think it does. 
String Mixins and Template Mixins are two different things. If you want 
to use String Mixins just make a function that creates a complete string 
with the source code and then mix it in. No need for Template Mixins in 
this case.

```D
string generateSourceCode(T)()
{
      return T.stringof ~ "* ctx;";
}

void main()
{
     mixin(generateSourceCode!int);

     static assert(is(typeof(ctx) == int*));

     assert(ctx is null);
}
```


More information about the Digitalmars-d-learn mailing list