CTFE, string mixins & code generation

Jan Hönig hrominium at gmail.com
Fri Jan 24 17:09:36 UTC 2020


On Friday, 24 January 2020 at 16:59:53 UTC, Marco de Wild wrote:
> For CTFE: functions should be pure. Therefore you cannot use 
> global or static variables. Constants (enums) are perfectly 
> fine to use though. I don't know the state of the GC and CTFE. 
> I recall that there might be some complexity when using the 
> `new` keyword.
>
> https://dlang.org/spec/function.html#interpretation
>
> Basically the only limitation of string mixins is that a single 
> string should evaluate to valid D code, opposed to C macros. So
> int y mixin("= 6");
> doesn't compile, while
> int y = mixin("6");
> or
> mixin("int y = 6;");
> does. You can use CTFE to compose the string.

Ok, so mixins are really easy.
CTFE is the hard pard.
The link that you send me, i could not find it (or i haven't 
tried hard enough). Thanks!


More information about the Digitalmars-d-learn mailing list