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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### General <a id="temp.arg.general">[[temp.arg.general]]</a>
|
| 2 |
+
|
| 3 |
+
There are three forms of *template-argument*, corresponding to the three
|
| 4 |
+
forms of *template-parameter*: type, non-type and template. The type and
|
| 5 |
+
form of each *template-argument* specified in a *template-id* shall
|
| 6 |
+
match the type and form specified for the corresponding parameter
|
| 7 |
+
declared by the template in its *template-parameter-list*. When the
|
| 8 |
+
parameter declared by the template is a template parameter pack
|
| 9 |
+
[[temp.variadic]], it will correspond to zero or more
|
| 10 |
+
*template-argument*s.
|
| 11 |
+
|
| 12 |
+
[*Example 1*:
|
| 13 |
+
|
| 14 |
+
``` cpp
|
| 15 |
+
template<class T> class Array {
|
| 16 |
+
T* v;
|
| 17 |
+
int sz;
|
| 18 |
+
public:
|
| 19 |
+
explicit Array(int);
|
| 20 |
+
T& operator[](int);
|
| 21 |
+
T& elem(int i) { return v[i]; }
|
| 22 |
+
};
|
| 23 |
+
|
| 24 |
+
Array<int> v1(20);
|
| 25 |
+
typedef std::complex<double> dcomplex; // std::complex is a standard library template
|
| 26 |
+
Array<dcomplex> v2(30);
|
| 27 |
+
Array<dcomplex> v3(40);
|
| 28 |
+
|
| 29 |
+
void bar() {
|
| 30 |
+
v1[3] = 7;
|
| 31 |
+
v2[3] = v3.elem(4) = dcomplex(7,8);
|
| 32 |
+
}
|
| 33 |
+
```
|
| 34 |
+
|
| 35 |
+
— *end example*]
|
| 36 |
+
|
| 37 |
+
The template argument list of a *template-head* is a template argument
|
| 38 |
+
list in which the nᵗʰ template argument has the value of the nᵗʰ
|
| 39 |
+
template parameter of the *template-head*. If the nᵗʰ template parameter
|
| 40 |
+
is a template parameter pack [[temp.variadic]], the nᵗʰ template
|
| 41 |
+
argument is a pack expansion whose pattern is the name of the template
|
| 42 |
+
parameter pack.
|
| 43 |
+
|
| 44 |
+
In a *template-argument*, an ambiguity between a *type-id* and an
|
| 45 |
+
expression is resolved to a *type-id*, regardless of the form of the
|
| 46 |
+
corresponding *template-parameter*.[^3]
|
| 47 |
+
|
| 48 |
+
[*Example 2*:
|
| 49 |
+
|
| 50 |
+
``` cpp
|
| 51 |
+
template<class T> void f();
|
| 52 |
+
template<int I> void f();
|
| 53 |
+
|
| 54 |
+
void g() {
|
| 55 |
+
f<int()>(); // int() is a type-id: call the first f()
|
| 56 |
+
}
|
| 57 |
+
```
|
| 58 |
+
|
| 59 |
+
— *end example*]
|
| 60 |
+
|
| 61 |
+
[*Note 1*: Names used in a *template-argument* are subject to access
|
| 62 |
+
control where they appear. Because a *template-parameter* is not a class
|
| 63 |
+
member, no access control applies. — *end note*]
|
| 64 |
+
|
| 65 |
+
[*Example 3*:
|
| 66 |
+
|
| 67 |
+
``` cpp
|
| 68 |
+
template<class T> class X {
|
| 69 |
+
static T t;
|
| 70 |
+
};
|
| 71 |
+
|
| 72 |
+
class Y {
|
| 73 |
+
private:
|
| 74 |
+
struct S { ... };
|
| 75 |
+
X<S> x; // OK, S is accessible
|
| 76 |
+
// X<Y::S> has a static member of type Y::S
|
| 77 |
+
// OK, even though Y::S is private
|
| 78 |
+
};
|
| 79 |
+
|
| 80 |
+
X<Y::S> y; // error: S not accessible
|
| 81 |
+
```
|
| 82 |
+
|
| 83 |
+
— *end example*]
|
| 84 |
+
|
| 85 |
+
For a *template-argument* that is a class type or a class template, the
|
| 86 |
+
template definition has no special access rights to the members of the
|
| 87 |
+
*template-argument*.
|
| 88 |
+
|
| 89 |
+
[*Example 4*:
|
| 90 |
+
|
| 91 |
+
``` cpp
|
| 92 |
+
template <template <class TT> class T> class A {
|
| 93 |
+
typename T<int>::S s;
|
| 94 |
+
};
|
| 95 |
+
|
| 96 |
+
template <class U> class B {
|
| 97 |
+
private:
|
| 98 |
+
struct S { ... };
|
| 99 |
+
};
|
| 100 |
+
|
| 101 |
+
A<B> b; // error: A has no access to B::S
|
| 102 |
+
```
|
| 103 |
+
|
| 104 |
+
— *end example*]
|
| 105 |
+
|
| 106 |
+
When template argument packs or default *template-argument*s are used, a
|
| 107 |
+
*template-argument* list can be empty. In that case the empty `<>`
|
| 108 |
+
brackets shall still be used as the *template-argument-list*.
|
| 109 |
+
|
| 110 |
+
[*Example 5*:
|
| 111 |
+
|
| 112 |
+
``` cpp
|
| 113 |
+
template<class T = char> class String;
|
| 114 |
+
String<>* p; // OK, String<char>
|
| 115 |
+
String* q; // syntax error
|
| 116 |
+
template<class ... Elements> class Tuple;
|
| 117 |
+
Tuple<>* t; // OK, Elements is empty
|
| 118 |
+
Tuple* u; // syntax error
|
| 119 |
+
```
|
| 120 |
+
|
| 121 |
+
— *end example*]
|
| 122 |
+
|
| 123 |
+
An explicit destructor call [[class.dtor]] for an object that has a type
|
| 124 |
+
that is a class template specialization may explicitly specify the
|
| 125 |
+
*template-argument*s.
|
| 126 |
+
|
| 127 |
+
[*Example 6*:
|
| 128 |
+
|
| 129 |
+
``` cpp
|
| 130 |
+
template<class T> struct A {
|
| 131 |
+
~A();
|
| 132 |
+
};
|
| 133 |
+
void f(A<int>* p, A<int>* q) {
|
| 134 |
+
p->A<int>::~A(); // OK, destructor call
|
| 135 |
+
q->A<int>::~A<int>(); // OK, destructor call
|
| 136 |
+
}
|
| 137 |
+
```
|
| 138 |
+
|
| 139 |
+
— *end example*]
|
| 140 |
+
|
| 141 |
+
If the use of a *template-argument* gives rise to an ill-formed
|
| 142 |
+
construct in the instantiation of a template specialization, the program
|
| 143 |
+
is ill-formed.
|
| 144 |
+
|
| 145 |
+
When name lookup for the component name of a *template-id* finds an
|
| 146 |
+
overload set, both non-template functions in the overload set and
|
| 147 |
+
function templates in the overload set for which the
|
| 148 |
+
*template-argument*s do not match the *template-parameter*s are ignored.
|
| 149 |
+
|
| 150 |
+
[*Note 2*: If none of the function templates have matching
|
| 151 |
+
*template-parameter*s, the program is ill-formed. — *end note*]
|
| 152 |
+
|
| 153 |
+
When a *simple-template-id* does not name a function, a default
|
| 154 |
+
*template-argument* is implicitly instantiated [[temp.inst]] when the
|
| 155 |
+
value of that default argument is needed.
|
| 156 |
+
|
| 157 |
+
[*Example 7*:
|
| 158 |
+
|
| 159 |
+
``` cpp
|
| 160 |
+
template<typename T, typename U = int> struct S { };
|
| 161 |
+
S<bool>* p; // the type of p is S<bool, int>*
|
| 162 |
+
```
|
| 163 |
+
|
| 164 |
+
The default argument for `U` is instantiated to form the type
|
| 165 |
+
`S<bool, int>*`.
|
| 166 |
+
|
| 167 |
+
— *end example*]
|
| 168 |
+
|
| 169 |
+
A *template-argument* followed by an ellipsis is a pack expansion
|
| 170 |
+
[[temp.variadic]].
|
| 171 |
+
|