C++ – Intentionality of SFINAE and Metaprogramming

cconceptshistorytemplates

SFINAE and template metaprogramming can do wonderful things and many libraries also use them considerably.

Historically both of these "magic concepts" were intentionally introduced/supported in C++ ? Or they were just later discovered as useful byproducts (side products) of original template programming ?

Best Answer

About a decade ago after a conference day I happened to find myself in a pub with Erwin Unruh and a few others and I asked him about the program VJovic mentioned. We have had a couple of beers by then, it was an unofficial meeting, and it's lived in my head for a decade, so take this with a grain of salt, but according to my memories:

He said that they had added template features in order to better serve the STL. According to him, some/many in the committee felt that they were creating something without knowing its full capabilities. He himself suspected that all the template stuff, especially so partial specialization, made up a Turing-complete language, and he always meant to do a formal proof of that, but never got around doing so.

Instead one night at a standardization meeting he came up with that program which printed prime numbers as error messages (a version that should work with modern compilers is here) that it computed during the compilation. As a template meta-program it isn't very impressive by today's standards, but it was a first, after all. Someone made what he considered a joke by formally submitting the program so it became an official ISO standardization document.

I remember that I specifically asked him about Bjarne Stroustrup's reaction to the program, and in response Erwin mimicked him by covering his eyes with his hand. :)

In hindsight I regret I hadn't asked Todd Veldhuizen, who also was at that conference, how he came up with expression templates. (He certainly was a nice chap to talk to.) But I was much younger than, and let the life-time opportunity slip by. :(