November 07
Opposite to run-time checking via

if (__ctfe)
{
    //
}

is there no way of checking at compile-time whether the current scope of a function is being executed in CTFE?
November 07
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