tags:

views:

73

answers:

2

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 expression 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 )?

+2  A: 
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(){}
Chubsdad
@Chubsdad:Here ..we can return the size of array by using sizof();
BE Student
@BE Student: I am not able to understand your question
Chubsdad
template<class T>int f(T){return sizof(T[15]);} is this correct..according to the statement
BE Student
I think you mean 'sizeof'. Yes. It is correct. In this case the expression 'sizeof(T[15])' is a dependent expression as it depends on the template parameter T
Chubsdad
yes it is sizeof(),Thanks for your answers and replies
BE Student
+5  A: 

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
};
Tony