
On Tue, Nov 16, 2010 at 3:27 AM, Cliff Green <cliffg@codewrangler.net> wrote:
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_.
Interesting. I was thinking that a unique_ptr would be more appropriate, but as it currently stands using auto_ptr might make sense in this case. It's worth a shot, thanks for the tip Cliff! -- Dean Michael Berris deanberris.com