A template argument that is equivalent to a template
parameter can be used in place of that
template parameter in a reference to the current instantiation
. For a template
type-parameter,
a template argument is equivalent to a template parameter
if it denotes the same type
. For a non-type template parameter,
a template argument is equivalent to a template parameter
if it is an
identifier that names a variable
that is equivalent to the template parameter
. A variable is equivalent to a template parameter if
- it has the same type as the template parameter
(ignoring cv-qualification) and
- its initializer consists of a single identifier
that names the template parameter or, recursively, such a variable.
[
Note 1:
Using a parenthesized variable name breaks the equivalence
. —
end note]
[
Example 1:
template <class T> class A {
A* p1;
A<T>* p2;
A<T*> p3;
::A<T>* p4;
class B {
B* p1;
A<T>::B* p2;
typename A<T*>::B* p3;
};
};
template <class T> class A<T*> {
A<T*>* p1;
A<T>* p2;
};
template <class T1, class T2, int I> struct B {
B<T1, T2, I>* b1;
B<T2, T1, I>* b2;
typedef T1 my_T1;
static const int my_I = I;
static const int my_I2 = I+0;
static const int my_I3 = my_I;
static const long my_I4 = I;
static const int my_I5 = (I);
B<my_T1, T2, my_I>* b3;
B<my_T1, T2, my_I2>* b4;
B<my_T1, T2, my_I3>* b5;
B<my_T1, T2, my_I4>* b6;
B<my_T1, T2, my_I5>* b7;
};
—
end example]