How do you post a boost packaged_task to an io_service in C++03?
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<bool> task_t; boost::shared_ptr<task_t> task = boost::make_shared<task_t>( boost::bind(&process_data, i, theTime)); io_service.post(boost::bind(&task_t::operator(), task));