Why does this mixin fail to compile?

ryuukk_ ryuukk.dev at gmail.com
Mon Jul 1 13:00:55 UTC 2024


On Monday, 1 July 2024 at 12:43:01 UTC, drug007 wrote:
> 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);
> }
> ```

please stick to what i wrote, i don't want string concatenation, 
i provide a reduced example from my project, everything should be 
a single template block, no extra functions other than the 
append() one


More information about the Digitalmars-d-learn mailing list