SafeD and Nullable concept

Jarrett Billingsley jarrett.billingsley at gmail.com
Thu Jan 15 06:23:13 PST 2009


On Thu, Jan 15, 2009 at 2:38 AM, Denis Koroskin <2korden at gmail.com> wrote:
> I think I have found one more reason for Nullable concept to appear in D:
>
> Since SafeD disallows pointers, it needs something safe to replace them.
>
> For example, it is impossible to use AA in SafeD, because opIn_r returns a
> pointer:
>
>> Foo[Bar] aa;
>>
>> Bar bar = new Bar();
>> Foo* fooPtr = bar in aa; // this line is disallowed in SafeD
>
> I wonder why it returns a pointer, and shouldn't it return Nullable!(Foo)
> (or just Foo? as an alias) instead?
>
>> Foo? foo = bar in aa; // null, if item is missing
>
> Note that now it became slightly more efficient, because we don't need an
> additional pointer dereference, which was present when we returned Foo*!

How do you distinguish between the key being missing and there being a
null reference in the AA?

Also, if you have an AA like:

Foo?[Bar] aa;

What is the return type of in?  "Foo??" ?



More information about the Digitalmars-d mailing list