Overloading opEquals(T)(T y)

Charles McAnany mcanance at rose-hulman.edu
Mon Feb 7 14:53:48 PST 2011


Hi, all. So I'm trying to make a BigRational struct, to get more comfortable
with D. I'm working on the opEquals part now, and I'm having some difficulty.
I'd like to write an equality checker for two BigRationals, and have all other
comparisons make a BigRational of the rhs and then forward that to the first
equality checker.

bool opEquals(Tdummy = void)(BigRational y){
	auto temp = this-y;
	if (temp.numerator == 0)
	return true;
	return false;
}

bool opEquals(T)(T y){
	return this == BigRational(y);
}

But this is an ambiguity error. Certainly, I could write opEquals(T: int)(T
y), opEquals(T:long)(T y), and so on and so on, but I feel there must be a
more elegant solution. Any ideas?
Thanks,
Charles


More information about the Digitalmars-d mailing list