CTFE determination?

Russell Lewis webmaster at villagersonline.com
Sun Sep 14 15:14:54 PDT 2008


bmeck wrote:
> well any suggestion on how to determine if a parameter is constant at run time? that is my goal overall... right now it seems casting to invariant ruins anything I can come up with.

Remember that when a function is not run through CTFE, then it doesn't 
really know anything about the arguments that it is passed.  It could be 
called several times, sometimes with compile-time-constant args, and 
sometimes without.

In order to tell the difference, you have to take on the responsibility 
to specialize the function yourself.  One option is to make the function 
a template, and then pass the compile-time-constant arguments as 
template parameters:

	void myFunc(int CompileTime1, char[] CompileTime2)
	           (int runtime)

...but that only works if you know that the same args will be compile 
time args.



More information about the Digitalmars-d mailing list