Function that calculates in compile time when it can

Minas Mina minas_mina1990 at hotmail.co.uk
Mon Aug 6 08:18:21 PDT 2012


On Monday, 6 August 2012 at 14:25:29 UTC, Eyyub wrote:
> On Monday, 6 August 2012 at 13:46:14 UTC, Tobias Pankrath wrote:
>> You can check for compile time with
>>
>> static if(__ctfe)
> No, you can't.
>
> __ctfe is a "CTFE-ed"(?) value.
>
> But you can do something like that : 
> http://dpaste.dzfl.pl/e3f26239
>
> Minas : I don't know if your PC is outdated, but it's weird. :/

It's Ubuntu 12.04 running on an Intel i5.

That's what I tried to calculate:
static x = fib(40);

ulong fib(ulong n)
{
	if(n < 2)
		return n;
	else
		return fib(n-1) +  fib(n-2);
}

Maybe because it has a lot of recursion?


More information about the Digitalmars-d-learn mailing list