Is it safe to use std::bind to pass a member function to boost::signals2::signal::connect()? In other words, is boost::bind and std::bind interchangeable?
It compiles with VC++ 2010 SP1, but the template code is way over my head and I’m afraid I might be venturing into undefined behaviour territory.
The
connectfunction takes aboost::functionobject, which is basically a generic wrapper around anything that has anoperator()defined for it. Therefore it is exactly as safe as what you are binding.For example, this is reasonably safe:
This is reasonably safe because it stores a
boost::shared_ptras part of its data.This is conditionally safe. It instantly becomes unsafe if that connection still exists and you execute
delete pValue.Personally, I don’t put much faith in “conditionally safe”, but that’s up to you. The point being that everything you bind to
boost::bindmust continue to exist so long as it is bound.