www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Check for ctfe

reply "cal" <callumenator gmail.com> writes:
I saw something on the forum not too long ago about statically 
checking to see if the current function is being executed at 
compile time, but can't seem to find it now. Can it be done? 
(Like static if (__ctfe__) or something)
Aug 24 2012
next sibling parent reply Timon Gehr <timon.gehr gmx.ch> writes:
On 08/25/2012 02:06 AM, cal wrote:
 I saw something on the forum not too long ago about statically checking
 to see if the current function is being executed at compile time, but
 can't seem to find it now. Can it be done? (Like static if (__ctfe__) or
 something)
if(__ctfe)
Aug 24 2012
parent reply "cal" <callumenator gmail.com> writes:
On Saturday, 25 August 2012 at 00:13:44 UTC, Timon Gehr wrote:
 On 08/25/2012 02:06 AM, cal wrote:
 I saw something on the forum not too long ago about statically 
 checking
 to see if the current function is being executed at compile 
 time, but
 can't seem to find it now. Can it be done? (Like static if 
 (__ctfe__) or
 something)
if(__ctfe)
Oh i was using it with static if which didn't work, thanks!
Aug 24 2012
parent reply Philippe Sigaud <philippe.sigaud gmail.com> writes:
On Sat, Aug 25, 2012 at 2:20 AM, cal <callumenator gmail.com> wrote:
 On Saturday, 25 August 2012 at 00:13:44 UTC, Timon Gehr wrote:
 On 08/25/2012 02:06 AM, cal wrote:
 I saw something on the forum not too long ago about statically checking
 to see if the current function is being executed at compile time, but
 can't seem to find it now. Can it be done? (Like static if (__ctfe__) or
 something)
if(__ctfe)
Oh i was using it with static if which didn't work, thanks!
Same here. I use it rarely, and every time, I first type 'static if (__ctfe) {...'
Aug 25 2012
parent reply "Minas Mina" <minas_mina1990 hotmail.co.uk> writes:
Why is it "if( __ctfe )" and not
static if.. ?
Aug 25 2012
next sibling parent Philippe Sigaud <philippe.sigaud gmail.com> writes:
On Sat, Aug 25, 2012 at 12:53 PM, Minas Mina
<minas_mina1990 hotmail.co.uk> wrote:
 Why is it "if( __ctfe )" and not
 static if.. ?
I guess because __ctfe *must* be a runtime value: its value changes at runtime. And, as 'static if' cannot act on a runtime value...
Aug 25 2012
prev sibling parent Timon Gehr <timon.gehr gmx.ch> writes:
On 08/25/2012 12:53 PM, Minas Mina wrote:
 Why is it "if( __ctfe )" and not
 static if.. ?
Both branches need to be compiled in order to have both a ctfe and a runtime version.
Aug 25 2012
prev sibling parent reply "bearophile" <bearophileHUGS lycos.com> writes:
cal:

 I saw something on the forum not too long ago about statically 
 checking to see if the current function is being executed at 
 compile time, but can't seem to find it now. Can it be done? 
 (Like static if (__ctfe__) or something)
It's named __ctfe, but unfortunately it's an (immutable) run-time value. When you use it you rely on the dead code elimination optimization done by the compiler. Bye, bearophile
Aug 24 2012
parent Timon Gehr <timon.gehr gmx.ch> writes:
On 08/25/2012 02:15 AM, bearophile wrote:
 cal:

 I saw something on the forum not too long ago about statically
 checking to see if the current function is being executed at compile
 time, but can't seem to find it now. Can it be done? (Like static if
 (__ctfe__) or something)
It's named __ctfe, but unfortunately it's an (immutable) run-time value. When you use it you rely on the dead code elimination optimization done by the compiler. Bye, bearophile
Which is basically guaranteed to be performed.
Aug 24 2012