Checking if CTFE is used?

Steven Schveighoffer schveiguy at gmail.com
Tue Dec 18 14:04:00 UTC 2018


On 12/18/18 7:21 AM, berni wrote:
> Is there a way to check if a function is indeed executed at compile time 
> or not? (Other than going through the whole executable binaries...)
> 
> I tried
> 
>> static this()
>> {
>>   if (__ctfe) pragma(msg,"works");
>>   // some other stuff
>> }
> 
> but unfortunatley this "if" is also executed at compile time, when I put 
> it into a function that is only called at runtime. When I try "static 
> if" instead the compiler complains about "__ctfe" being not known at 
> compile time.

Well, asserting would at least tell you that it's used.

if(__ctfe) assert(0, "Yep, CTFE used");

But obviously, it couldn't be there for release purposes :)

-Steve


More information about the Digitalmars-d-learn mailing list