[cfe-dev] How to perform template substitution in the clang	library
    John McCall 
    rjmccall at apple.com
       
    Sun Dec  2 23:58:00 PST 2012
    
    
  
On Dec 2, 2012, at 5:40 AM, stewart mackenzie <setori88 at gmail.com> wrote:
> Further to the question:
> 
> Kenny said:
> 
> I've got a partial solution, the only caveat is that, I can't get
> std::is_same<N<4>, N<4>>::value to return true. Well I can live with
> that, as I could just define a constexpr method which operates on the
> values directly. But I hope someone could provide a correct answer for
> this.
> 
> I have put the complete solution and the modified input to
> https://gist.github.com/4178490.
> 
> I've found that to substitute arguments into a class template and
> instantiate it, one would:
> 
>    Use the arguments to turn the ClassTemplateDecl into
> ClassTemplateSpecializationDecl, and
>    Instantiate the specialization using Sema::InstantiateClass method.
You definitely don't want to call InstantiateClass directly;
RequireCompleteType is better.  More generally, you want to
use the Sema functions to create the type you're interested in.
For a template alias, that will automatically perform the substitution,
because template aliases are not lazily substituted.
For function templates, I would suggest faking up an explicit
instantiation declaration.
John.
    
    
More information about the cfe-dev
mailing list