comparing nullables

bauss jj_1337 at live.dk
Fri Jun 15 16:49:47 UTC 2018


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/std/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


More information about the Digitalmars-d-learn mailing list