title: How to extract tuple into a function parameters
body: <p>I'm working with C++ on Linux and I need to develop a common library to simplify the multi-threading development.</p>
  <p>Well, I know that there are some mechanism of multi-threading in C++11, such as <code>std::async</code>, <code>std::future</code> etc. But I have to work with <code>pthread</code> because of some historical reason.</p>
  <p>Basically, what I'm trying to do is to make a very very simple template function, which is kind of like <code>std::future</code>. Here it is.</p>
  <pre><code>template&lt;typename S&gt;
  struct signature;
  
  template&lt;typename R, typename... Args&gt;
  struct signature&lt;R(*)(Args...)&gt; {
      using return_type = R;
      using argument_type = std::tuple&lt;R(*)(Args...), Args...&gt;; // f, args...
  };
  
  template&lt;typename F, typename... Args&gt;
  void func(F* f, Args&amp;&amp;... args) {
      typename signature&lt;decltype(f)&gt;::argument_type tp = std::make_tuple(f, std::forward&lt;Args&gt;(args)...);
      pthread_t td;
      pthread_create(&amp;td, nullptr, [](void *p){
              auto param = static_cast&lt;typename signature&lt;decltype(f)&gt;::argument_type*&gt;(p);
              std::get&lt;0&gt;(*param)(std::get&lt;1&gt;(*param)); // ???
              return (void*)nullptr;
              }, &amp;tp);
  }
  
  void f(int a) {}
  void f2(int a, int b) {}
  
  int main() {
      func(f, 1);
      // func(f2, 2, 2); ERROR!
  
      return 0;
  }
  </code></pre>
  <p>In a word, I try to wrap the parameters of the function into a tuple and pass the tuple into the third parameter of <code>pthread_create</code>, which is a labmda.</p>
  <p>So in the piece of code, <code>std::get&lt;0&gt;(*param)</code> is the function, and the rest part of the tuple <code>*param</code> is the parameter list which should be passed to the function. But I don't know how to expand it. Obvisouly, <code>std::get&lt;0&gt;(*param)(std::get&lt;1&gt;(*param));</code> is not OK because it can only handle the function with one parameter. If I want to pass a function with two parameters, I will get an error.</p>
  <p>So how to expand the tuple there?</p>
  <p>BTW, please ignore other issues, such as why don't call <code>pthread_join</code>. I just remove them here to minimize my post.</p>