2 ms·
You can annotate D functions as 'pure', which would have that effect, but purity is used for other reasons. Evaluating functions at compile time has another wr
by WalterBright 9y ago
You can annotate D functions as 'pure', which would have that effect, but purity is used for other reasons.
Evaluating functions at compile time has another wrinkle in D - it is path dependent:
int square(int x) {
if (x < 100)
return x * x;
printf("oops\n");
return 0;
}
const int x = square(3); // works
const int y = square(100); // fails at compile time
I.e. the path taken through the function has to be pure, not every part of the function.