Reputation: 12963
In the example of this description of packaged_task
from cppreference, a class named task
appears. What is it?
#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';
}
Upvotes: 2
Views: 340
Reputation: 76325
task
is an object of type std::packaged_task<int()>
. It's created in the first line.
Upvotes: 4