Object.toString, toHash, opCmp, opEquals
Alexandru Ermicioi
alexandru.ermicioi at gmail.com
Fri Jun 7 17:39:57 UTC 2024
On Thursday, 6 June 2024 at 09:57:29 UTC, Quirin Schroll wrote:
> You need 16 overloads, all but 1 of them `final`, the
> non-`final` one without attributes.
There really should be only one interface provided each method
with no lambda function arguments in Object by default:
```d
interface ToString {
string toString();
}
```
If there is need to have better constraints, people can just
extend the interface and narrow the declaration:
```d
interface SafeNogcToString : ToString {
string toString() @safe @nogc;
}
```
People that need that enforcement, can in worst case do a cast
down to interface that satisfies their attribute requirements,
and if object doesn't satisfy it, then handle it.
For lambda ones, there should be some other solution. In worst
case, default provided interface could have narrowest possible
configuration, i.e. @safe @nogc pure const, from which people
could widen the configuration in each interface extension.
More information about the Digitalmars-d
mailing list