Boost logo

Boost Users :

From: Loïc Joly (loic.joly_at_[hidden])
Date: 2007-04-13 03:26:07


Peter Dimov a écrit :

>
> If you are using a Boost release, you can do:
>
> shared_ptr<Owned> getOwned( shared_ptr<Owner> p, int i )
> {
> return shared_ptr<Owned>( &p->owned[ i ], boost::bind(
> &shared_ptr<Owner>::reset, p ) );
> }
>
> which is essentially your:
>
>
>>- Make unknownType a class that contain a shared_ptr<Owner> and a
>>Owned*, and forward all its functions to Owned.
>
>
> Of course you need to keep the vector<> from reallocating since your pointer
> will dangle.
>
> If you are using the very latest CVS version that includes explicit support
> for shared_ptr aliasing, it's even easier:
>
> shared_ptr<Owned> getOwned( shared_ptr<Owner> p, int i )
> {
> return shared_ptr<Owned>( p, &p->owned[ i ] );
> }

Thank you !

-- 
Loïc

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net