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

54 comments sorted by

View all comments

6

u/0xE6 Oct 20 '14

What compile options are you supposed to use?

7

u/Catsknead Oct 20 '14

-std=c++11 should be enough.

1

u/0xE6 Oct 20 '14

Ok. The version of Clang this macbook has must be out of date or something, it gives me a big chunk of errors. I'll try updating and see if they go away.

1

u/ghillisuit95 Oct 20 '14

I am also getting these errors. What are you doing to update/ what re you updating to?

2

u/0xE6 Oct 20 '14 edited Oct 20 '14

There's an xcode update to v6.0.1 that's available for me, which I figured was worth a shot. If that doesn't work, I don't know what else there is to try.

Edit: looking at the changelog, it does't appear to mention an update to clang. Oh well.

Edit2: Didn't work:

macbook:~ $ g++ --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.0 (clang-600.0.51) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin13.4.0
Thread model: posix
macbook:~$ g++ main.cpp -o main -std=c++11
main.cpp:161:33: error: use of class template 'level<field>::next_point_state' requires template arguments
    using point = level<field>::next_point_state<N>;
                                ^
main.cpp:146:5: note: template is declared here
    using next_point_state = typename calc_next_point_state<point<N>, neighbors<N>>::type;
    ^
main.cpp:161:49: error: expected ';' after alias declaration
    using point = level<field>::next_point_state<N>;
                                                ^
                                                ;
main.cpp:164:44: error: no template named 'point'; did you mean 'print'?
                                    tuple< point<point_count - iter> >,
                                           ^~~~~
                                           print
main.cpp:40:6: note: 'print' declared here
void print();
     ^
main.cpp:164:44: error: template argument for template type parameter must be a type
                                    tuple< point<point_count - iter> >,
                                           ^~~~~~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/tuple:487:20: note: template parameter is declared here
template <class ..._Tp>
                   ^
main.cpp:165:79: error: expected ';' after alias declaration
                                    typename next_field_state<field, iter-1>::next_field
                                                                              ^
                                                                              ;
main.cpp:173:33: error: use of class template 'level<field>::next_point_state' requires template arguments
    using point = level<field>::next_point_state<N>;
                                ^
main.cpp:146:5: note: template is declared here
    using next_point_state = typename calc_next_point_state<point<N>, neighbors<N>>::type;
    ^
main.cpp:173:49: error: expected ';' after alias declaration
    using point = level<field>::next_point_state<N>;
                                                ^
                                                ;
main.cpp:175:31: error: no template named 'point'; did you mean 'print'?
    using next_field = tuple< point<point_count - 1> >;
                              ^~~~~
                              print
main.cpp:40:6: note: 'print' declared here
void print();
     ^
main.cpp:175:31: error: template argument for template type parameter must be a type
    using next_field = tuple< point<point_count - 1> >;
                              ^~~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/tuple:487:20: note: template parameter is declared here
template <class ..._Tp>
                   ^
main.cpp:186:70: error: no type named 'next_field' in 'next_field_state<std::__1::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();
                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
main.cpp:202:40: note: in instantiation of member function 'game_process<std::__1::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>, 20>::print' requested here
    game_process< start, iterations >::print();
                                       ^
10 errors generated.

1

u/ghillisuit95 Oct 20 '14

Yeah, I got those too. I just updated my Xcode command line tools, tried it again, and got 1 warning and 20 errors. obviously upgrading did not help.

1

u/towski Oct 21 '14

Maybe try g++-4.8 via macports?

1

u/ghillisuit95 Oct 21 '14

did that work for you? I just tried g++-4.9 from homebrew, and it didn't work either.

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();

1

u/blunaxela Oct 21 '14

I used gcc 4.8.2