[Insight-developers] template depth limit

Brad King brad.king@kitware.com
Thu, 28 Jun 2001 14:41:25 -0400 (EDT)


> > instantiation hidden inside another.  If we are hitting GCC's default
> > limit of 17, then that means the class is instantiating at least 17 other
> > template classes when it is used.  Usually a re-structuring of classes can
> 
> Is this saying a given class A instantiates B which instantiates C
> which instantiates D, ... 17 levels?
Yes, this is exactly what it is saying.  The classic example of a template
class that does this looks like this:

// A class with recursive instantiation:
template <int d> struct Foo: public Foo<d-1> {};

// Terminate the recursion:
template <> struct Foo<0> {};

// This explicit instantiation causes Foo<1...10> to be instantiated
// (depth 10), and is then stopped by the Foo<0> specialization.
template struct Foo<10>;

> Or is this saying a given class A instantiates B, C, D, .... 17
> classes but all at the same "level". In other words, class A
> aggregates 17 ivars which are themselves templates.
This one is more of template "breadth", but I've never heard a term for
it.

-Brad