2

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';
}
qdii
  • 12,505
  • 10
  • 59
  • 116

1 Answers1

4

task is an object of type std::packaged_task<int()>. It's created in the first line.

Pete Becker
  • 74,985
  • 8
  • 76
  • 165