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 for rest of types, such as structs, unions & enums for the sake of objects being able to compare.

Could we just template that opEquals in this manner:
-------
bool opEquals(T : Object, X : Object)(T lhs, X rhs)
{
    if (lhs is rhs) return true;

    if (lhs is null || rhs is null) return false;

    if (!lhs.opEquals(rhs)) return false;

    if (typeid(lhs) is typeid(rhs) ||
        !__ctfe && typeid(lhs).opEquals(typeid(rhs)))
    {
        return true;
    }

    return rhs.opEquals(lhs);
}
-------

That would at least allow us to define an overload which is safe and would be picked up by new implementation.

I'm wondering why it wasn't done yet, are there any reasons for that?

- Alex.

Reply via email to