#include #include #include int f() { return 42; } boost::packaged_task* schedule(boost::function const& fn) { // Normally, the pointer to the packaged task is stored in a queue // for execution on a separate thread, and the schedule function // would return just a future boost::function copy(fn); boost::packaged_task* result = new boost::packaged_task(copy); return result; } int main() { boost::packaged_task* p(schedule(f)); (*p)(); boost::unique_future future = p->get_future(); std::cout << "The answer to the ultimate question: " << future.get() << std::endl; return 0; }