Nullable with reference types
via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Jul 1 02:45:43 PDT 2015
On Tuesday, 30 June 2015 at 18:29:31 UTC, Steven Schveighoffer
wrote:
> I know this is just back-of-envelope, but what's wrong with:
>
> alias Nullable(T) if(is(T == class)) = T;
>
> bool isNull(T)(T t) if(is(T == class)) { return t is null;}
That's what I intended. (Same for pointers and slices, BTW.)
I does however have a slightly different behaviour: In the
current implementation, there can be instances for which `isNull`
returns false, but whose payloads are nevertheless `null`.
More information about the Digitalmars-d-learn
mailing list