Checking for CTFE at compile-time

H. S. Teoh hsteoh at quickfur.ath.cx
Wed Nov 7 22:11:43 UTC 2018


On Wed, Nov 07, 2018 at 10:01:15PM +0000, Per Nordlöw via Digitalmars-d-learn wrote:
> Opposite to run-time checking via
> 
> if (__ctfe)
> {
>     //
> }

It's actually not a "run-time" check, because the backend optimizer will
optimize out the true branch (check the emitted asm to confirm this).


> is there no way of checking at compile-time whether the current scope
> of a function is being executed in CTFE?

`if (__ctfe)` *is* a compile-time check.

I think you're getting confused by the blanket term "compile-time", that
actually means (at least) two different things. See:

	https://wiki.dlang.org/User:Quickfur/Compile-time_vs._compile-time


T

-- 
Real men don't take backups. They put their source on a public FTP-server and let the world mirror it. -- Linus Torvalds


More information about the Digitalmars-d-learn mailing list