The following code prints out the string “T” not the actual typename when the templated function is called. Is there a way to get the real typename without adding anything to the types being templated?
#define stringify(a) #a
#define tostring(a) stringify(a)
template <typename T>
void function_foo(T a, T b)
{
cout << tostring(T) << endl;
...
}
Templates don’t work like that. In your template
Tspecifies a type, and not a sequence of tokens:There is no way to get
lolztypeorlulztyperespectively. What you could try is usingtypeid(T).name(), but that isn’t very helpful because it isn’t required to be human readable and not even required to be distinct for each type.You could try using geordi’s file
type_strings.hpp, which can print out a human readable string when compiled with GCC.