Short version of my question:
When I tried to boost::bind io_service::post like this:
boost::bind(&boost::asio_io_service::post, &ios,
boost::bind(&MyClass::func, this, arg1, arg2));
I get errors like this:
error: no matching function for call to ‘bind(<unresolved overloaded function type>,
boost::asio::io_service*, boost::_bi::bind_t<void, boost::_mfi::mf2<void, MyClass,
const char*, const char*>, boost::_bi::list3<boost::_bi::value<MyClass*>,
boost::_bi::value<const char*>, boost::_bi::value<const char*> > >)’
How can I fix this?
Very simple test code: http://pastebin.com/V0uyLywC
Long version of my question:
I'm trying to write a generic event queue class, which you can add different types of events to the queue. You can subscribe to events by types, when that type of events is added, the subscribed callback function will be called.
An event queue object can potentially be subscribed by a different thread group from a different io_services. The internal queue of this class will be thread-safe using boost::lockfree:queue or boost::interprocess::message_queue (if this will be inter-process in the future). And the subscribed callback function will need to be called by its corresponding io_service's post, hence the attempted nested boost::bind above.
Is this a good and workable design?
Assuming this approach will work, I figured then an alternative would be also passing the io_service when you subscribe, but I was thinking 1) perhaps this class can be used when it does not involve io_services, and 2) this class shouldn't need to know about io_service.
Thanks all.
P.S. I have read boost::bind composition inside io_service::post function but it feels a bit different to my problem.