Function that calculates in compile time when it can
Philippe Sigaud
philippe.sigaud at gmail.com
Mon Aug 6 09:25:06 PDT 2012
On Mon, Aug 6, 2012 at 6:17 PM, Minas Mina <minas_mina1990 at hotmail.co.uk> wrote:
> I found this:
>
> real sin(real x) @safe pure nothrow; /* intrinsic */
> I don't see anything about ctfe. Maybe I didn't understand well
> and sin is not evaluated at compile time. Can someone clarify
> this?
Oh, I thought they were implemented as polynomial approximations.
Never mind, you can test it with any function:
int foo(int i)
{
if (__ctfe)
{
pragma(msg, "CT");
return -1;
}
else
return 1;
}
void main()
{
auto i = foo(0);
static j = foo(0);
writeln(i); // 1
writeln(j); // -1
}
So, auto i doesn't provoke CT-evaluation (else it'd be -1).
More information about the Digitalmars-d-learn
mailing list