
On Fri, Jan 07, 2005 at 11:30:34AM +0100, Ion Gazta?aga wrote:
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).
Then you can add other partial specialisations: template< template<class,class> class P, class U, class V, class W > struct pointer_to_other< P<U,W>, V > { typedef P<V,W> type; }; This will work with all two-parameter smart pointer templates without having to change them. If you need it for smart pointer templates that take three parameters, add another specialisation. jon -- This space left intentionally blank.