Nullable or Optional? Or something else?

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Wed Sep 2 19:23:32 PDT 2009


Rainer Deyke wrote:
> Andrei Alexandrescu wrote:
>> Apparently a good design is to define Optional!T with a minimum of
>> member functions (ideally none) and have it use the "alias this" feature
>> to masquerade as a T. That way Optional!T looks and feels much like a T,
>> except that it supports a function
>>
>> bool isNull(T)(Optional!T value);
>>
>> Am I on the right track?
> 
> You need some syntactic way to distinguish the contained value from the
> container.  Using "alias this" seems messy here.  Optional!Optional!T is
> both valid and likely to occur.

Interesting. I wonder whether it's better to fold Optional!(Optional!T) 
into Optional!T.

Andrei



More information about the Digitalmars-d mailing list