I am using template metaprogramming in c++ to generate a hierarchy of classes from using a typelist like so:
//! Basic typelist class
template<class H, class T>
class Typelist
{
public:
typedef H Head;
typedef T Tail;
};
//! Terminating type
class NullType {};
//! Forward declaration
template<class Types>
class Recur;
//! Specialisation to terminate the recursion
template<>
class Recur<NullType>
{
};
//! General recursive class
template<class Types>
class Recur: public Recur<typename Types::Tail>
{
};
// Dummy classes
class Type1{};
class Type2{};
class Type3{};
int main()
{
// Defines the typelist
typedef Typelist<Type1,Typelist<Type2,Typelist<Type3,NullType>>> Types;
// Instantiate the recursion
Recur<Types> recur;
return 1;
}
This would produce a class hierarchy like so:
Recur<Typelist<Type2,Typelist<Type3,NullType>>> which derives from:
Recur<Typelist<Type3,NullType>> which derives from:
Recur<NullType> (base class)
Question: Are there any Visual Studio 2010 compiler limits to the depth of class derivation using this recursive technique? In other words if my typelist contained N types would the code above compile and construct N classes even if N equals say 100,000?
Annex B of the Standard specifies only a minimum level of direct and indirect base classes and nested template instantiations, and it’s a quality of implementation issue whether a specific compiler goes beyond that. Consult your specific compilers own documentation for the precies numbers. Below follow the minimum quantities required by the Standard.
Annex B (informative)
Implementation quantities [implimits]