Boost logo

Boost :

Subject: Re: [boost] [ptr_container] Questionable strong guarantee of ptr_map::insert()
From: Nevin \ (nevin_at_[hidden])
Date: 2009-08-25 01:02:01


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());
    ap.release();
}

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.

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

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