
template< class P, class V > struct pointer_to_other; template< template<class> class P, class U, class V > struct pointer_to_other< P<U>, V > { typedef P<V> type; };
#include <boost/shared_ptr.hpp> #include <typeinfo> #include <iostream>
int main() { typedef pointer_to_other< boost::shared_ptr<int>, double >::type pointer; std::cout << typeid(pointer).name() << std::endl; }
On compilers that can't handle the above, just add partial specializations for "well known" pointer types (auto_ptr, shared_ptr).
I think this would work only with template classes with only one template parameter, like shared_ptr, but not with other smart pointers (offset_ptr or others, or future smart pointers that have some extra policy template parameters). I would propose adding a similar general well-known (at least with boost smart pointers) mechanism to obtain a pointer to other generically. Do you think this pointer_to_other is general enough to include it in the same level as get_pointer, or do you find this mechanism too particular? Regards, Ion