
From: "Dean Michael Berris" <mikhailberis@gmail.com>
... I suppose this can be done with a pointer to a boost::asio::io_service and a flag that says whether the io_service is owned or provided by reference.
Unless I'm missing something, no flag is needed (warning - uncompiled code, but based on real compilable code): class some_net_lib { public: // use internal io_service some_net_lib() : io_service_ptr(new boost::asio::io_service), io_service_(*io_service_ptr) { } // use io_service provided by user some_net_lib(boost::asio::io_service& ios) : io_service_ptr(), io_service_(ios) { } private: // careful - declaration order of these two is very important std::auto_ptr<boost::asio::ios_service> io_service_ptr; boost::asio::ios_service& io_service_; }; Obviously, all of the internal / implementation code will use io_service_. Cliff