Comment

Comment by dataflow

> Not really. The whole point of constexpr is to state that an expression is constant, thus the value returned by the function is computed at compile time.

That's not even one point of constexpr, let alone the whole point. Putting constexpr in front of a function declaration does absolutely nothing to the codegen. See for yourself: https://gcc.godbolt.org/z/34h6Tanzn

Notice that both h() and f() are called despite being constexpr.

> To me it seems thay annotating a function with constexpr is the clearest and most straight-forward way to go about expressing constant expressions.

Again, it doesn't do what you think (see above). It does absolutely nothing to a function.

> To each his own, but if the whole point is to represent constant expressions then the constexpr keyword seems to be straight-forward.

This isn't an opinion thing. The consteval literally does what you're imagining constexpr does. Just replace constexpr with consteval in the code above. (I could probably argue that one has little use too, but that's not what I'm arguing here.)

parent dataflow 5 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton