Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2005-01-05 14:40:21


Ion Gaztañaga wrote:

[...]

> My question is, do you find this mechanism useful to include it in
> boost in a general way, and if so, is there another way of doing this
> without
> modifying existing classes (for example, if I want use these
> mechanism with shared_ptr)?

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).


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk