How do you post a boost packaged_task to an io_service in C++03?

筅森魡賤 提交于 2019-11-30 18:41:48
Rost

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));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!