<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>On Nov 26, 2012, at 2:55 PM, stewart mackenzie <<a href="mailto:setori88@gmail.com">setori88@gmail.com</a>> wrote:</div><blockquote type="cite"><p>I have it on authority that the timing of my previous questions were dismal! So I'll start the question on a happy Thanksgiving note.</p><p>We have a C++ source file like this:</p><p> template <int n><br>
struct N {};</p><p> struct B {<br>
template <typename M><br>
using A = typename std::conditional<std::is_same<M, N<4>>::value,<br>
int*, void*>::type;<br>
};</p><p> template <typename T, T value><br>
struct F : B {};</p><p> template <><br>
struct F<decltype(&fopen), &fopen> : B {<br>
template <typename M><br>
using A = double*;<br>
};</p><p> template <><br>
struct F<decltype(&fclose), &fclose> : B {<br>
template <typename M><br>
using A = typename std::conditional<std::is_same<M, N<16>>::value,<br>
void*, char**>::type;<br>
};</p><p> // More specialization of 'F' follows.</p><p>It is easy to find the ClassTemplateDecls (<a href="http://clang.llvm.org/doxygen/classclang_1_1ClassTemplateDecl.html">http://clang.llvm.org/doxygen/classclang_1_1ClassTemplateDecl.html</a>) of `N` and `F`, and the<br>
QualType (<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html">http://clang.llvm.org/doxygen/classclang_1_1QualType.html</a>)<br>
and FunctionDecl (<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html</a>)<br>
of the function pointers `&fopen`, `&fclose`, etc. But the problem is<br>
how to substitute these arguments into N, F and F::A without modifying<br>
the source code.</p><p>The question is:</p><p>* How do I evaluate `F<decltype(&fprintf), &fprintf>::A<N<4>>` and<br>
know that it is an `int*`?<br>
* How do I evaluate `F<decltype(&fopen), &fopen>::A<N<7>>` and know<br>
that it is a `double*`?<br>
* and so on...</p></blockquote></div><div>Template instantiation requires an active Sema object. The interface to</div><div>Sema isn't stable, and it's not tremendously well-documented, but</div><div>basically you just want to imitiate the series of calls that the parser would</div><div>make in order to build up the type expression that you need.</div><div><br></div><div>John.</div></body></html>