Boost logo

Boost :

From: Andy Thomas-Cramer (Andy_Thomas-Cramer_at_[hidden])
Date: 2005-08-03 15:58:56


Thanks, that did it.
It's not intuitive, and not obvious from the documentation.

> -----Original Message-----
> From: boost-bounces_at_[hidden]
[mailto:boost-bounces_at_[hidden]]
> On Behalf Of Michael B. Edwin Rickert
> Sent: Wednesday, August 03, 2005 3:14 PM
> To: boost_at_[hidden]
> Subject: Re: [boost] weak_ptr, maybe empty
>
> Andy Thomas-Cramer wrote:
> > I have a weak_ptr that might be empty. If not empty, I'd like to
make a
> > smart pointer from it.
> >
> > But the code below throws in the shared_ptr constructor, and I don't
see
> > how to test whether a weak_ptr is empty.
> >
> > boost::weak_ptr<int> wp;
> > boost::shared_ptr<int> sp(wp);
> > if ( sp.get() ) {
> > ...
> > }
>
> The documentation (http://boost.org/libs/smart_ptr/weak_ptr.htm) seems
> to show a few options. The most similar to your situation would be:
>
> boost::weak_ptr< int > wp;
> boost::shared_ptr< int > sp = wp.lock();
> if ( sp.get() ) {
> ...
> }
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost


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