[ create a new paste ] login | about

Link: http://codepad.org/47OB3nJi    [ raw code | fork ]

D, pasted on Nov 26:
module strongintp;

int main()
{
	intp a=42;
	assert(a.value==42,"1");
	a=43;
	assert(a.value==43,"2");
	int b=44;
	a=b; // ok: Error: function strongintp.intp.opAssign (short v) is not callable using argument types (int)
	long c=45;
	a=c; // ok: Error: function strongintp.intp.opAssign (short v) is not callable using argument types (long)
	intp d=46;
	a=d;
	assert(a.value==46,"3");
	assert(a==intp(46),"4");
	intp e=c; // ok: Error: constructor strongintp.intp.this (short v) is not callable using argument types (long)
	return 0;
}

struct intp
{
	static if((byte*).sizeof==4) alias int integer;
	else static if((byte*).sizeof==8) alias long integer;
	else static assert(false);
	integer value;

	this(short v){ value=v; }
	//this(ushort v){ value=v; }
	bool opEquals(ref const intp v) const { return value==v.value; }
	int opCmp(ref const intp v) const
	{
		return value>v.value?1:value<v.value?-1:0;
	}
	void opAssign(intp v){ value=v.value; }
	void opAssign(short v){ value=v; }
}


Create a new paste based on this one


Comments: