In this code, how can I use decltype in std::future to deduce the return type of bar() ? Although directly using std::future<int> works, I would like to know how can decltype be used in such a situation.
#include <iostream>
#include <future>
int bar(int a)
{
return 50;
}
int main()
{
std::packaged_task<decltype(bar)> task(bar);
//std::future<decltype(bar(int))> f = task.get_future(); //doesn't work need to do something like this
std::future<int> f = task.get_future(); //works
std::thread t1(std::move(task), 10);
t1.detach();
int val = f.get();
std::cout << val << "\n";
return 0;
}
Also, is the use of decltype in std::packaged_task correct ?
Aucun commentaire:
Enregistrer un commentaire