Nullable or Optional? Or something else?

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Thu Sep 3 08:35:45 PDT 2009


Steven Schveighoffer wrote:
> On Wed, 02 Sep 2009 16:54:30 -0400, Andrei Alexandrescu 
> <SeeWebsiteForEmail at erdani.org> wrote:
> 
>> grauzone wrote:
>>> Andrei Alexandrescu wrote:
>>>> I plan to add a Nullable struct to Phobos (akin to C#'s Nullable, 
>>>> Boost's Optional).
>>>>
>>>> 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
>>>  I still don't understand how one can feel comfortable with the fact, 
>>> that "alias this" can overshadow arbitrary members of the alias'ed type.
>>
>> That's why I want to add no member functions to Optional. The test for 
>> null will be a free function.
> 
> How does Optional!valuetype support this:
> 
> Optional!valuetype x;
> x = null;
> 
> Don't you need opAssign?
> 
> -Steve

I should have said: no *named* member. Operators and cdtors are fair game.

Andrei



More information about the Digitalmars-d mailing list