printf() metaprogramming challenge

Radu void at null.pt
Fri May 24 09:52:58 UTC 2019


On Friday, 24 May 2019 at 08:00:31 UTC, Petar Kirov [ZombineDev] 
wrote:
> On Friday, 24 May 2019 at 07:09:56 UTC, Radu wrote:
>> On Friday, 24 May 2019 at 04:49:22 UTC, bpr wrote:
>>>> [...]
>>
>> Indeed it doesn't work with -betterC flag. Easily testable on 
>> run.dlang.io
>>
>> This probably would work if CTFE was supported when compiling 
>> with betterC.
>
>
> In cases like this, one needs to use the enum lambda trick:
>
> // Before:
> string foo(string arg1) { /* .. */ }
>
> // After:
> enum foo(string arg1) = () { /* .. */ };
>
>
> (Replace `string arg1` with all compile-time and run-time 
> parameters that `foo` may take.)
>
> That way, `foo` won't reach the code-generator and hence you 
> won't get errors with `-betterC`.

Yes, good point! I forgot about this trick.


More information about the Digitalmars-d mailing list