bearophile wrote: > Andrei Alexandrescu: >> It could if there was a way to disable the default constructor. Walter >> seemed to be interested in the idea. > > (I'm always a little suspicious of library solutions, because they sometimes > smell of over-generalization, but sometimes they are a better solution.) > It's interesting, can you please quickly show me how disabling the default > constructor may allow you to implement this solution?
Because: > struct NonNullable(T) > { > T ptr; > alias ptr this; > > this(T ptr) > { > assert(ptr !is null); > this.ptr = ptr; > } > this(NonNullable!T ptr) > { > this.ptr = ptr.ptr; > } > } > > // Boom! I just broke your non-nullable type! > NonNullable!Object o;