Why are opEquals/opCmp arguments not in or const for Objects?
Peter Williams
pwil3058 at bigpond.net.au
Sun Mar 17 16:19:03 PDT 2013
The current signatures for opCmp/opEqual mean that code like:
bool strictly_ordered(T)(in T[] list) {
for (auto j = 1; j < list.length; j++) {
if (list[j - 1] >= list[j])
return false;
}
return true;
}
will fail to compile if T is a class because opCmp cannot be
called with a const argument. This restricts the quality of code
that can be written by limiting legitimate use of in/const
arguments to functions/methods.
Trying to work around this problem by defining opCmp/opEquals for
the class being used with in or const argument does not work as
they are not recognised as an override of the Object methods.
So my question is "Why are the arguments to opEquals and opCmp
(for Objects) not declared in or const?".
Thanks
Peter
More information about the Digitalmars-d
mailing list