
On Mon, 2008-05-05 at 11:13 -0400, Frank Mori Hess wrote:
What is an ADL protector? I'm not familiar with that idea. I see you added a namespace and a using statement, but what problem does it solve?
Generally, an ADL protector prevents derivation from boost::enable_shared_from_this to bring in all other functions from namespace boost. Example (try it with boost 1.35.0): #include <boost/enable_shared_from_this.hpp> #include <boost/utility.hpp> namespace A { struct X : boost::enable_shared_from_this< X > {}; template< typename T > void next( const T& ) {} } template< typename T > void prior( const T& ) {} int main() { A::X x; next( x ); prior( x ); } That is the reason why it might be a good idea to allow/require an ADL protector for enable_shared_from_this. In the example implementation I showed it also solves another problem: sp_accept_owner is called with a boost::shared_ptr as the first argument. Given that you have a class X which is *not* derived from enable_shared_from_this, it would pick up enable_shared_from_this' sp_accept_owner if it's not protected by an ADL barrier (another common name for ADL protector), since it's signature is a better match than the default sp_accept_owner(...). By adding the ADL protector, the sp_accept_owner inside the protector is only considered if the pointer passed as the second argument has an accessible base class from the same namespace (enable_shared_from_this_impl) - which can only be enable_shared_from_this<U>. Regards, Daniel