Skip to content
Compile Time Turing Machine
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Compile Time Turing Machine

Going medieval on your compiler

Everyone interested in C++ template metaprogramming probably heard about Turing-completeness of C++ templates, and this project shows how to actually build a Turing Machine with templates and constant expressions, allowing things like this:


ADD_RULE(A, Blank, 1, Right, B);
ADD_RULE(A, 1, 1, Left, B);

ADD_RULE(B, Blank, 1, Left, A);
ADD_RULE(B, 1, Blank, Left, C);

ADD_RULE(C, Blank, 1, Right, Stop);
ADD_RULE(C, 1, 1, Left, D);

ADD_RULE(D, Blank, 1, Right, D);
ADD_RULE(D, 1, Blank, Right, A);

using tape = Tape<Blank>;
using machine = Machine<A, 0, tape>;
using result = Run<machine>::type;

int main() {
    return 0;

This is a 4-state 2-symbol busy beaver example ( The result is

1 _ 1 1 1 1 1 1 1 1 1 1 1 1 

You can check out ideone run here: All the work is performed before the program is even launched!

Here is a blog post with a thorough explanation of the underlying mechanics:

You can’t perform that action at this time.