Developing a plan for D2.0: Getting everything on the table
Daniel Keep
daniel.keep.lists at gmail.com
Wed Jul 15 03:19:24 PDT 2009
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;
More information about the Digitalmars-d
mailing list