This is the statement from ISO C++ Standard 14.6.2.1: Dependent types :
A type is dependent if it is
— a template parameter,#1
— a qualified-id with a nested-name-specifier which contains a class-name
that names a dependent type or whose unqualified-id names a dependent type,#2
— a cv-qualified type where the cv-unqualified type is dependent, #3
— a compound type constructed from any dependent type,#4
— an array type constructed from any dependent type or whose size is specified
by a constant expressio开发者_Go百科n that is value-dependent, #5
— a template-id in which either the template name is a template parameter
or any of the template arguments is a dependent type or an expression
that is type-dependent or value-dependent.#6
I am unable to understand the last two points?
Can any one give examples for these statements(especially for last #5,#6 )?
Working from 1) a type is dependent if it is a template parameter
:
template <typename T, int N, template <typename> class My_Template>
struct X
{
5 — an array type constructed from any dependent type or whose size is specified by a constant expression that is value-dependent,
T a[5]; // array of dependent type
int b[N]; // value-dependent size
6 — a template-id in which either the template name is a template parameter
or any of the template arguments is a dependent type or an expression
that is type-dependent or value-dependent.
My_Template<int> c; // template parameter
Some_Template<T> d; // template argument is dependent
Another_Template<sizeof c> e; // type-dependent expression
Another_Template<N> f; // value-dependent expression
};
template<class T> struct Base{
};
template<class T, int n, template<class X> class U> struct Derived : Base<T>{
T array1[10]; // #5
int array2[n]; // #5
U<T> u; // #6
Base<T> b; // #6
};
int main(){}
精彩评论