forcing compile time function execution
Vladimir Panteleev
vladimir at thecybershadow.net
Tue Dec 27 10:29:00 PST 2011
On Tuesday, 27 December 2011 at 18:00:27 UTC, Artur Skawina wrote:
> Is there a way to *force* CTFE? Without using an extra wrapper
> like this:
>
> auto f_impl(alias a)() { / * ... ctfeable ... */ }
> auto f(alias a)() { enum ctfed = f_impl!a; return ctfed; }
>
> A "@compile" (or "@ctfe" etc) function attribute would
> eliminate the need for the wrapper...
import std.math;
template Now(alias e)
{
enum Now = e;
}
void main()
{
auto f = Now!(sin(3));
}
This should probably be in Phobos somewhere :) I suggested this
before, but a bug (now fixed) prevented the idea from working.
More information about the Digitalmars-d
mailing list