On 06/16/12 21:22, bearophile wrote:
> Guillaume Chatelet:
> 
> I like hard books, if they give something valuable back.

I think you'll find it rewarding.

> 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);
> }

That's a good one ! I forgot about the _invariant_ keyword.
It's pretty close. For what I understood of x10 (I'm not using it yet
just interested in the language) the compiler will also enforce the
invariance at compile time not solely at runtime. ie

void main(){
  NoZero a = 0; // shouldn't compile
}

Thx for the design though, I keep it in my toolbox.

--
Guillaume

Reply via email to