Specializing on Compile Time Constants

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Mon Oct 12 14:57:02 PDT 2009


dsimcha wrote:
> I'm working on a mathematical expression interpreter for D, which would allow
> for closed form mathematical expressions to be specified as string literals at
> runtime and be evaluated.  For example:
> 
> MathExp myExpression = mathExp("x^2 + e^cos(-x) - 2 * sqrt(pi)", "x");
> writeln(myExpression(2));  // Does exactly what you think it does.
> 
> I've found the syntax so convenient that I'd like to transparently specialize
> it on strings known at compile time.  The idea is that, when the expression is
> hard-coded, you will still be able to use the MathExp interface, but your
> expression will evaluate at the full speed of a statically compiled function.
>  Is there any way to test whether the value of an argument to a template
> function is known at compile time and specialize on this?

As an aside, I'd so use that if you allowed LaTeX math expressions.

Andrei



More information about the Digitalmars-d mailing list