
Alexander wrote:
WFM...
void foo(scoped_array<int> &b) { scoped_array<int> a(new int[5]); swap(a,b); // escape }
Hm.. I agree with you that having swap to escape scoping but not having release looks inconsequent. In my opinion there should be no swap either. I use swap to do things like reallocate an array to a new size. I also use it to modify a linked list that uses scoped_ptr for its links.
swap() still guarantees that some code will delete the object or array at some point. I think leaks are impossible. Would release() do that? I'm unfamiliar with its function. If it means that the code that released the pointer is now responsible for deleting it, I don't want it. It will just mean that I have to examine all the code to look for releases and then see whether I can prove that code is guaranteed to delete it. The best thing about scoped_ptr and _array is that they are almost foolproof. The only ways that I can think of to mess one up are (a) to use the wrong one for the type of allocation (object or array) and (b) to get() its pointer and then delete it. That's my opinion as a long-time user. -- Dick Hadsell 203-992-6320 Fax: 203-992-6001 Reply-to: hadsell@blueskystudios.com Blue Sky Studios http://www.blueskystudios.com 1 American Lane, Greenwich, CT 06831-2560