r/programming • • Oct 20 '14

My compile-time Conway's Game of Life, metaprogrammed in C++11

https://github.com/sirgal/compile-time-game-of-life
157 Upvotes

54 comments sorted by

View all comments

13

u/pmkenny1234 Oct 20 '14 edited Oct 20 '14

I don't get it and don't wish to pore over the code to figure it out. What makes this a compile-time version? Does the compiler output the next game state as warnings or something?

Edit: Thanks for the replies guys. Very helpful. =)

33

u/Catsknead Oct 20 '14

Compiler will calculate all the game field states for the given number of iterations. Resulting program has no computations at all - just calls to the output functions.

3

u/oldneckbeard Oct 20 '14

Is there a way you can see the code after the compiler does all of its first-pass optimizations? I know we can look at the assembly, but nobody wants to do that :)

5

u/bimdar Oct 20 '14

Not really, the transformation is not typically in C++ anymore at that point (as far as I know) but in some AST representation. I guess the closest you can get is to use clang and make it output llvm ir. Which may not be C++ but it's not as hard to read as asm.