
Paul Mensonides wrote: [...]
template<class T, class M, class C> inline typename closure<M C::*>::type operator->*(const std::auto_ptr<T>& sp, M C::* member) { return make_closure(&*sp, member); }
[...]
Basically, the implementation above does all the work necessary to implement operator->* once and for all (for any number of different smart pointers). The only things that one might need to change for a particular smart pointer is how the smart pointer is passed to operator->* and how the raw pointer is accessed:
template<class T, class M, class C> inline typename closure<M C::*>::type operator->*(boost::shared_ptr<T> sp, M C::* member) { return make_closure(sp.get(), member); }
template<class T> class smart_ptr { // ... public: template<class M, class C> inline typename closure<M C::*>::type operator->*(M C::* member) { return make_closure(get(), member); } // ... };
You don't have to change the implementation of ->* depending on the smart pointer type. *p is always the dereference operation, and (proxy references notwithstanding) &*p is always a raw pointer to the pointee. get() is needed for cases when the source is NULL, but we need not worry about them here, as ->* isn't allowed. So: template<class P, class M, class C> inline typename closure<M C::*>::type operator->*( P p, M C::* member) { return make_closure( &*p, member ); } It would work for iterators, too.