Apparently, C++ templates are Turing complete. In theory, that means you can write programs which get run at compile time. So here's a program which calculates the factorial of 8 at compile time:
#include <cstdio> template <int N> struct factorial { enum { RET = factorial<N - 1>::RET * N }; }; // Base case - only instantiated when the parameter is 0. template <> struct factorial<0> { enum { RET = 1 }; }; int main() { std::printf("%d\n", factorial<8>::RET); }
That's partly derived from the source code examples for this crazy book about ‘generative programming’.
Some guy has even written a Turing machine using templates.
Of course, you can only use template value parameters that are simple integral values, so you can't do anything interesting or useful like this. But it proves how yucky it is.