|
Boost : |
From: Dave Harris (brangdon_at_[hidden])
Date: 2003-10-07 16:10:58
In-Reply-To: <uoewtp1ll.fsf_at_[hidden]>
dave_at_[hidden] (David Abrahams) wrote (abridged):
> I hate to do this, but I feel I ask whether if the user supplies
> inplace construction, the resulting pointer can be delete'd (since the
> class may have an overloaded operator new/delete). I think you may
> have to use inplace destruction plus operator delete. That could
> make it dangerous to use auto_ptr, for example.
Interesting point. Are we talking about std::vector or the usual pointer
case?
For pointers, can't we use the class's definition of operator new
explicitly?
void *p = T::operator new( sizeof(T) );
load_construct<Archive,T>( ar, p, file_version );
Then it can surely be deleted as normal.
For vectors we can use the same approach. Alternatively we may be able to
use stack memory and inplace destruction. Arranging for the object to be
destroyed correctly if push_back throws will require some careful code. I
imagine it will use explicit try/catch rather than auto_ptr.
-- Dave Harris, Nottingham, UK
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk