5 ms·
> In this example, should fib(35) be evaluated at compile time or runtime? In that example, at compile time. If you write fib(35) you deserve to have to wait f
by dataflow 5y ago
> In this example, should fib(35) be evaluated at compile time or runtime?
In that example, at compile time. If you write fib(35) you deserve to have to wait for the compiler to do it at compile time instead of at run time. (I'm not saying this to be funny. I'm really trying to make a point. You really do need a realistic example to motivate your side of the argument. If they're hard to come up with, that's kind of my point.) And honestly if I wrote that I would fully expect my compiler's optimizer to already waste that time constant-folding anyway; if I was concerned about its compile time I wouldn't write that even without constexpr.
> Best to give them a choice.
A need for that choice (assuming it's even necessary here, which is debatable, see above) doesn't mean you need a new keyword, especially not for functions. It could've been an attribute, and whatever it is, it only really makes sense on variables, not functions. And whatever it is, turning it into an exclusion instead of an inclusion would probably make sense here, seeing as how so much of the standard library has constexpr in front of it.
- bobthebuilders 5y agoWhat? Why would fib(35) be evaluated at comple time? What if it's fib(1500)? The computers I want to run the program on is way faster than the pi I use for development.
- dataflow 5y ago> What? Why would fib(35) be evaluated at compile time? Same reason why fib(2) might be. > What if it's fib(1500)? Are you familiar with exponential growth? This would take longer than the heat death of the universe, whether you evaluate it at compile time or run time...
- bobthebuilders 5y agoRight, but maybe a military supercomputer could compute such a thing. I know my pi surely can't.