[Issue 9636] null initialization for std.typecons.Nullable
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Wed Oct 8 05:05:33 PDT 2014
https://issues.dlang.org/show_bug.cgi?id=9636
--- Comment #7 from monkeyworks12 at hotmail.com ---
(In reply to monarchdodra from comment #5)
> The original request was the ability to write "myNullable = null". I said
> this should be rejected, because "t = null" could actually be a "non-null
> operation".
>
> I suggested instead using a "null-token" as a "workaround", but, as
> JakobOvrum states, "why all this?"
>
> Is there something we actually *get* from this, or is it only sugar? If it's
> only sugar, i suggest we close. How do we close an enhancement? Won't Fix?
> Invalid?
Because of the design mistake in Nullable that it does not alias itself to T if
T is already a nullable type, Nullable's 'null' and the wrapped type's 'null'
are two different things, and it's necessary to make a distinction. One
solution is to use Nullable!(...).init, but that can be inconveniently long as
Bearophile pointed out. Another solution is to do `enum nullState =
Nullable!(...).init`, but it's then in the global scope, and it's annoying to
create a new enum for each type you want to use Nullable with. Hopefully in the
future we can deprecate Nullable in lieu of an Option type and fix these little
mistakes.
--
More information about the Digitalmars-d-bugs
mailing list