5 ms·
...isn't that what templates were made for? Template metaprogramming in C++ is Turing-complete.
by chrisrodrigue 1y ago
...isn't that what templates were made for? Template metaprogramming in C++ is Turing-complete.
- pjmlp 1y agoNot at all, originally template metaprogramming was discovered by accident. Cannot recall any longer if the original article on the matter appeared on The C/C++ Users Journal or Dr. Dobbs. Eventually it started to get abused and the Turing completeness has been discovered. Since C++11, the approach to a more sane way to do metaprogramming with templates has been improving. Instead of tag dispatch, ADL and SFINAE, we can make use of concepts, if constexpr/eval/init, type traits, and eventually reflection, instead of the old clunky ways.
- troutwine 1y ago“C++ Templates are Turing Complete” by Todd L. Veldhuizen has the history of discovery, early elaboration.
- omoikane 1y agoLink to paper: http://web.archive.org/web/20131101122512/http://ubietylab.net/ubigraph/content/Papers/pdf/CppTuring.pdf http://web.archive.org/web/20131101122512/http://ubietylab.n... Via "Accidentally Turing-Complete": https://news.ycombinator.com/item?id=30189780 https://news.ycombinator.com/item?id=30189780
- einpoklum 1y agoTemplates are semi-accidentally Turing-complete. They were intended for writing compile-time-generic, run-time-concrete functions and types - but it turned out you could use them, along with the overload resolution mechanisms, to compute things. The Turing-completeness involves recursive use. Computing things using templates is not intuitive. Many of us have gotten used to it - but that's because that's all we had for many years. It's a different sub-language within C++. As constexpr capabilities widen, we can avoid "tortuted" templates and can just write our compile-time checks and figurings in plain C++ - more or less. Sometimes, enhanced language features in C++ allow us to actually throw away and forget about other existing features, or at least - complex and brittle idioms using existing features. Like SFINAE :-)