This is a follow-on from a previous question (here), but I\'m working on a multithreaded application and I would like to post a Boost packaged_task to a threaded io_service.
boost::packaged_task supports boost::move since Boost version 1.50, see corresponding ticket.
But the problem is that io_service::post completion handler parameter must be CopyConstructible as noted in Asio handler requirements. Therefore boost::packaged_task cannot be posted directly or by moving. (Thanks to Igor R. for this issue).
There is workaround using pointers, e.g. you could wrap boost::packaged_task with boost::shared_ptr and bind it to operator():
typedef boost::packaged_task task_t;
boost::shared_ptr task = boost::make_shared(
boost::bind(&process_data, i, theTime));
io_service.post(boost::bind(&task_t::operator(), task));