www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - comparing nullables

reply Alex <sascha.orlov gmail.com> writes:
Hi all,
do you see any valid reason why the last line yields an error:

import std.typecons;
void main()
{
	void* ptr1;
	void* ptr2;

	assert(ptr1 is null);
	assert(ptr2 is null);
	assert(ptr1 == ptr2);

	Nullable!uint val1;
	Nullable!uint val2;
	assert(val1.isNull);
	assert(val2.isNull);
	assert(val1 == val2);

	Nullable!(uint, uint.max) val3;
	Nullable!(uint, uint.max) val4;
	assert(val3.isNull);
	assert(val4.isNull);
	assert(val3 == val4);
}

The error is
core.exception.AssertError /usr/local/opt/dmd/include/dlang/dmd/s
d/typecons.d(3457): Called `get' on null Nullable!(uint,nullValue).

As I can see, this is due the lack of opEquals in the Nullable(T, 
T nullValue), in contrast to Nullable(T).
Jun 15 2018
parent reply bauss <jj_1337 live.dk> writes:
On Friday, 15 June 2018 at 15:00:38 UTC, Alex wrote:
 Hi all,
 do you see any valid reason why the last line yields an error:

 import std.typecons;
 void main()
 {
 	void* ptr1;
 	void* ptr2;

 	assert(ptr1 is null);
 	assert(ptr2 is null);
 	assert(ptr1 == ptr2);

 	Nullable!uint val1;
 	Nullable!uint val2;
 	assert(val1.isNull);
 	assert(val2.isNull);
 	assert(val1 == val2);

 	Nullable!(uint, uint.max) val3;
 	Nullable!(uint, uint.max) val4;
 	assert(val3.isNull);
 	assert(val4.isNull);
 	assert(val3 == val4);
 }

 The error is
 core.exception.AssertError /usr/local/opt/dmd/include/dlang/dmd/s
d/typecons.d(3457): Called `get' on null Nullable!(uint,nullValue).

 As I can see, this is due the lack of opEquals in the 
 Nullable(T, T nullValue), in contrast to Nullable(T).
https://github.com/dlang/phobos/pull/6583
Jun 15 2018
parent Alex <sascha.orlov gmail.com> writes:
On Friday, 15 June 2018 at 16:49:47 UTC, bauss wrote:
 https://github.com/dlang/phobos/pull/6583
Thanks a lot.
Jun 15 2018