Boost logo

Boost :

Subject: Re: [boost] [ptr_container] Questionable strong guarantee of ptr_map::insert()
From: Thorsten Ottosen (thorsten.ottosen_at_[hidden])
Date: 2009-08-26 04:20:12


Kazutoshi Satoda skrev:
> Thorsten Ottosen wrote:
>>>> Hm. Do you propose to break the existing interface?
>>>
>>> Yes, I personally believe that the following use should be banned by
>>> design.
>>>>> map.insert(some_key(...), std::auto_ptr<value>(new value));
> (snip)
>>> I want to hear about some compatibility policy in Boost to guess the
>>> possibility of this kind of breaking (but otherwise good) changes.
>>
>> Well, you also break perfectly valid and safe code where the auto
>> pointer is returned from a function.
>
> Hmm, I didn't think of such code. I agree such code is valid and safe.
>
> However, as far as I know, there is no way to distinguish the two; a
> temporary auto_ptr, and a returned auto_ptr. Then the interface can
> allow both, or disallow both. I still think the latter is better choice
> in a generic library.
>
> Do you think passing a temporary auto_ptr should be allowed to allow
> passing a returned auto_ptr?

Oh yes. Generic libraries in particular needs to be useable rather than
over-encapsulated.

If there is a real need for operations with the strong guarantee, I
think we should add them with the following signature:

  strong_push_back( std::auto_ptr<U>&, ... );

albeit they can be implemeted by a user because you have access to the
underlying container with .base():

   std::auto_ptr<U> ptr( ... );
   cont.base().push_back( ptr.get() );
   ptr.release();

-Thorsten


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