Templates
Templates get a whole section of their own for two reasons:
- I like templates and have spent a lot of time working with them, both as a committee member and as a programmer
- They have been extended in so many ways since the Annotated Reference Manual was published
As described in the ARM, templates allow you to write generic classes and functions parameterised by types:
template<class T>
class List
{
// ...
};
List<string> names;
template<class T>
void print_list(const List<T>& list);
The following is a fairly complete list of the changes made by the committee to templates as they were described in the ARM:
- Non-type template arguments
- Default template arguments
- Explicit qualification of template functions
- Templates as template arguments
- Member templates
- Use of template to disambiguate template names
- typename
- Explicit instantiation
- Specialisation and partial specialisation
- Template function overloading
- Separate compilation and exporting template definitions