std::async を使用して std::bind で作成された関数オブジェクトを呼び出すことは可能ですか? 次のコードはコンパイルに失敗します。
#include <iostream>
#include <future>
#include <functional>
using namespace std;
class Adder {
public:
int add(int x, int y) {
return x + y;
}
};
int main(int argc, const char * argv[])
{
Adder a;
function<int(int, int)> sumFunc = bind(&Adder::add, &a, 1, 2);
auto future = async(launch::async, sumFunc); // ERROR HERE
cout << future.get();
return 0;
}
エラーは次のとおりです。
'async' の呼び出しに一致する関数がありません: 候補テンプレートは無視されました: 置換の失敗 [with Fp = std:: _1::function &, Args = <>]: 'std:: _1::__invoke_ofに 'type' という名前の型がありません、 >
std::function オブジェクトで async を使用することはできませんか、それとも何か間違っていますか?
(これは Apple LLVM 5.0 コンパイラで Xcode 5 を使用してコンパイルされています)