How to perform template substitution in the clang library

Hi all,

Specifically, we have a C++ source file like this:

template
struct N {};

struct B {
template
using A = typename std::conditional<std::is_same<M, N<4>>::value,
int*, void*>::type;
};

template <typename T, T value>
struct F : B {};

template <>
struct F<decltype(&fopen), &fopen> : B {
template
using A = double*;
};

template <>
struct F<decltype(&fclose), &fclose> : B {
template
using A = typename std::conditional<std::is_same<M, N<16>>::value,
void*, char**>::type;
};

// More specialization of ‘F’ follows.

It is easy to find the ClassTemplateDecls](http://clang.llvm.org/doxygen/classclang_1_1ClassTemplateDecl.html)s) of N and F, and the QualType and FunctionDecl of the function pointers &fopen, &fclose, etc. But the problem is how to substitute these arguments into N, F and F::A without modifying the source code.

The question is:

  • How do I evaluate F<decltype(&fprintf), &fprintf>::A<N<4>> and know that it is an int*?
  • How do I evaluate F<decltype(&fopen), &fopen>::A<N<7>> and know that it is a double*?
  • and so on…

Kind regards
Stewart