[temp.arg.general] (original) (raw)
13 Templates [temp]
13.4 Template arguments [temp.arg]
13.4.1 General [temp.arg.general]
[Example 1: template<class T> class Array { T* v;int sz;public: explicit Array(int); T& operator[](int); T& elem(int i) { return v[i]; } }; Array<int> v1(20);typedef std::complex<double> dcomplex; Array<dcomplex> v2(30); Array<dcomplex> v3(40);void bar() { v1[3] = 7; v2[3] = v3.elem(4) = dcomplex(7,8);} — _end example_]
The template argument list of a template-head is a template argument list in which the template argument has the value of the template parameter of the template-head.
If the template parameter is a template parameter pack ([temp.variadic]), the template argument is a pack expansion whose pattern is the name of the template parameter pack.
[Example 2: template<class T> void f();template<int I> void f();void g() { f<int()>(); } — _end example_]
[Note 1:
Names used in a template-argumentare subject to access control where they appear.
Because a template parameter is not a class member, no access control applies where the template parameter is used.
— _end note_]
[Example 3: template<class T> class X { static T t;};class Y { private: struct S { }; X<S> x; }; X<Y::S> y; — _end example_]
For a template argument that is a class type or a class template, the template definition has no special access rights to the members of the template argument.
[Example 4: template <template <class TT> class T> class A { typename T<int>::S s;};template <class U> class B { private: struct S { };}; A<B> b; — _end example_]
When template argument packs or default template arguments are used, a template-argument list can be empty.
[Example 5: template<class T = char> class String; String<>* p; String* q; template<class ... Elements> class Tuple; Tuple<>* t; Tuple* u; — _end example_]
An explicit destructor call ([class.dtor]) for an object that has a type that is a class template specialization may explicitly specify thetemplate-arguments.
[Example 6: template<class T> struct A { ~A();};void f(A<int>* p, A<int>* q) { p->A<int>::~A(); q->A<int>::~A<int>(); } — _end example_]
If the use of a template argument gives rise to an ill-formed construct in the instantiation of a template specialization, the program is ill-formed.
When name lookup for the component name of atemplate-idfinds an overload set, both non-template functions in the overload set and function templates in the overload set for which thetemplate-argument_s_do not match thetemplate-parameter_s_are ignored.
[Note 2:
If none of the function templates have matchingtemplate-parameters, the program is ill-formed.
— _end note_]
[Example 7: template<typename T, typename U = int> struct S { }; S<bool>* p;
The default argument for U is instantiated to form the type S<bool, int>*.
— _end example_]