www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Comparison of null `Nullable`s

reply =?UTF-8?B?THXDrXM=?= Marques <luis luismarques.eu> writes:
Have you considered making these work, instead of throwing an 
exception?

     import std.typecons;

     alias T = Nullable!(int, -1);

     void main()
     {
         T a;
         T b;
         assert(a == b);

         T c;
         T d = 42;
         assert(c != d);
     }

It could be a template parameter for Nullable, and the default be 
to preserve the current behavior.
Mar 30 2016
parent Meta <jared771 gmail.com> writes:
On Wednesday, 30 March 2016 at 12:06:24 UTC, Luís Marques wrote:
 Have you considered making these work, instead of throwing an 
 exception?

     import std.typecons;

     alias T = Nullable!(int, -1);

     void main()
     {
         T a;
         T b;
         assert(a == b);

         T c;
         T d = 42;
         assert(c != d);
     }

 It could be a template parameter for Nullable, and the default 
 be to preserve the current behavior.
https://issues.dlang.org/show_bug.cgi?id=14804 A link to the PR is in the last update to this bug.
Mar 30 2016