Boost logo

Boost Users :

Subject: Re: [Boost-users] shared_ptr / auto_ptr
From: Nevin Liber (nevin_at_[hidden])
Date: 2010-02-23 17:24:59


On 23 February 2010 14:55, Baptiste Lepilleur
<baptiste.lepilleur_at_[hidden]>wrote:

> [A] template<class Y>
>> [B] explicit shared_ptr(std::auto_ptr<Y> & r): px(r.get()), pn()
>>
>
> By the way, shouldn't this constructor take std::auto_ptr by value instead
> of by reference. I remember being forced to introduce a local variable with
> the example below (was with sunstudio 12, default STL if I remember
> correctly). I think this was caused because you can not bind a temporary
> object to a non const reference.
>

Passing the auto_ptr by value would only get us the basic exception safety
guarantee, as the shared_ptr will have taken ownership, even though it might
still throw before it is done constructing itself. Passing it in by
reference allows us to have the strong exception safety guarantee.

-- 
Nevin Liber  <mailto:nevin_at_[hidden]>  (847) 691-1404


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