View mode: basic / threaded / horizontal-split · Log in · Help
August 25, 2012
Check for ctfe
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)
August 25, 2012
Re: Check for ctfe
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)
August 25, 2012
Re: Check for ctfe
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
August 25, 2012
Re: Check for ctfe
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!
August 25, 2012
Re: Check for ctfe
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.
August 25, 2012
Re: Check for ctfe
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) {...'
August 25, 2012
Re: Check for ctfe
Why is it "if( __ctfe )" and not
static if.. ?
August 25, 2012
Re: Check for ctfe
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...
August 25, 2012
Re: Check for ctfe
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.
Top | Discussion index | About this forum | D home