Template-Templates

  

What is template class C> for?

The second template argument is itself a template; consider the following declaration (taken from a posting on comp.lang.c++.moderated):

template class container=std::vector>

struct A {

    void push_back(const T& val) { l_.push_back(val); }

    void pop() { l_.pop_back(); }

  private:

    container l_;

};

What is template class C> for? 

  

The first parameter is a concrete type,  the second is a class template.  For example:

template 

struct X

{

  // ...

};

template  class C>

class A

{

public:

 // ...

private:

  C c_int;

  C c_char;

  C c_long:

};

int main()

{

  A a;

}

Here, we pass class template X as a template parameter to A. Basically, this is useful when you need multiple expansions of the same template type.  In this case, A makes use of its template-template parameter by instantiating three different types

from it as member data.

This is also useful when you want to pass A in a type and a template, and internally A applies the type to that template:

template  class C>

class A

{

  C data_;

};

And so on.  It's a useful technique in generative template programming