Compile time function execution...

Walter Bright newshound at digitalmars.com
Fri Feb 16 11:03:17 PST 2007


Russell Lewis wrote:
> Say, like this:
>     version(4K_PAGES)
>         const int page_size = 4*1024;
>     else
>         const int page_size = 16*1024*1024;
>     const int page_shift = eval!(log_base_2(page_size));

Don't need eval!() for const declarations.

> Sure, you could integrate page_shift into the version statement...but I 
> think that the above is better.
> 
> P.S. I would prefer the template
>     compile_time!(value)
> over
>     eval!(value)
> for readability reasons.

eval!() isn't even in the standard library! You can name it whatever you 
wish. In any case, I used the name "eval" simply because it was 
analogous to the eval function found in many scripting languages.



More information about the Digitalmars-d mailing list