Passing C functions and parameters as rvalue references
<p>I'm trying to retrofit two pieces of legacy code. One of the pieces implements a timeout for a function call. So far it's been used on C++ methods and works perfectly.</p>

<p>Now, there's a requirement to implement a similar timeout to an older C library. I'm trying to use the same code for this, but running into issues.</p>

<p>Here's a simplified version of the code, with the problem I'm facing.</p>

<pre><code>uint32_t myFunc1()
{
    return 0;
}

uint32_t myFunc2(uint32_t a)
{
    return a;
}

int main()
{
    uint32_t dummy = 1;
    timedCall(myFunc1); //compiles fine. 
    timedCall(myFunc2, dummy); //compile errors C2672, C2893
}

template &lt;class F, class... Args&gt;
uint32_t timedCall(F &amp;&amp;f, Args&amp;&amp;... a)
{
    try
    {
        std::packaged_task&lt;uint32_t(Args...)&gt; myTask(std::bind(f, a...));
        auto res = myTask.get_future();
        std::thread(std::move(myTask), a...).detach(); //This is where the issue is.        

        //Do other stuff
    }
    catch(...)
    {
        //handle exceptions
    }

    return 0; //return something
}
</code></pre>

<p>I get the following errors:</p>

<pre><code>C2672   'std::invoke': no matching overloaded function found
C2893   Failed to specialize function template 'unknown-type std::invoke(_Callable &amp;&amp;,_Types &amp;&amp;...)'
</code></pre>

<p>Could someone please tell me what I'm doing wrong and how to fix it? I'm using Visual Studio 2015.  </p>