On Tue, 27 Dec 2011 21:02:49 +0200, Artur Skawina <[email protected]>
wrote:
On 12/27/11 19:29, Vladimir Panteleev wrote:
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...
Umm, the point was to *avoid* the extra useless wrapper. The only reason
for its existence (and any kind of assignment to a static/enum) is to
tell the compiler to try CTFE. Without the compile time assignment, it
won't try hard enough - which means that, for f_impl()s that are not
simple enough, code will be silently emitted and evaluated at runtime.
Even when the functions are supposed to only do *compiletime* checking.
(This happens eg. when /ctfeable/ contains loops)
Hence the "@compile" attribute suggestion, and list selection.
(I actually tried something similar to Now(), but that only obfuscates
the code even more, for no gain)
artur
// lib.d
T fun(T);
unittest
{
enum a = fun;
}
Should do the trick. No change in client code. Yes @ctfe_forced might be
nice but not that we lack a solution.
I also like this one because it doesn't pollute the function.