What is the rationale behind enabling Nullable!T to be used as a regular T?
FeepingCreature
feepingcreature at gmail.com
Fri Feb 14 08:59:44 UTC 2020
On Friday, 14 February 2020 at 08:54:41 UTC, Adnan wrote:
> What is the rationale behind enabling Nullable!T to be used as
> a regular T?
The rationale is we have a few more months to wait before the
deprecation period for that functionality runs out and we can
remove it. :)
> Back to D.
>
> const Nullable!int a;
> assert(a.isNull);
> writeln(a + 4); // compiles with 0 warnings
>
> Why is opBinary implemented for Nullable!T? Doesn't it defeat
> its purpose?
If you switch to 2.090.1, you will get warnings there. If you run
with -de, the warnings will be errors.
---
The original reason was I believe that Nullable was never really
intended to be Optional, it was intended to give types a "null"
state like objects and pointers. Well, objects and pointers crash
when you access them if they're null, so...
(No, it's not a very good reason.)
More information about the Digitalmars-d
mailing list