Expanding CTFE code during compilation

Steven Schveighoffer schveiguy at gmail.com
Mon Jul 25 12:59:47 UTC 2022


On 7/23/22 2:27 PM, Azi Hassan wrote:
> On Saturday, 23 July 2022 at 00:56:39 UTC, Steven Schveighoffer wrote:
>> On 7/22/22 3:22 PM, Azi Hassan wrote:
>>
>>> Oh, interesting syntax. I was thinking something along the lines of
>>>
>>> ```D
>>> template printEnum(...) {
>>>      version(debug) {
>>>          ... // everything we already did
>>>      } else {
>>>          enum printEnum(alias x) = x;
>>>      }
>>> }
>>> ```
>>>
>>> But I like yours better.
>>
>> `version(debug)` isn't valid syntax, `debug` is a keyword.
>>
> 
> I stand corrected, I must've got it confused with version(unittest)

And *I* stand corrected! `unittest` is also a keyword, so clearly that's 
not disqualifying. Indeed, the grammar specifically includes 
`version(unittest)` and `version(assert)`.

However, because `debug` is exactly like `version` in how it operates, 
`version(debug)` would make little sense.

-Steve


More information about the Digitalmars-d-learn mailing list