Boost logo

Boost :

Subject: Re: [boost] Should pass boost::asio::io_service by raw pointer or smart pointer?
From: Antony Polukhin (antoshkka_at_[hidden])
Date: 2018-12-25 12:53:07

On Thu, Dec 20, 2018, 09:08 Richard Hodges via Boost <boost_at_[hidden]

> * 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

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;


Not sure about C++17. Is there a way to avoid unique_ptr?

Boost list run by bdawes at, gregod at, cpdaniel at, john at