destructor, postblit constructor --- force calling always

Carl Sturtivant sturtivant at gmail.com
Sun Mar 30 18:03:21 PDT 2014


> D's structs don't have identity. That means, they can be moved 
> without notice at any point in the program. AFAIK the compiler 
> even does that when handling exceptions in a few cases (e.g. 
> with structs on the stack). Having moveable value types allows 
> for a lot of optimizations, both on the compiler side as well 
> as when implementing e.g. containers in user code. So no there 
> is no way to always get notified. I also proposed a move 
> constructor in the past, but the idea was not well recieved. 
> When I needed a move constructor, usually adding another level 
> of indirection solved the problem.

Thanks for that discussion. As you might have guessed, adding 
another level of indirection is what I was trying to avoid. A 
move constructor would have taken care of my problem.

What about destructors, are they always called, or is this 
another optimization if the struct is in it's default .init state?



More information about the Digitalmars-d-learn mailing list