forcing compile time function execution
so
so at so.so
Tue Dec 27 11:18:02 PST 2011
On Tue, 27 Dec 2011 21:02:49 +0200, Artur Skawina <art.08.09 at gmail.com>
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.
More information about the Digitalmars-d
mailing list