One really cool and practical usage of compile time function execution is for generating code at compile time, possibly from config files, or maybe scripts.
Here's a simple example of processing a file at compile time.
main.d
string make_ints(string s)
{
string ret = "";
foreach (varname; split(s))
ret ~= "int " ~ varname ~ "; ";
return ret;
}
void main()
{
mixin(make_ints(import("script")));
foo = 1;
bar = 2;
xyz = 3;
}
script
foo bar xyz
At compile time, the file "script" will be read, split at spaces, and then make_ints returns int foo; int bar; int xyz;
directly into the D code, ready for those variables to be used.
While this is a useless example, you could easily see how this could be used to read values from a config file (maybe values for the size of a cache, or something like that). Games could make use of this to generate raw D code from scripts, which will be great for performance (typically games resort to using interpreted code for scripting, and suffer performance wise).
You could also use this for automatic performance tuning. Say you have some constant X, which can be tweaked to affect performance in various ways, but you don't know what value of X will give you the best performance. You could put X in a file, read it in at compile time for use, try some other values at run time and put the best one back into the file. That way, you get gradually improving performance without having to do anything manually.