Subject: Re: [boost] [ptr_container] Questionable strong guarantee of ptr_map::insert()
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2009-08-25 09:06:07
Nevin ":-]" Liber wrote:
> 2009/8/24 Jeffrey Bosboom <jbosboom_at_[hidden]>
> > 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).
> The implementation is actually fairly simple. In psuedocode:
> internal_insert(Iterator position, T* p)
> // insert p into the container; throw on failure
> insert(Iterator position, auto_ptr<T>& ap)
> internal_insert(position, ap.get());
> insert(Iterator position, T* p)
> auto_ptr<T> ap(p);
> insert(position, ap);
> While I do understand how "copy" semantics work for auto_ptrs, when I see an
> auto_ptr as a (sink) parameter to a function, my expectation is that either
> the callee takes ownership of the underlying object, or if it fails, that I
> as the caller retain ownership. The details are, of course, that one passes
> the auto_ptr by non-const reference to any function that might fail.
You might argue that the function should take an auto_ptr by reference, but as written, it does what it ought.
Rob Stewart robert.stewart_at_[hidden]
Software Engineer, Core Software using std::disclaimer;
Susquehanna International Group, LLP http://www.sig.com
IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk