From: Howard Hinnant (hinnant_at_[hidden])
Date: 2001-01-07 12:12:47
Peter Dimov wrote on 1/7/2001 9:07 AM
>Why auto_ptr<X> and not auto_array?
>What code that uses auto_ptr<T> would work as expected with T = X?
I think auto_array is a good solution to this problem. I don't think
auto_ptr<X> adds (or subtracts) any functionality over auto_array. I
think it boils down to which "name" for this functionality is best:
4. auto_ptr<T, ArrayPolicy>
The array version is a distinct class from the single version (though
implementations could well share common code under the covers). Though
they are distinct classes, the semantics are very similar:
Hold the pointer and pretty much act like a think wrapper to the
But return it to the heap on destruction.
The details on exactly how the pointer is returned to the heap vary a
little: delete vs delete. The important fact is that the correct form
of delete must be used.
It is only because the semantics are so similar that one would even
consider sharing the name "auto_ptr" over two distinct classes. The big
question is: Are the semantics close enough that such sharing has
benefits (such as self documentation)?
As anecdotal evidence of self documentation, I present one newbie:
who stumbled upon the syntax auto_ptr<T> and expected it to work. Such
evidence is far from comprehensive or conclusive.
This question seems quite analogous to function overloading. At what
point are two functions similar enough to justify using the same name (or
same operator)? I invite more discussion on this topic.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk