Reputation: 5793
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?
Upvotes: 10
Views: 2255
Reputation: 137810
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.
Upvotes: 22