Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-02-12 13:26:53

From: "Darin Adler" <darin_at_[hidden]>
> I think that it's strange that constructing a shared_ptr from a weak_ptr
> that's 0 throws the boost::detail::bad_weak_to_shared_cast exception, but
> using the get() operation on weak_ptr results in a shared_ptr that's 0.
> I think the 0 behavior is better than the exception behavior. We can make
> the bad_weak_to_shared_cast exception be an implementation detail never
> exposed in the interface.

Ah, but that's a feature. You think that 0 is better? Use get(). Someone
else feels that an exception is better? Use the constructor.

The idiom is either

if(shared_ptr<T> sp = wp.get())
// use *sp, sp->
// object is gone


shared_ptr<T> sp(wp); // may throw

// use *sp, sp->

Boost list run by bdawes at, gregod at, cpdaniel at, john at