On 02/08/2011 12:16 AM, bearophile wrote:
Charles McAnany:

Hi, all. So I'm trying to make a BigRational struct, to get more comfortable
with D.

I suggest to ask similar questions in the D.learn newsgroup.


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.

One possible solution:

bool opEquals(T)(T y) if (is(T == BigRational)) { ... }
bool opEquals(T)(T y) if (!is(T == BigRational)) { ... }


Another solution:

bool opEquals(T)(T y) {
     static if (is(T == BigRational)) {
         // ...
     } else {
         // ...
     }
}

Bye,
bearophile

I just thought at this alternative between a constraint and a static if a few hours ago. In which case, and according to which reasoning, would one choose one or the other? (I chose static if only for the very bad reason I can hardly stand is().)

Denis
--
_________________
vita es estrany
spir.wikidot.com

Reply via email to