
On Thu, Dec 20, 2018, 09:08 Richard Hodges via Boost <boost@lists.boost.org wrote: <...>
* Many people keep shared_ptr's to sockets, deadline_timers and so on. This is an error. All ASIO io objects are moveable. Store by value.
Hmmm... just double checking that my knowledge is up to date: there's no way to create a timer, async wait for it and pass the ownership to the callback. In other words, code like the following can not be improved in C++14: template <class Time, class Func> static void run_delayed(Time duration_or_time, const Func& f) { auto timer = std::make_unique<boost::asio::deadline_timer>( get_ios(), duration_or_time ); boost::asio::deadline_timer& timer_ref = *timer; timer_ref.async_wait( timer_task<Func>{ std::move(timer), f } ); } Not sure about C++17. Is there a way to avoid unique_ptr?