类似于std::function,它会把结果自动到转移到future对象
int countdown (int from, int to) {
for (int i=from; i!=to; --i) {
std::cout << i << '
';
std::this_thread::sleep_for(std::chrono::seconds(1));
}
std::cout << "Lift off!
";
return from-to;
}
std::packaged_task<int(int,int)> tsk (countdown); // set up packaged_task
std::future<int> ret = tsk.get_future();