Template-Templates
What is template
The second template argument is itself a template; consider the following declaration (taken from a posting on comp.lang.c++.moderated):
template
struct A {
void push_back(const T& val) { l_.push_back(val); }
void pop() { l_.pop_back(); }
private:
container
};
What is template
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
C
};
int main()
{
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 A
{
C
};
And so on. It's a useful technique in generative template programming