Templates as template arguments
This is a fairly straightforward extension that allows template names
to be passed as arguments into templates. This allows, for example, the
implementation mechanism for a smart container to be specified as a
template argument, e.g.,
template<class T> class List;
template<class T> class Vector;
template<class T, template<class U> class C = List>
class Group
{
// ...
C<T> container;
};
Group<int> group_int_list;
Group<int, Vector> group_int_vector;
Here,
Group is implemented using another container class
(a template) which can be specified for each
Group instance.
The alternative was to specify
List<int> or
Vector<int> as a type argument but this has two
main disadvantages:
- the contained type int is specified twice and errors caused
by the type differing in those two places might not be caught
- the container cannot choose to create instances of the passed type
with different arguments, e.g., Group might want to declare
C<T*> for each C<T>