Re: Wrong selection of opEquals for objects.

2020-08-28 Thread Simen Kjærås via Digitalmars-d-learn
On Friday, 28 August 2020 at 13:35:43 UTC, Alexandru Ermicioi wrote: On Friday, 28 August 2020 at 12:29:20 UTC, Simen Kjærås wrote: Seems that these methods should be rooted out from Object, and placed in respective interfaces like: - interface Equatable(T) { bool opEquals(T va

Re: Wrong selection of opEquals for objects.

2020-08-28 Thread Alexandru Ermicioi via Digitalmars-d-learn
On Friday, 28 August 2020 at 12:29:20 UTC, Simen Kjærås wrote: Seems that these methods should be rooted out from Object, and placed in respective interfaces like: - interface Equatable(T) { bool opEquals(T value); } - Then it would be a lot more simple. People who want equ

Re: Wrong selection of opEquals for objects.

2020-08-28 Thread Simen Kjærås via Digitalmars-d-learn
On Friday, 28 August 2020 at 10:42:09 UTC, Alexandru Ermicioi wrote: No that is not a solution at all, in template code that requires safety. You basically will have to sacrifice safety for rest of types, such as structs, unions & enums for the sake of objects being able to compare. Yup. Ther

Re: Wrong selection of opEquals for objects.

2020-08-28 Thread Alexandru Ermicioi via Digitalmars-d-learn
On Friday, 28 August 2020 at 10:42:09 UTC, Alexandru Ermicioi wrote: ... Also, why it is limited to just objects? It seems that this function enforces symmetry between two objects. What about rest of the possible types, such as structs, unions?

Re: Wrong selection of opEquals for objects.

2020-08-28 Thread Alexandru Ermicioi via Digitalmars-d-learn
On Friday, 28 August 2020 at 10:28:07 UTC, Simen Kjærås wrote: What you'll need to do is mark every function that does compare two class objects with == as @trusted or @system. No that is not a solution at all, in template code that requires safety. You basically will have to sacrifice safety

Re: Wrong selection of opEquals for objects.

2020-08-28 Thread Simen Kjærås via Digitalmars-d-learn
On Friday, 28 August 2020 at 08:16:01 UTC, Alexandru Ermicioi wrote: Hi everyone, there is https://issues.dlang.org/show_bug.cgi?id=21180 bug, anyone knows how to avoid it? Test case: - import std; class Silly { bool opEquals(const Silly silly) const @safe { return si

Re: Wrong selection of opEquals for objects.

2020-08-28 Thread Alexandru Ermicioi via Digitalmars-d-learn
On Friday, 28 August 2020 at 08:16:01 UTC, Alexandru Ermicioi wrote: Hi everyone, Would be glad at least to pointers, where in dmd is logic for operator overloading happens, as well as for overloading rules, so I could fix it myself, if no-one is able to pick up it.

Wrong selection of opEquals for objects.

2020-08-28 Thread Alexandru Ermicioi via Digitalmars-d-learn
Hi everyone, there is https://issues.dlang.org/show_bug.cgi?id=21180 bug, anyone knows how to avoid it? Test case: - import std; class Silly { bool opEquals(const Silly silly) const @safe { return silly is this; } alias opEquals = Object.opEquals; } bool comp