Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the type of T?

Tags:

c++

templates

In the code below:

template<typename T>
struct X {};

int main()
{
  X<int()> x; // what is the type of T ?
}

What is the type of T? I saw something like this in the boost sources.

like image 960
big-z Avatar asked Aug 20 '10 11:08

big-z


People also ask

What is the meaning of type T?

Psychology A personality type that takes risks; type Ts tend to be extroverted and creative, and crave novel experiences and excitement. See Extreme sports, Novelty seeking behavior.

What is T and K in TypeScript?

keyof T returns a union of string literal types. The extends keyword is used to apply constraints to K , so that K is one of the string literal types only. extends means “is assignable” instead of “inherits”; K extends keyof T means that any value of type K can be assigned to the string literal union types.

What is t-test used for?

The t-test, also known as t-statistic or sometimes t-distribution, is a popular statistical tool used to test differences between the means (averages) of two groups, or the difference between one group's mean and a standard value.

What do you compare the t-value to?

The calculations behind t-values compare your sample mean(s) to the null hypothesis and incorporates both the sample size and the variability in the data. A t-value of 0 indicates that the sample results exactly equal the null hypothesis.


2 Answers

Consider the function int func(). It has a function type int(void). It can be implicitly converted to pointer type as the C++ Standard says in 4.3/1, but it this case there's no need in such conversion, so T has the function type int(void), not a pointer to it.

like image 114
Kirill V. Lyadvinsky Avatar answered Nov 13 '22 10:11

Kirill V. Lyadvinsky


Here is what I did. Though the output of code below is implementation specific, many times it gives a good hint into the type of T that we are dealing with.

template<typename T> 
struct X {
   X(){
      cout << typeid(T).name();
   }
}; 

int main() 
{ 
  X<int()> x; // what is the type of T ? 
  cout << typeid(int()).name() << endl;
} 

The output on VC++ is

int __cdecl(void)

int __cdecl(void)

like image 35
Chubsdad Avatar answered Nov 13 '22 11:11

Chubsdad