News for hackers. Stuff that matters.
Re:C++17 constexpr everything, or as much as the compiler can by mehrdadn on Thursday December 28, 2017 @06:49PM (#16026201)
(EDIT to my last comment since I can't actually edit it -- I'm not sure if I misinterpreted your comment earlier or if you updated yours, but this is my updated reply.)

> It is expected that some corners of the language will never be available at compile time, for example I/O. So you need a keyword to declare a function to be callable a compile time, otherwise its constexpressness would depend on its implementation details and wouldn't be possible to check it in isolation.

Don't compilers already require the implementation of a function to be there in order to evaluate the code at compile-time? And don't they already have to verify that it can indeed be called at compile-time? I don't really get what the constexpr flag helps the compiler. It could just assume everything is constexpr implicitly unless proven otherwise.

Re:C++17 constexpr everything, or as much as the compiler can by StephanTLavavej on Thursday December 28, 2017 @07:17PM (#16026372)
constexpr isn't just a claim about today - it's a promise for the future. That is, the compiler can certainly notice that a function can be evaluated at compile time, and indeed optimizers will often perform enough inlining and constant propagation to boil down function calls to constant values in the binary. The constexpr keyword serves two purposes: it claims that the implementation is usable in constant expressions today (therefore allowing compilers to diagnose (i.e. emit compiler errors for) things that can't be done at compiletime, like I/O), and it promises that the implementation won't change in the future to be hostile to compile-time evaluation. This promise is important - otherwise, users could take a dependency on a function's current behavior (e.g. by using its result as an array bound, or as a template argument), and then they would be broken by implementation changes in the future that prohibited compile-time evaluation.
Re:C++17 constexpr everything, or as much as the compiler can by mehrdadn on Thursday December 28, 2017 @07:48PM (#16026539)
I see, so you're saying it's a verifiable promise by the function writer that it can be evaluated at compile-time?

Meaning its entire purpose is to just be an easier version of a compile-time unit-test like static_assert(f(1) == 2)?

Re:C++17 constexpr everything, or as much as the compiler can by twic on Saturday December 30, 2017 @06:39AM (#16034847)
Beautifully put. This is what's missing from D's approach.