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
}
