Solve the eight queens problem at compile-time Can you solve the eight queens puzzle at compile-time?

Pick any suitable output format.

I'm particularly interested in a C++ template metaprogramming solution, but you can use languages that have similar constructs, like, for example, Haskell's type system.

Ideally your metaprogram would output all solutions. No hardcoding.
My meta-program finds all 92 solutions. They are printed as error messages:

error: ‘solution’ is not a member of ‘std::integral_constant&lt;int, 15863724&gt;’


This means the first queen should be placed at y=1, the second at y=5, the third at y=8 and so on.

The meta-program consists of two mutually recursive meta-functions put_queen and put_queens:

#include &lt;type_traits&gt;

template&lt;int queens, int rows, int sums, int difs, int x, int y&gt;
struct put_queen;

template&lt;int queens, int rows, int sums, int difs, int x&gt;
struct put_queens : std::integral_constant&lt;int,
    // try all 8 possible values for y
       put_queen&lt;queens, rows, sums, difs, x, 1&gt;::value
     | put_queen&lt;queens, rows, sums, difs, x, 2&gt;::value
     | put_queen&lt;queens, rows, sums, difs, x, 3&gt;::value
     | put_queen&lt;queens, rows, sums, difs, x, 4&gt;::value
     | put_queen&lt;queens, rows, sums, difs, x, 5&gt;::value
     | put_queen&lt;queens, rows, sums, difs, x, 6&gt;::value
     | put_queen&lt;queens, rows, sums, difs, x, 7&gt;::value
     | put_queen&lt;queens, rows, sums, difs, x, 8&gt;::value
&gt; {};

template&lt;int queens, int rows, int sums, int difs, int x, int y&gt;
struct put_queen : std::conditional&lt;
    // if blocked
    rows &amp; (1 &lt;&lt; y)
 || sums &amp; (1 &lt;&lt; (x + y))
 || difs &amp; (1 &lt;&lt; (x - y + 8)),
    // then backtrack
    std::integral_constant&lt;int, 0&gt;,
    // else recurse
    put_queens&lt;queens * 10 + y,
               rows | (1 &lt;&lt; y),
               sums | (1 &lt;&lt; (x + y)),
               difs | (1 &lt;&lt; (x - y + 8)),
               x + 1
    &gt;
&gt;::type {};


The variable queens stores the y coordinates of the queens placed on the board so far.
The following three variables store the rows and diagonals that are already occupied by queens.
x and y should be self-explanatory.

The first argument to conditional checks whether the current position is blocked.
If it is, we backtrack by returning the (meaningless) result 0.
Otherwise, the queen is placed on the board, and the recursion continues with the next column.

When x reaches 8, we have found a solution:

template&lt;int queens, int rows, int sums, int difs&gt;
struct put_queens&lt;queens, rows, sums, difs, 8&gt; {
    // print solution as error message by accessing non-existent member
    enum { value = std::integral_constant&lt;int, queens&gt;::solution };
};


Since integral_constant has no member solution, the compiler prints queens as an error message.

To start the recursion, we inspect the value member of the empty board:

int go = put_queens&lt;0, 0, 0, 0, 0&gt;::value;


The complete program can be found at ideone.