3 ms·
Maybe 'constexpr' has been added rather to express the intent (for example, for library development)?
by minipci1321 9y ago
Maybe 'constexpr' has been added rather to express the intent (for example, for library development)?
- WalterBright 9y agoYou 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.