Is Nullable supposed to provide Optional semantics?

vit vit at vit.vit
Fri Dec 29 22:08:59 UTC 2017


On Friday, 29 December 2017 at 21:43:25 UTC, Chris Paulson-Ellis 
wrote:
> On Friday, 29 December 2017 at 21:34:27 UTC, vit wrote:
>> use:
>>    n = Nullable!Object.init;   //doesn't call destroy
>>
>> instead of:
>>    n.nullify();
>
> Only nullify() can make isNull return true again. I need that 
> semantic.


     import std.typecons : Nullable;

     auto o = new Object();

     Nullable!Object n;
     assert(n.isNull == true);

     n = o;
     assert(n.isNull == false);

     n = Nullable!Object.init;
     assert(n.isNull == true);

     o.toString();       //OK

     assert(Nullable!Object.init.isNull == true);


more: 
https://forum.dlang.org/thread/jrdedmxnycbqzcprebjl@forum.dlang.org?page=1


More information about the Digitalmars-d-learn mailing list