Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It should be noted that at least some cases which previously required template meta programming can now be done in a more natural style with constexpr. A constexpr function can be evaluated at compile time, this means that its return value can be used in places that require a compile time constant.

constexpr functions where quite restrictive in C++11. They could pretty much only contain a single expression and a return. C++14 significantly relaxes these restrictions.

http://en.wikipedia.org/wiki/C%2B%2B14#Relaxed_constexpr_res...

Type-level meta programming is still confined to using templates though...



I tried to make a proposal for a more natural meta programming:

https://github.com/hun-nemethpeter/cpp-reflector-mini/blob/m...


D has very good support for this. here's a quick string templating function i wrote, for instance: https://gist.github.com/martindemello/2686640

it calls a function at compile time to expand placeholders, and then compiles the generated string via the mixin() statement and carries on with the code. far more pleasant than c++.


constexpr doesn't really help for logic programming though, which is what this post is using template specialization to do. You can't ask for the answer to Russell's paradox using constexpr (which is, IMHO, a good thing).


> Type-level meta programming is still confined to using templates though...

Which there is less of need for this, since we have better type deduction in C++11 and 14 as well.




Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: