I would like to know if it is possible to know and output a template class name at compile time. It would look like something like this:
template<typename T>
class SomeTemplateClass
{
SOME_WAY_TO_PRINT_CLASS_NAME(T)
};
Then, each time the template class is called, for example:
using C = SomeTemplateClass<std::string>;
or
SomeTemplateClass<std::string> instance;
The compiler would echo a message like:
note: Template argument of SomeTemplateClass is std::__cxx11::basic_string<char>
As far as I searched, I found one way, that crashes the compiler to give the type of the class:
template<typename T>
class SomeTemplateClass
{
public:
using print = typename T::expected_crash;
};
using C = SomeTemplateClass<std::string>;
int main()
{
C::print err;
return 0;
}
That gives:
error: no type named ‘expected_crash’ in ‘class std::__cxx11::basic_string<char>’
But it is more a hack than a clean solution, and I was wondering if there was an other solution to this problem.
Thanks!