【发布时间】:2016-07-02 03:07:28
【问题描述】:
我遇到了以下 sn-p 的问题:
std::promise<int> promise;
auto operation = [](std::promise<int> promise) { promise.set_value(1); };
auto fn = std::bind(operation, std::move(promise));
fn();
使用clang 我得到以下错误:
候选模板被忽略:替换失败 [with _Args = ]: 未定义模板 'std::__1::__bind_return, std::__1::tuple, false>' 运算符()(_Args&& ...__args)
提前致谢!
【问题讨论】:
-
你想要移动捕捉。
std::bind不能那样做。 Lambda can do it starting with C++14,但不在 C++11 中。 -
@IgorTandetnik
std::bind可以很好地进行移动捕获。问题是它将捕获的东西作为左值传递。 -
您的标题具有误导性:您当前的代码中没有
std::function。