Do string mixins work under -betterC?
DLearner
bmqazwsx123 at gmail.com
Wed Dec 17 14:15:42 UTC 2025
On Wednesday, 17 December 2025 at 00:13:42 UTC, Richard (Rikki)
Andrew Cattermole wrote:
[...]
>>> string genStuff(string val) {
>>> return val ~ ";";
>>> }
>>>
>>> void myFunc() {
>>> mixin(genStuff("this"));
>>> }
[...]
>>> This won't work without a way to mark `genStuff` as CTFE
>>> only. Which doesn't exist currently.
>>>
>>> Compiler has to know that a given execution context is CTFE
>>> only otherwise disallowed.
>>
>> 1. Any proposals to mark a function as CTFE only?
>
> No, this is something that should've been done a while back.
>
> The main concern is that you can get a linker error if you
> don't emit a function that was called.
Actually, in your example, don't see the problem.
'mixin' operates to provide text to the compiler _prior to_ run
time.
Therefore, even if 'genStuff()' has a run-time (as well as)
compile-time meaning,
the use of mixin should force the compile-time meaning to be
taken.
So no ambiguity?
DL
More information about the Digitalmars-d-learn
mailing list