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