Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-04-10 08:37:17


From: "Raoul Gough" <RaoulGough_at_[hidden]>
> I see the point. Still, it makes simple usage a bit tedious: instead of
> writing wp->foo() I would then have to write make_shared (wp)->foo() with
> no likely safety benefit in this case. I guess there's no way around this
if
> you want the extra safety in the general case.

I originally had

shared_ptr weak_ptr::operator->() const
{
    return shared_ptr(*this);
}

but Darin argued that this is likely to confuse users. I can see arguments
for both sides; having this operator-> in will allow me to do

std::for_each(wpv.begin(), wpv.end(), mem_fn(&X::f));

but, on the other hand, having an exception thrown in the middle of the loop
is usually not what I'd want anyway (usually I'd want to skip over invalid
weak_ptrs); and when I need to perform more than one task on a weak_ptr,
using its -> operator is less efficient since it would construct a
shared_ptr every time.


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