テンプレート関数を非同期に渡すにはどうすればよいですか?
コードは次のとおりです。
//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&& ...)
async(launch __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&& ...)
async(_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: エラー: 'type' という名前の型が 'class std::result_of' にありません