
2009/8/24 Jeffrey Bosboom <jbosboom@uci.edu>
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@eviloverlord.com> (847) 691-1404