
13 Feb
2013
13 Feb
'13
6:19 p.m.
btw just curious, why didn't you call do_something_sync() directly in post() instead of through a lambda?
Without lambda I'd have to create a binder: boost::bind(&class_name::do_something_sync, this). It's just a bit more verbose :). But in a real code there's also another point: usually it's preferable to use shared_from_this idiom with async functions, to simplify control over object lifetime. So it would be either { io_.post(bind(&class_name::do_something_sync, shared_from_this())); } or { auto self = shared_from_this(); io_.post([=] { self->do_something_sync(); }); } ...so the bind version already looks less verbose.