Re:C++17 constexpr everything, or as much as the compiler can
by minipci1321 on Thursday December 28, 2017 @04:23PM
(#16024998)
Maybe 'constexpr' has been added rather to express the intent (for example, for library development)?
[ Parent
| on HN ]
Re:C++17 constexpr everything, or as much as the compiler can
by WalterBright on Thursday December 28, 2017 @05:08PM
(#16025370)
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.