Boost logo

Boost :

Subject: Re: [boost] [ptr_container] Questionable strong guarantee of ptr_map::insert()
From: Jeffrey Bosboom (jbosboom_at_[hidden])
Date: 2009-08-25 00:12:27


Edward Diener wrote:
> Nevin ":-]" Liber wrote:
>> I believe
>> that most
>> people expect that if they pass an auto_ptr and an exception is
>> thrown, then
>> the auto_ptr has not relinquished ownership. Otherwise, why bother
>> with an
>> auto_ptr at all?
>
> I would have assumed that if I pass an auto_ptr that ownership is
> relinquished no matter what happens later, exception or not. Is not that
> how the copy constructor of an auto_ptr is supposed to work ?

I agree -- auto_ptr's copy constructor has move semantics, and the copy
(move) must be made before the function is entered (arguments can be
evaluated in any order, but there's a sequence point before entering the
function body).

For the record, if the argument was an auto_ptr&, I would expect the
auto_ptr to still own the resource if an exception was thrown, although
I don't know how to implement it (moving back into the auto_ptr might
throw too).

--Jeffrey Bosboom


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