字符串化模板参数 [英] Stringifying template arguments
本文介绍了字符串化模板参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有可能在C ++中将模板参数字符串化吗?
我试过这个:
Is it possible in C++ to stringify template arguments? I tried this:
#define STRINGIFY(x) #x
template <typename T>
struct Stringify
{
Stringify()
{
cout<<STRINGIFY(T)<<endl;
}
};
int main()
{
Stringify<int> s;
}
但是我得到的是一个'T',而不是一个' 。
But what I get is a 'T', and not an 'int'. Seems that the preprocessors kicks in before template resolution.
是否有其他方法可以执行此操作?
Is there any other way to do this?
有什么办法可以在模板解析后进行预处理? (编译器是VC ++)。
Is there any way for the preprocessing to take place after template resolution? (Compiler is VC++).
推荐答案
您可以尝试
typeid(T).name()
:根据评论修正。
这篇关于字符串化模板参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文