I want to be able to create a method in a templated class that returns the name of the type subsituted in the template parameter.
eg:
template <typename T>
class CPropertyValueT
{
std::string GetTypeName()
{
return #T;
}
}
This is possible with a preprocessor macro using #, I figured there must be a way with templates.
Is this possible?
You can use
typeid(T).name(), though it will return decorated name of the type.If you’re using GCC, then you can use GCC API, declared in
cxxabi.hheader, to demangle the names.Here is an example (source):
Output:
Another interesting link that describe demangling in GCC and Microsoft VC++: