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?
As I understand it, constexpr is not Turing complete unlike template metaprogramming, so I
Share
constexpris absolutely Turing-complete. Recursion is allowed. It a convenient way to define functions that work at compile time as well as runtime.constexprfunctions, being mere functions, cannot perform operations on types, though. (Unless you use template metaprogramming to define said function, of course.)Both class templates and
constexprcan 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.