Matthias Vallentin
2012-04-11 18:41:43 UTC
A natural fit to execute tasks asynchronously is via io_service::post.
Asio already supports moveable handlers and is on its way to integrate
nicely with C++11. Ideally, I would like to do this:
template <typename F>
std::future<typename std::result_of<F()>::type>
schedule(F f)
{
typedef typename std::result_of<F()>::type result_type;
std::packaged_task<result_type> task(f);
std::future<result_type> future = task.get_future();
io_service_.post(std::move(task)); // Impossible,
CompletionHandler requires copy-contruction.
return std::move(future);
}
Are there any plans to relax the CompletionHandler copy-constructable
requirement? For example, I could imagine on overload for
io_service::post that takes an rvalue reference. This would ensure
backwards compatibility while supporting idioms like shown above.
Matthias
Asio already supports moveable handlers and is on its way to integrate
nicely with C++11. Ideally, I would like to do this:
template <typename F>
std::future<typename std::result_of<F()>::type>
schedule(F f)
{
typedef typename std::result_of<F()>::type result_type;
std::packaged_task<result_type> task(f);
std::future<result_type> future = task.get_future();
io_service_.post(std::move(task)); // Impossible,
CompletionHandler requires copy-contruction.
return std::move(future);
}
Are there any plans to relax the CompletionHandler copy-constructable
requirement? For example, I could imagine on overload for
io_service::post that takes an rvalue reference. This would ensure
backwards compatibility while supporting idioms like shown above.
Matthias