User-defined "opIs"

Meta via Digitalmars-d digitalmars-d at puremagic.com
Wed Sep 24 15:48:35 PDT 2014


The following code fails under DMD 2.065:

struct Test
{
     bool opBinary(string op: "is", T: typeof(null))(T val)
     {
         return false;
     }

     bool opBinaryRight(string op: "is", T: typeof(null))(T val)
     {
         return false;
     }
}

void main()
{
     auto t = Test();
     //Error: incompatible types for ((t) is (null)): 'Test' and 
'typeof(null)'
     //assert(t !is null);
     //assert(null !is t);
}

Is this supposed to work, and if not, should an enhancement be 
made to allow it? This is stopping std.typecons.Proxy from being 
a true proxy. See the following:

struct Test
{
	int* ptr;
	mixin Proxy!ptr;
	
	this(int* p)
	{
		ptr = p;
	}
}

auto i = new int;
assert(i !is null);
auto t = Test(i);
//Error: incompatible types for ((t) !is (null)): 'Test' and 
'typeof(null)'
//assert(t !is null);


More information about the Digitalmars-d mailing list