Is it possible to avoid call to destructor for structs?
    Adam D. Ruppe 
    destructionator at gmail.com
       
    Sun Sep 24 18:02:47 UTC 2017
    
    
  
On Sunday, 24 September 2017 at 17:11:26 UTC, Haridas wrote:
> In the following code, Bar is an element of struct Foo. Is 
> there a way to avoid a call to ~Bar when ~Foo is getting 
> executed?
No, but you could just set a flag in Bar that the destructor 
checks and skips running if it is set.
In fact, the destructor should do nothing if bar is in its 
initial state, so that's how you could check it. For example
~this() {
    if(this.member is null) return;
    // finalize this.member
}
    
    
More information about the Digitalmars-d-learn
mailing list