From: Gary Powell (Gary.Powell_at_[hidden])
Date: 2001-04-05 11:44:45
> AFAIK auto_ptr_ref supports passing/returning auto_ptrs by value. I think
> that this is unnecessary for boost::auto_ptr, since
> (1) we have
> boost::shared_ptr for this,
I was thinking of dropping boost::auto_ptr.
But I'm open to comments here.
Because std:auto_ptr is everywhere and does everything except the sizeof(T)
test at the call to delete, and IMO that isn't enough justification for
The my reason for keeping it, is that this change should become part of
std::auto_ptr and in order to prove to the library committee that its worth
doing, there should be some prior usage.
> (2) passing auto_ptrs by value instead of
> non-const reference is dangerous (exception safety), and
I thought that was the second main purpose of auto_ptr. See
shared_ptr<>(auto_ptr<>() ); constructor, and assignment.
> (3) returning
> std::auto_ptrs by value is sometimes useful since std::auto_ptr is
> but boost::auto_ptr is not, so it doesn't need this "capability."
Again, I thought this was the third main purpose of auto_ptr, returning a
pointer to allocated memory, forcing the calling function to take ownership,
and not leak memory.
auto_array_ptr still has the same problems about const copies, and AFAIK
Greg C. used auto_pointer_ref in auto_array_ptr for the same purpose.
So we could drop boost::auto_ptr, but not boost::auto_ptr_ref.
Let me outline why auto_ptr/auto_array_ptr.
1) local variables that must be destructed in case of an exception being
thrown. Often used in constructors which do multiple allocations.
2) Passing by value to functions which will take ownership possession. eg,
3) Returning by value from functions which create objects via new, and
calling functions must take ownership possession. eg. static creation/clone
auto_array_ptr takes care of the case where you allocate char x, instead
of just a single object.
Therefore I would want shared_array to have an additional constructor and
assignment operator that takes a boost::auto_array_ptr
This way if shared_array( auto_array_ptr<>(new T[n] ) throws when it
allocates the new for the pointer to the counter it won't leak the T[n].
If I'm confused about this please enlighten me. (I'm in the process of
becoming an exception safe programmer and its a hard journey.)
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk