std :: function <void()>?</void()>的右值引用

时间:2014-11-03 17:59:06

标签: c++ c++11 visual-studio-2013 rvalue-reference stdthread

我正在尝试编译一些第三方代码,因为它包含类似于以下的调用,因此无法正常工作:

void async(std::function<void()> f)
{
    typedef std::function<void()> F;
    auto task_wrapper = [](F&& f){
        f();
        // some other stuff
    };
    std::async(std::launch::deferred, task_wrapper, std::move(f));
}

失败了:

error C2664: cannot convert argument 1 from 'std::function<void (void)>' to 'F &&'

我希望有人可以向我解释为什么这会失败,而其他使用参数和返回类型的调用如下所示:

template<typename Ret, typename... Args>
void threadPool::async(std::function<Ret(Args...)> f, Args... args)
{
    typedef std::function<Ret(Args...)> F;
    auto task_wrapper = [](F&& f, Args&&... args){
        f(args...);
        // other stuff
    };

    std::async(std::launch::deferred,
        task_wrapper, std::move(f), std::move(args...));
}

修改

使用Visual Studio 2013进行编译时遇到此错误。

0 个答案:

没有答案