November 07, 2018 Checking for CTFE at compile-time | ||||
---|---|---|---|---|
| ||||
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, 2018 Re: Checking for CTFE at compile-time | ||||
---|---|---|---|---|
| ||||
Posted in reply to Per Nordlöw | 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 |
Copyright © 1999-2021 by the D Language Foundation