Nullable or Optional? Or something else?

Max Samukha spambox at d-coding.com
Thu Sep 3 02:10:57 PDT 2009


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
> 
> bool isNull(T)(Optional!T value);
> 
> Am I on the right track? If so, what is the name you'd prefer for this
> artifact?
> 
> 
> Andrei

I prefer Nullable.

Will there be an isNull overload for types that are inherently nullable 
(class references, pointers, delegates, etc)?

Probably, there should be an isNullable concept for checking any type for 
nullability along with a ValueOfNullable template for obtaining the type of 
the underlying value.

Should we be able to generically construct a Nullable!T from a value of T?

How to generically set a nullable to null?

Do we need a requirement that assert(isNull(Nullable!(T).init)) pass for any 
T?

Can 'to' be extended to correctly convert nullable types from and to "null" 
string? Should conversions from "null" be case-sensitive?







More information about the Digitalmars-d mailing list