【发布时间】:2014-09-12 18:49:31
【问题描述】:
我怎样才能将模板函数传递给异步?
代码如下:
//main.cpp
#include <future>
#include <vector>
#include <iostream>
#include <numeric>
int
main
()
{
std::vector<double> v(16,1);
auto r0 = std::async(std::launch::async,std::accumulate,v.begin(),v.end(),double(0.0));
std::cout << r0.get() << std::endl;
return 0;
}
以下是错误消息:
^ a.cpp:13:88: 注意:候选人是: 在 a.cpp:1:0 包含的文件中: /usr/include/c++/4.8/future:1523:5: 注意:模板 std::future::type> std::async(std::launch, _Fn&&, _Args&& ...) 异步(启动 __policy,_Fn&& __fn,_Args&&... __args) ^ /usr/include/c++/4.8/future:1523:5:注意:模板参数推导/替换失败: a.cpp:13:88:注意:无法推断模板参数“_Fn” auto r0 = std::async(std::launch::async,std::accumulate,v.begin(),v.end(),double(0.0)); ^ 在 a.cpp:1:0 包含的文件中: /usr/include/c++/4.8/future:1543:5: 注意:模板 std::future::type> std::async(_Fn&&, _Args&& ...) 异步(_Fn&& __fn,_Args&&... __args) ^ /usr/include/c++/4.8/future:1543:5:注意:模板参数推导/替换失败: /usr/include/c++/4.8/future: 代替'template std::future::type> std::async(_Fn&&, _Args&& ...) [with _Fn = std::launch; _Args = {}]’: a.cpp:13:88: 从这里需要 /usr/include/c++/4.8/future:1543:5: 错误:‘class std::result_of’中没有名为‘type’的类型【问题讨论】:
标签: c++ algorithm c++11 templates stdasync