Boost logo

Boost :

Subject: Re: [boost] [shared_ptr] enable_shared_from_any ?
From: Frank Mori Hess (frank.hess_at_[hidden])
Date: 2010-05-17 09:20:34


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Saturday 15 May 2010, Philip Warner wrote:
> And yes, this is sloppy, but in our case we have a set of interfaces
> that want to implement variant function return types based on derived
> class pointers, and we can not do that by returning shared_ptr objects.
> We need to return raw pointers, then rewrap them.

Are you saying you want to have a covariant return types with shared_ptr?
Have you considered doing something like the following (completely untested):

class Base
{
        typedef X FReturnType;
private:
        template<typename T>
        friend shared_ptr<T::FReturnType> g(T &t);
        virtual FReturnType* f();
};
class Derived: public Base
{
public:
        typedef DerivedFromX FReturnType;
private:
        template<typename T>
        friend shared_ptr<T::FReturnType> g(T &t);
        virtual FReturnType* f();
}
template<typename T>
shared_ptr<typename T::FReturnType> g(T &t)
{
        return shared_ptr<typename T::FReturnType>(t.f());
}

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkvxQqIACgkQ5vihyNWuA4WqXACcCVjVolqyngjpqlZyIsuN6bTR
XY4Anj5sz8ZrcZ7l/Eih+iPsKYa7nGyY
=w5TK
-----END PGP SIGNATURE-----


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