dmd 1.047 and 2.032 releases
bearophile
bearophileHUGS at lycos.com
Thu Sep 3 04:50:17 PDT 2009
Indeed, using CTFE will probably feel different after this release of D1/D2. Good work.
I'd like to improve this Wikipedia page some more:
http://en.wikipedia.org/wiki/Compile_time_function_execution
So after all such bugfixes are there better ways to implement the following code (better = simpler, more natural, etc)?
import std.stdio: writeln;
int[] genFactorials(int n) {
int factorial(uint n) {
int result = 1;
for (int i = 1; i < n+1; i++)
result *= i;
return result;
}
int[] result;
for (; n >= 0; --n)
result = factorial(n) ~ result;
return result;
}
const int N = 13;
static const auto factorials = cast(int[N])genFactorials(N - 1);
void main() {
writeln(factorials);
}
For me creating tables at compile-time is an important use case for CTFE. But that CTFE code is/was fragile, if you change it a bit it stops compiling.
Bye,
bearophile
More information about the Digitalmars-d-announce
mailing list