It might not be exactly what you want, but gcc provides __PRETTY_FUNCTION__ which ends up printing the type of T for you:
- #include <iostream>
-
#include <string>
-
using namespace std;
-
-
template <typename T>
-
void WhatEver(void)
-
{
-
T t;
-
cout << __PRETTY_FUNCTION__ << endl;
-
}
-
-
int main()
-
{
-
WhatEver<int>();
-
WhatEver<long>();
-
WhatEver<string>();
-
-
return 0;
-
}
-
output:
void WhatEver() [with T = int]
void WhatEver() [with T = long int]
void WhatEver() [with T = std::basic_string<char, std::char_traits<char>, std::allocator<char> >]
If you aren't using gcc maybe you can look under it's hood to find out how __PRETTY_FUNCTION__ works?