A fresh look at comparisons
Janice Caron
caron800 at googlemail.com
Wed Apr 16 07:40:49 PDT 2008
On 16/04/2008, Steven Schveighoffer <schveiguy at yahoo.com> wrote:
> IMO, opCmp should be
> defined in an interface, and those classes which implement it should
> implement that interface. This would prevent trying to compare something
> that doesn't implement the opCmp method.
Of course, you realise that just because you declare "MyClass
implements opCmp()", it doesn't necessarily follow that all possible
subclasses of MyClass, which may be declared by other programmers, in
other modules, at any time in the future, will also implement opCmp().
Nor can you be sure that your opCmp() function will be appropriate for
all such subclasses.
And yet, that's exactly what implementing such an interface would tell
the compiler!
Hence the "fresh look" at comparisons. :-)
More information about the Digitalmars-d
mailing list