Integral types that define opCmp, opEquals
Frits van Bommel
fvbommel at REMwOVExCAPSs.nl
Tue Mar 6 13:54:30 PST 2007
Henning Hasemann wrote:
>> IIRC 'is' tests if a _type_ is valid. Try something like is(typeof(i < i)).
>
> Works quite well, only thing is that
> it yields true for everything that is derived from object,
> but these indeed *have* defined opCmp so I guess
> there is no real way to find out if the writer of
> a class things this class' objects should be comparable
> to themselves.
No, AFAIK there indeed isn't, but there *is* a way to see if a class has
an overridden Object.opCmp: (warning: dirty trick)
---
import std.stdio;
class Foo { // opCmp overridden
int opCmp(Object o) { return 0; }
}
class Bar { } // opCmp not overridden
void main()
{
writefln(&Foo.opCmp != &Object.opCmp); // prints "true"
writefln(&Bar.opCmp != &Object.opCmp); // prints "false"
}
---
More information about the Digitalmars-d
mailing list