title: Extracting calling convention from a function type using template metaprogramming in c++
body: <p>This is a fairly long shot, as I'm not sure it's possible, but maybe somebody more experienced than me in template metaprogramming will enlighten me.</p>
  
  <p>I'm writing an automated lua function binding system using templates, extracting the function type using partial specialization:</p>
  
  <pre><code>template&lt;typename T, T FUNCTION&gt; class Function_c;
  template&lt;typename R, R (*FUNCTION)()&gt; class Function_c&lt;R (*)(), FUNCTION&gt;; //specialized version
  </code></pre>
  
  <p>Problem is, this doesn't tell me the function calling convention, so (in VS2012 32 bits) it won't compile for __stdcall, and it will crash with __fastcall. I can create another specialized version to deal with a particular calling convention, eg:</p>
  
  <pre><code>template&lt;typename R, R (__stdcall *FUNCTION)()&gt; class Function_c&lt;R (__stdcall *)(), FUNCTION&gt;;
  </code></pre>
  
  <p>But the number of permutations is starting to get out of hand: 2 (global &amp; member functions) times max number of parameters times number of calling conventions.</p>
  
  <p>So I'm wondering if there's any way to get the calling convention as a template parameter (probably not, since it's not really a type) to cut down on the amount of copypasting.</p>