Some fun with GCC
's error messages...
// going up to the tip...
#line 1
template<typename T, int N, int M = N, bool up = true>
struct hill {
typedef typename hill<T**, N, M - 2>::next next;
};
#line 1
// ... on the tip! down now again ...
template<typename T, int N>
struct hill<T**, N, 1, true> {
typedef typename hill<T, N, 3, false>::next next;
};
#line 1
// going down...
template<typename T, int N, int M>
struct hill<T**, N, M, false> {
typedef typename hill<T, N, M + 2, false>::next next;
};
// preparing for the finish...
#line 1
template<typename T>
struct ThatWasTheHill { };
template<typename T>
struct TheFollowingIsTheHill
{ typedef typename ThatWasTheHill<T>::next next; };
#line 1
template<typename T, int N>
struct hill<T*, N, N, false>
{ typedef typename TheFollowingIsTheHill<T>::next next; };
// start off!
hill<int*, 7> h;
Works with 3
upwards...
main.cpp: In instantiation of 'TheFollowingIsTheHill<int>':
main.cpp:3: instantiated from 'hill<int*, 7, 7, false>'
main.cpp:4: instantiated from 'hill<int***, 7, 5, false>'
main.cpp:4: instantiated from 'hill<int*****, 7, 3, false>'
main.cpp:4: instantiated from 'hill<int*******, 7, 1, true>'
main.cpp:3: instantiated from 'hill<int*****, 7, 3, true>'
main.cpp:3: instantiated from 'hill<int***, 7, 5, true>'
main.cpp:3: instantiated from 'hill<int*, 7, 7, true>'
main.cpp:7: instantiated from here
main.cpp:6: error: no type named 'next' in 'struct ThatWasTheHill<int>'
This is the result with the brand new bleeding edge clang compiler, using -fno-caret-diagnostics
to prevent it mixing source code in between :)
main.cpp:6:44: error: no type named 'next' in 'ThatWasTheHill<int>'
main.cpp:3:51: note: in instantiation of template class 'struct TheFollowingIsTheHill<int>' requested here
main.cpp:4:51: note: in instantiation of template class 'struct hill<int *, 7, 7, 0>' requested here
main.cpp:4:51: note: in instantiation of template class 'struct hill<int ***, 7, 5, 0>' requested here
main.cpp:4:47: note: in instantiation of template class 'struct hill<int *****, 7, 3, 0>' requested here
main.cpp:3:46: note: in instantiation of template class 'struct hill<int *******, 7, 1, 1>' requested here
main.cpp:3:46: note: in instantiation of template class 'struct hill<int *****, 7, 3, 1>' requested here
main.cpp:3:46: note: in instantiation of template class 'struct hill<int ***, 7, 5, 1>' requested here
main.cpp:7:15: note: in instantiation of template class 'struct hill<int *, 7, 7, 1>' requested here
Maybe you are lucky and it works with your compiler too :)