title: C++11: cannot convert argument from 'T *const' to 'T *&&'
body: <p>I have variadic template class representing a thread with function and input arguments.</p>
  
  <pre><code>template&lt;typename F&gt; class my_thread;
  
  template&lt;typename Return, typename... Input&gt;
  class my_thread&lt;Return(Input...)&gt;
  {
      template&lt;typename F&gt;
      my_thread(F&amp;&amp; f, Input&amp;&amp;... value) : /* mainly std::forward&lt;Input&gt;... to std::tuple&lt;Input...&gt; */ { }
  }
  </code></pre>
  
  <p>Now, instancing that class is simple for global functions</p>
  
  <pre><code>int fnc(int, double);
  my_thread&lt;int(int, double)&gt; thr(fnc, 42, 3.14);
  </code></pre>
  
  <p>It is (obviously) not that simple for function members of some class.</p>
  
  <pre><code>my_thread&lt;int(int, double)&gt; thr(&amp;Foo::fnc, 42, 3.14); // won't work, unless Foo::fnc is static.
  </code></pre>
  
  <p>I know, that <code>std::thread</code>, has some mechanics (probably partial specialization), which allows non-static member functions to be passed, if, before all arguments, pointer to instance of that class is passed (<code>std::thread(&amp;Foo::bar, Foo(), 42, 3.14); // OK</code>). I was not able to find out how to make that happen, so my <code>my_thread</code> requires static member functions to be passed, and pointer to instance of that class has to be excplicit argument of that function.</p>
  
  <pre><code>struct Dog
  {
      void bark();
      static void bark(Dog* dog)
      {
          dog-&gt;bark();
      }
  }
  </code></pre>
  
  <p>That is something I have to live with, but that is not problem.<br>
  Problem is instantiating <code>my_thread</code> with that function. I wrote <code>my_thread&lt;int(Foo*, double)&gt; thr(&amp;Foo::bar, this, 3.14);</code> into Visual Studio 2015 and it complained about</p>
  
  <blockquote>
    <p>error C2664: 'my_thread&lt;int (Foo &#42;, double)>::my_thread(my_thread&lt;int (Foo &#42;, double)> &amp;&amp;)': cannot convert argument 2 from 'Foo &#42;const ' to 'Foo &#42;&amp;&amp;'</p>
  </blockquote>
  
  <p>I tried some magic with casting, but then, I found out, that passing <code>&amp;*this</code> instead of <code>this</code> works.</p>
  
  <p>I was happy to find out solution (or at least something that compiles and runs on Windows) and I decided to try it on linux with G++. I used same code (using <code>&amp;*this</code>), but G++ was angry at me, because</p>
  
  <blockquote>
    <p>In member function 'void Foo::SomeFunction()':
      error: no matching function for call to ‘my_thread&lt;int(Foo&#42;,
      double)>::my_thread(int (&#42;)(Foo&#42;, double), Foo&#42; const, double&amp;)’<br>
     note: candidates are: my_thread(F&amp;&amp;, Input&amp;&amp;...)<br>
     note: template argument deduction/substitution failed:<br>
    note:   cannot convert ‘this’ (type ‘Foo&#42; const’) to type ‘Foo*&amp;&amp;’</p>
  </blockquote>
  
  <p>I was quite surprised that I got pretty much same error as before. I edited back <code>&amp;*this</code> to just <code>this</code> and I was able to compile and run that on G++ under linux.</p>
  
  <p><strong>My question is:</strong><br>
  Who is right? G++ 4.9.2 or MVS2015? How do I solve it, so that my code can be run on both platforms?<br>
  Or, am I using bad approach to that? How is std::thread implemented, such that it knows, that when non-static member function is passed, it will require pointer to instance of that class as an argument?</p>
  
  <hr>
  
  <p><strong>EDIT</strong><br>
  I am adding more code, so that my intention will be clearer.</p>
  
  <pre><code>template&lt;typename F&gt; struct my_thread; // std::function like syntax
  
  template&lt;typename Return, typename... Input&gt;
  struct my_thread&lt;Return(Input...)&gt;
  {
      struct thread_data
      {
          template&lt;typename F&gt;
          thread_data(F&amp;&amp; _func, Input&amp;&amp;... _input) : func(std::forward&lt;F&gt;(_func)), input(std::forward&lt;Input&gt;(_input)...) { }
  
          std::function&lt;Return(Input...)&gt; func;
          std::tuple&lt;Input...&gt; input;
      };
  
      template&lt;typename F&gt;
      my_thread(F&amp;&amp; _func, Input&amp;&amp;... _input) : data(std::forward&lt;F&gt;(_func), std::forward&lt;Input&gt;(_input)...) { }
  
      thread_data data;
  };
  </code></pre>