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 ?

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 ?

Thanks alot for your time,

Olivier.

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

Thanks for the help.

On another note, is there anyway to retrieve an AST representing only the input file and not the entire translation unit?

Thanks again for your time.

Best regards,

Olivier

Not directly. However, you can walk the full AST and filter out those AST nodes whose source locations don't fall in the input file. Decl::getSourceLocation() gives you the location of an AST node, and you can then use the SourceManager to decompose the source location.

- Doug