When I first saw this meme:

C++ template meta programming meme with Bjarne Stroustrup looking bewildered

I thought to myself, yeah right, but now I am not sure any more. So was template meta programming in C++ discovered by accident as the meme claims or was it intentional?

Did Bjarne & co actually make it without realizing the potential?

  • 2
    This is a borderline "skeptics" or "reference request" question which is borderline on this site, but might have been acceptable on some other sites. – rwong Nov 25 '16 at 18:27
  • Living on the edge! – Lennart Rolland Nov 25 '16 at 18:56
  • 2
    Accidental Turing-completeness is actually rather common. Wikipedia has a partial list with entries such as "Magic: The Gathering". – Kilian Foth Nov 26 '16 at 7:34

There is more to invention than giving a simple list of implications and with C++ Stroustrup aimed for generality:

I'm not interested in a language that can only do what I can imagine

This is from Did you really not understand what you were doing?:

This one seems very popular. Or rather, it seems to be popular to assert that I had no clue so that C++'s success is some kind of accident. Yes, such statements annoy me, because they dismiss my work over decades and the hard work of many of my friends.

Let's first be perfectly clear: No, I did not anticipate the run-away success of C++ and no, I did not forsee every technique used with C++ or every application of C++. Of course not!

However, statements like these are very misleading:

  • Bjarne doesn't understand C++!
  • Bjarne didn't anticipate RAII and deterministic destruction!
  • Bjarne didn't anticipate template-metaprogramming!

I did outline the criteria for the design and implementation of C++. I did explicitly aim for generality: "I'm not interested in a language that can only do what I can imagine" and for efficiency "a facility must not just be useful, it must be affordable."


I was very surprised when Jeremy Siek first showed my the compile-time if that later became std::conditional, but I had aimed for generalty (and gotten Turing completeness modulo translation limits). I opposed restrictions to C++ immediately when Erwin Unruh presented what is widly believed to be the first template metaprogram to the ISO Standards committee's evolution working group. To kill template-metaprogramming, all I would have had to do was to say nothing. Instead my comment was along the lines "Wow, that's neat! We mustn't compromise it. It might prove useful." Like all powerful ideas, template-metaprogramming can be misused and overused, but that does not imply that the fundamental idea of compile-time computation is bad. And like all powerfuls ideas, the implications and techniques emerged over time with contributions from many individuals.


The following excerpt is subject to: https://creativecommons.org/licenses/by-sa/3.0/

History of TMP

Historically TMP is something of an accident; it was discovered during the process of standardizing the C++ language that its template system happens to be Turing-complete, i.e., capable in principle of computing anything that is computable. The first concrete demonstration of this was a program written by Erwin Unruh, which computed prime numbers although it did not actually finish compiling: the list of prime numbers was part of an error message generated by the compiler on attempting to compile the code.

Source: https://en.wikibooks.org/wiki/C%2B%2B_Programming/Templates/Template_Meta-Programming#History_of_TMP

Not the answer you're looking for? Browse other questions tagged or ask your own question.