[Issue 17440] Nullable.nullify() resets referenced object
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Jan 15 20:12:11 UTC 2018
https://issues.dlang.org/show_bug.cgi?id=17440
hsteoh at quickfur.ath.cx changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |hsteoh at quickfur.ath.cx
--- Comment #9 from hsteoh at quickfur.ath.cx ---
But by-reference objects in D *already* have nullable semantics, i.e.:
-------
class C {}
C c;
assert(c is null); // c is null by default
c = new C;
assert(c !is null);
c = null; // nullify
assert(c is null);
-------
Of course the syntax is slightly different (direct use of null vs. .isNull /
.nullify). But there's really no benefit to using Nullable with reference
types in D.
OTOH, if you're using generic code that expect a single API for nullable
objects, perhaps the solution is to write an overload of Nullable that simply
maps .isNull to `is null` and .nullify to `= null` when the wrapped type is a
class.
--
More information about the Digitalmars-d-bugs
mailing list