Thread overview
Check for ctfe
Aug 25, 2012
cal
Aug 25, 2012
Timon Gehr
Aug 25, 2012
cal
Aug 25, 2012
Philippe Sigaud
Aug 25, 2012
Minas Mina
Aug 25, 2012
Philippe Sigaud
Aug 25, 2012
Timon Gehr
Aug 25, 2012
bearophile
Aug 25, 2012
Timon Gehr
August 25, 2012
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
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
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
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
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
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
Why is it "if( __ctfe )" and not
static if.. ?
August 25, 2012
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
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.