On 01-10-2012 07:40, Tommi wrote:
import std.stdio;

int pow2(int val) pure
{
     if (__ctfe)
         return 6;
     else
         return val * val;
}

void main()
{
            assert(pow2(3) == 9);
     static assert(pow2(3) == 6);

     writeln("9 = 6 ... I knew it! '6' was faking it all along");
     readln();
}

This is a corner case.

__ctfe is there to allow special-cased CTFE code when absolutely necessary. By necessity, this separates a function into two worlds: compile time and run time.

As far as purity goes, pow2 *is* pure. It just does something different depending on whether you run it at compile time or run time. I don't see this as a problem in practice.

--
Alex Rønne Petersen
a...@lycus.org
http://lycus.org

Reply via email to