Nullable!T with T of class type

Jonathan M Davis newsgroup.d at jmdavisprog.com
Thu Jun 28 19:22:38 UTC 2018


On Thursday, June 28, 2018 18:10:07 kdevel via Digitalmars-d-learn wrote:
> On Tuesday, 26 June 2018 at 21:54:49 UTC, Jonathan M Davis wrote:
> > [H]onestly, I don't understand why folks keep trying to put
> > nullable types in Nullable in non-generic code.
>
> How do you signify that a struct member of class type is optional?

Structs aren't nullable, so wrapping them in a Nullable makes perfect sense.
Whether they happen to be on the stack or members of another type is
irrelevant to that. It's wrapping types like pointers and class references
in a Nullable that's an odd thing to do - the types where someone might ask
why the extra bool is necessary in the Nullable. Wrapping them in a Nullable
makes sense in generic code, because the code isn't written specifically for
them, but something like Nullable!MyClass in non-generic code is pointless
IMHO, because a class reference is already nullable.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list