title: Perfect Forwarding Variadic Template to Standard Thread
body: <p>I'm trying to make a form of std::thread that puts a wrapper around the code executed in the thread. Unfortunately I can't get it to compile due likely to my poor understanding of rvalues and the <code>Function</code> templated type I'm trying to pass. Here's my code:</p>
  
  <pre><code>#include &lt;vector&gt;
  #include &lt;thread&gt;
  #include &lt;utility&gt;
  
  void Simple2(int a, int b) {}
  
  template &lt;typename Function, typename... Args&gt;
  void Wrapper(Function&amp;&amp; f, Args&amp;&amp;... a) {
    f(std::forward&lt;Args&gt;(a)...);
  }
  
  class Pool {
   public:
    template &lt;typename Function, typename... Args&gt;
    void Binder(Function&amp;&amp; f, Args&amp;&amp;... a) {
      std::thread t(Wrapper&lt;Function, Args...&gt;,
                    std::forward&lt;Function&gt;(f), std::forward&lt;Args&gt;(a)...);
    }
  };
  
  int main() {
    Wrapper(Simple2, 3, 4);       // Works
  
    Pool pool;
    pool.Binder(Simple2, 3, 4);   // Doesn't compile
  }
  </code></pre>
  
  <p>The Clang3.0 output that seems important here is:</p>
  
  <pre><code>/usr/include/c++/4.6/functional:1286:9: error: non-const lvalue reference to type 'void (int, int)' cannot bind to a value of unrelated type 'void (*)(int, int)'
  </code></pre>
  
  <p>and</p>
  
  <pre><code>note: in instantiation of function template specialization 'std::thread::thread&lt;void (void (&amp;)(int, int), int &amp;&amp;, int &amp;&amp;), void (&amp;)(int, int), int, int&gt;' requested here
  </code></pre>
  
  <p>Which I think is hinting at a mismatch between <code>Wrapper&lt;Function, Args...&gt;</code> and the rvalues <code>f, a...</code> being given to std::thread.</p>
  
  <p>Curiously this compiles in GCC4.9 and newer Clang if I change the <code>std::forward&lt;Function&gt;(f)</code> to <code>std::ref(f)</code>.</p>