On Sunday, June 17, 2012 08:38:41 Philippe Sigaud wrote: > On Sat, Jun 16, 2012 at 9:22 PM, bearophile <[email protected]> wrote: > > I see. is that semantically different from this (beside being shorter)? > > > > struct NoZero { > > int value; > > this(int x) { value = x; } > > alias value this; > > invariant() { assert(value != 0); } > > } > > void main() { > > auto a = NoZero(5); > > auto b = NoZero(0); > > } > > The invariant isn't invoked through alias this, it seems: > > void main() { > auto a = NoZero(5); > a = 0; // compiles and runs happily > }
It wouldn't be. No public function was called. All you did was access the public member variable. Having public members and invariants at the same time doesn't work very well. - Jonathan M Davis
