As I understand it, constexpr
is not Turing complete unlike template metaprogramming, so I believe these are not the same. So the question is to what extent does constexpr
make template metaprogramming obsolete?
constexpr
is absolutely Turing-complete. Recursion is allowed. It a convenient way to define functions that work at compile time as well as runtime. constexpr
functions, being mere functions, cannot perform operations on types, though. (Unless you use template metaprogramming to define said function, of course.)
Both class templates and constexpr
can be used to contain compile-time constant expressions, but there the similarity ends. They are not redundant and TMP won't be going away anytime soon.
Some particularly ugly compile-time calculations might be more elegantly rewritten as proper functions, though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With