我想以不同的方式处理模板参数,因此对于代码:
template <class T> class A {
public:
A() {}
};
void faa(A<int>& param);
我想知道 param 是模板专业化并可以访问它的参数。
所以我写了一个ASTVisitor
with 函数
bool VisitFunctionDecl(FunctionDecl *f) {
std::cout<< "VisitFunctionDecl" <<std::endl;
const DependentTemplateSpecializationType* t1;
const TemplateSpecializationType* t2;
for(ParmVarDecl* p :f->params())
{
t1=p->getType()->getAs<DependentTemplateSpecializationType>();
t2=p->getType()->getAs<TemplateSpecializationType>();
if(t1!=nullptr||t2!=nullptr)
{
std::cout<< "template param found" <<std::endl;
}
}
return true;
}
但这些演员nullptr
总是 - 我从来没有得到template param found
输出。
我究竟做错了什么?有没有其他方法可以将 t 转换为允许检查模板参数的类型之王?