forcing compile time function execution

Jonathan M Davis jmdavisProg at gmx.com
Tue Dec 27 16:29:24 PST 2011


On Tuesday, December 27, 2011 18:59:55 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...

The _only_ time that CTFE is done is when it _must_ be done. So, if you want 
something to be evaluated at compile time, you need to assign it to a value 
which must be initialized at compile time. e.g. an enum or a static variable.

- Jonathan M Davis


More information about the Digitalmars-d mailing list