title: How can I use template specialisation to find member function argument types etc?
body: <p>I'm sure I've seen this described before but can't for the life of me find it now.</p>
  
  <p>Given a class with a member function of some form, eg:</p>
  
  <pre><code>int Foo::Bar(char, double)
  </code></pre>
  
  <p>How can I use a template and various specialisations to deduce the constituent types, eg:</p>
  
  <pre><code>template&lt;typename Sig&gt;
  struct Types;
  
  // specialisation for member function with 1 arg
  template&lt;typename RetType, typename ClassType, etc...&gt;
  struct Types&lt;RetType (ClassType::*MemFunc)(Arg0)&gt;
  {
      typedef RetType return_type;
      typedef ClassType class_type;
      typedef MemFunc mem_func;
      typedef Arg0 argument_0;
      etc...
  };
  
  // specialisation for member function with 2 args
  template&lt;typename RetType, typename ClassType, etc...&gt;
  struct Types&lt;RetType (ClassType::*MemFunc)(Arg0, Arg1)&gt;
  {
      typedef RetType return_type;
      typedef ClassType class_type;
      typedef MemFunc mem_func;
      typedef Arg0 argument_0;
      typedef Arg0 argument_1;
      etc...
  };
  </code></pre>
  
  <p>Such that when I instantiate Types with my above member function, eg:</p>
  
  <pre><code>Types&lt;&amp;Foo::Bar&gt;
  </code></pre>
  
  <p>it resolves to the correct specialisation, and will declare the relevant typedefs?</p>
  
  <p>Edit:</p>
  
  <p>I'm playing around with fast-delegates with the callback statically bound to a member function. </p>
  
  <p>I have the following mockup which I believe does statically bind to the member function:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  template&lt;class class_t, void (class_t::*mem_func_t)()&gt;
  struct cb
  {
      cb( class_t *obj_ )
          : _obj(obj_)
      { }
  
      void operator()()
      {
        (_obj-&gt;*mem_func_t)();
      }
  
      class_t *_obj;
  };
  
  struct app
  {
    void cb()
    {
      std::cout &lt;&lt; "hello world\n";
    }
  };
  
  int main()
  {
    typedef cb &lt; app, &amp;app::cb &gt; app_cb;
  
    app* foo = new app;
    app_cb f ( foo );
    f();
  }
  </code></pre>
  
  <p>However - how to get this as a specialisation in the manner above?</p>