[cfe-dev] Getting the corresponding template parameters of a template argument list in partial template specializations
Douglas Gregor
dgregor at apple.com
Mon Jul 26 09:39:03 PDT 2010
On Jul 26, 2010, at 2:40 AM, Olivier wrote:
> Hi,
>
> I'm trying to figure out how I can retrive the template parameters that
> correspond to certain template arguments in the template argument list of a
> partial template specialization (ouf), i.e. :
>
> template< typename Tp0, int N0, typename Tp1, int N1 >
> struct Foo
> { /* ... */ }
>
> template< typename Tp0, int N1 >
> struct Foo<Tp0,1,short,N1>
> { /* ... */ }
>
> In this example, the TemplateArgumentList object I get from the
> ClassTemplatePartialSpecializationDecl will contain 4 template arguments :
>
> - One of kind TemplateArgument::Type
> - One of kind TemplateArgument::Integral
> - One of kind TemplateArgument::Type
> - One of kind TemplateArgument::Expression
>
> And a TemplateParameters of two elements.
>
> I can't seem to figure out how to get the identifier of template arguments of
> type TemplateArgument::Expression. How can I achieve this ?
Get the expression (an Expr*) from the template argument. It'll be a DeclRefExpr that refers to the NonTypeTemplateParmDecl for N1.
> As a more general question, I would like to be able to print
> out "<Tp0,1,short,N1>" from the corresponding
> ClassTemplatePartialSpecialization object. What is the best way to do this ?
ClassTemplatePartialSpecializationDecl::getTemplateArgsAsWritten() will give you the template arguments as written.
- Doug
More information about the cfe-dev
mailing list