Is it possible to force CTFE?
Tommi
tommitissari at hotmail.com
Thu Sep 27 05:14:26 PDT 2012
On Sunday, 10 June 2012 at 10:16:23 UTC, jerro wrote:
>
> No, but you could wrap it in a template to force it to always
> execute at compile time.
So, I just realized, I could have just this one convenience
template that I can use whenever I want to force an expression to
be evaluated at compile-time. Like so:
template ct(alias expr)
{
enum ct = expr;
}
int fun(int a, int b)
{
return a + b;
}
//... and use it like:
ct!(fun(1, 2))
That's not *too* inconvenient. Although, best would be a function
attribute that would force the compiler to apply ctfe
aggressively whenever it can with calls to that function.
More information about the Digitalmars-d-learn
mailing list