Is it possible to call function objects created with std::bind using std::async. The following code fails to compile:
#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;
}
The error is:
No matching function for call to 'async': Candidate template ignored: substitution failure [with Fp = std::_1::function &, Args = <>]: no type named 'type' in 'std::_1::__invoke_of, >
Is it just not possible to use async with std::function objects or am I doing something wrong?
(This is being compiled using Xcode 5 with the Apple LLVM 5.0 compiler)
async
get the functor arguments from? Try passing anstd::function<void()>
. – Luzluzader