I'm trying to implement js style async/await. the function below returns a function that returns std::future object.
template <typename TResult, typename... TArgs>
std::function<std::future<TResult>(TArgs...)> async(std::function<TResult(TArgs...)> callback) {
return [=]() {
return std::async(std::launch::async, callback);
};
}
and I execute the function like below:
auto test = asyncTest([=](const std::string &text) mutable {
static int i = 0;
await(1000);
titleText.set(std::to_string(i) + text);
i++;
});
test("asdf");
I got a compile error with this thing:
error: no matching function for call to 'async'
and
note: candidate template ignored: could not match 'function<type-parameter-0-0 (type-parameter-0-1...)>' against '(lambda)'
How can I make the template infers the type of the return value and the arguments?