Description
C++ has long had default function arguments. Default template arguments work in much the same way. For example, in this code:
template <class T, class U = double, int N = 100> class A {...};U and N are parameters with default values specified. If this template is used, for example by saying:
A<short> a;it will be as if you had said instead:
A<short, double, 100> a;The C++ standard library uses default template arguments widely, to supply common policies (such as memory allocators). A specialized use of the library may override one of these defaults.
Concept
The sample program defines a series of templates. B takes a default type argument, C a default non-type argument, and D a default argument of type template. The result of running the program is:
sizeof U = 1 sizeof U = 4 N = 200 N = 100 A::f()
Supported
Supported
Supported