在from cppreference的这个描述的例子中packaged_task
,出现了一个名为的类task
。它是什么?
#include <iostream>
#include <future>
#include <thread>
int main()
{
std::packaged_task<int()> task([](){return 7;}); // wrap the function
std::future<int> result = task.get_future(); // get a future
std::thread(std::move(task)).detach(); // launch on a thread
std::cout << "Waiting...";
result.wait();
std::cout << "Done!\nResult is " << result.get() << '\n';
}