Skip to content

Instantly share code, notes, and snippets.

@mindbound
Created August 19, 2012 12:40
Show Gist options
  • Save mindbound/3394644 to your computer and use it in GitHub Desktop.
Save mindbound/3394644 to your computer and use it in GitHub Desktop.
Turing completeness of C++ templates
#include <cstdio>
template <int D, int A, typename B>
struct K
{
static const int x = K<D + 1, 0, K<D, A, B>>::x
+ K<D + 1, 1, K<D, A, B>>::x
+ K<D + 1, 2, K<D, A, B>>::x
+ K<D + 1, 3, K<D, A, B>>::x
+ K<D + 1, 4, K<D, A, B>>::x;
};
template <int A, typename B>
struct K<16, A, B>
{
static const int x = 1;
};
static const int y = K<0, 0, int>::x;
int main()
{
printf("%i\n", y);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment