Suggestion: common & polish constructors (+ destructors)

Bill Baxter wbaxter at gmail.com
Fri Nov 3 04:33:20 PST 2006


Kristian Kilpi wrote:
> 
> It would be nice if you could add code into constructors (and 
> destructors)  with mixins. For example, you could initialize member 
> objects/structures  added by a mixin, etc.
> [snip]
> And finally, there should also be common destructors (e.g.  
> '~common_this()', 'finish_this()', 'destroy_this()') to be used with  
> mixins. This way each mixin could add code to the actual destructor.

Actually what you suggest seems to already be the case for destructors. 
  Don't know if it's in the spec, but I just noticed it yesterday.


template Death(int i)
{
     ~this() {
         writefln("Death says: see you! ", i);
     }
}
class DClass
{
     mixin Death!(1);
     mixin Death!(2);
     mixin Death!(3);

     ~this() {
         writefln("Class bye bye!");
     }

     mixin Death!(4);
     mixin Death!(5);
     mixin Death!(6);
}

The destructors get called in reverse order of appearance within DClass.

--bb



More information about the Digitalmars-d mailing list