~= call copy ctor?

Jonathan M Davis jmdavisProg at gmx.com
Sun Jul 22 11:43:04 PDT 2012


On Sunday, July 22, 2012 20:14:20 Namespace wrote:
> On Sunday, 22 July 2012 at 17:41:33 UTC, Ali Çehreli wrote:
> > On 07/22/2012 09:27 AM, Mafi wrote:
> > >> Unfortunately it has a bad name, which is going to be
> > 
> > changed.
> > 
> > > Really? I thought we have to stay with this name now. In my
> > > opinion this name is quite bad, especially in the presence of
> > > UFCS. What is going to be changed to? destroy()?
> > 
> > Yep! :) It should be available in 2.060:
> > 
> > // Scheduled for deprecation in December 2012.
> > // Please use destroy instead of clear.
> > 
> > https://github.com/D-Programming-Language/druntime/blob/master/src/object.
> > di#L682
> > 
> > Ali
> 
> And how do I check if my object is still valid?

You don't. The object is completely invalid at that point. Its vtbl has been 
zeroed out. Asking how you check whether it's valid is like asking how you can 
tell whether an object in C++ which has been deleted is valid. It just doesn't 
work that way. If you're destroying it, you need to then _never_ use it for 
_anything_. You can set a reference which pointed to it to null, and then it's 
null, and you can check for null, but an object which has had clear/destroy 
called on it is in an invalid state and should not be touched. It's 
specifically set up such that it's highly likely to cause your program to crash 
if you try and use it at all. If you want to check an object for validity, you 
need to do something else.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list