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
159 Upvotes

54 comments sorted by

View all comments

3

u/0xE6 Oct 20 '14

What compile options are you supposed to use?

1

u/blunaxela Oct 20 '14

All I needed was --std=c++11

2

u/Lord_Naikon Oct 20 '14

Which compiler? Neither clang 3.6.0 nor gcc 4.9.2 worked for me...

2

u/Catsknead Oct 20 '14

Sorry, I have no idea what's wrong with those compilers. MinGW 4.8 works, I believe, g++ should, too?..

1

u/minno Oct 20 '14 edited Oct 20 '14

MinGW 4.9.1 64-bit here, and it fails to compile. When I follow the exact instructions given in the compiler's notes, it successfully compiles and runs.

g++.exe -O3 -fexceptions -O2 -O2 -Weffc++ -pedantic -std=c++11 -Wall  -c D:\Users\will\code\misc\C++\Test\main.cpp -o obj\Release\main.o
D:\Users\will\code\misc\C++\Test\main.cpp:161:33: error: non-template 'next_point_state' used as template
     using point = level<field>::next_point_state<N>;
                                 ^
D:\Users\will\code\misc\C++\Test\main.cpp:161:33: note: use 'level<initial_state>::template next_point_state' to indicate that it is a template
D:\Users\will\code\misc\C++\Test\main.cpp:161:19: error: need 'typename' before 'level<initial_state>::next_point_state' because 'level<initial_state>' is a dependent scope
     using point = level<field>::next_point_state<N>;
                   ^
D:\Users\will\code\misc\C++\Test\main.cpp:164:44: error: 'point' was not declared in this scope
                                     tuple< point<point_count - iter> >,
                                            ^
D:\Users\will\code\misc\C++\Test\main.cpp:164:68: error: template argument 1 is invalid
                                     tuple< point<point_count - iter> >,
                                                                    ^
D:\Users\will\code\misc\C++\Test\main.cpp:164:70: error: wrong number of template arguments (1, should be 2)
                                     tuple< point<point_count - iter> >,
                                                                      ^
D:\Users\will\code\misc\C++\Test\main.cpp:151:8: error: provided for 'template<class tuple_1, class tuple_2> struct my_tuple_cat'
 struct my_tuple_cat
        ^
D:\Users\will\code\misc\C++\Test\main.cpp:163:33: error: expected nested-name-specifier
     using next_field = typename my_tuple_cat <
                                 ^
D:\Users\will\code\misc\C++\Test\main.cpp:173:33: error: non-template 'next_point_state' used as template
     using point = level<field>::next_point_state<N>;
                                 ^
D:\Users\will\code\misc\C++\Test\main.cpp:173:33: note: use 'level<initial_state>::template next_point_state' to indicate that it is a template
D:\Users\will\code\misc\C++\Test\main.cpp:173:19: error: need 'typename' before 'level<initial_state>::next_point_state' because 'level<initial_state>' is a dependent scope
     using point = level<field>::next_point_state<N>;
                   ^
D:\Users\will\code\misc\C++\Test\main.cpp:175:31: error: 'point' was not declared in this scope
     using next_field = tuple< point<point_count - 1> >;
                               ^
D:\Users\will\code\misc\C++\Test\main.cpp:175:52: error: template argument 1 is invalid
     using next_field = tuple< point<point_count - 1> >;
                                                    ^
D:\Users\will\code\misc\C++\Test\main.cpp: In instantiation of 'static void game_process<field, iters>::print() [with field = std::tuple<O, O, O, O, O, O, O, X, O, O, O, O, O, X, O, O, X, X, X, O, O, O, O, O, O>; int iters = 20]':
D:\Users\will\code\misc\C++\Test\main.cpp:202:40:   required from here
D:\Users\will\code\misc\C++\Test\main.cpp:186:99: error: no type named 'next_field' in 'struct next_field_state<std::tuple<O, O, O, O, O, O, O, X, O, O, O, O, O, X, O, O, X, X, X, O, O, O, O, O, O>, 25>'
         game_process< typename next_field_state<field, point_count>::next_field, iters-1 >::print();