Developing a plan for D2.0: Getting everything on the table
Bill Baxter
wbaxter at gmail.com
Wed Jul 15 15:29:44 PDT 2009
On Wed, Jul 15, 2009 at 2:42 PM, Jarrett
Billingsley<jarrett.billingsley at gmail.com> wrote:
> On Wed, Jul 15, 2009 at 5:37 PM, bearophile<bearophileHUGS at lycos.com> wrote:
>> Daniel Keep:
>>> 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;
>>
>> I am sorry, but I don't understand still. That's valid D2 code, and I can understand it. But from its look it seems (beside the not handy syntax, it's not as adding a "?") the opposite of what I was saying (that by default all D objects have to be non-nullable). Can you please help me understand? :-)
>
> If you declare:
>
> NonNullable! Object o;
>
> o.ptr is initialized to null, because you aren't required to call its
> constructor. If you were able to disable the default constructor,
> this line would give you an error, and you would be required to write:
>
> NonNullable! Object o = new Object();
>
> or so.
>
Maybe it would be less confusing to say "disable the default initializer".
--bb
More information about the Digitalmars-d
mailing list