Summary: comparison of interfaces not implemented
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Keywords: patch
          Severity: normal
          Priority: P2
         Component: druntime

--- Comment #0 from Simen Kjaeraas <> 2011-01-17 09:08:09 
PST ---
Currently, object.di's global opEquals function does not support comparing
interfaces. The following code adds such support, but may add bloat due to
duplicated code for all type combinations:

 * Returns true if lhs and rhs are equal.
equals_t opEquals(T, U)(T lhs, U rhs)
    if ((is(T == class) || is(T == interface)) && (is(U == class) || is(U ==
    // If aliased to the same object or both null => equal
    if (lhs is rhs)
        return true;
    // If either is null => non-equal
    if (lhs is null || rhs is null)
        return false;
    // If comparison is supported via opEquals, use it
    static if (__traits(compiles,{lhs.opEquals(rhs) && rhs.opEquals(lhs);}))
        // If same exact type => one call to method opEquals
        if (typeid(lhs) is typeid(rhs) || typeid(lhs).opEquals(typeid(rhs)))
            return lhs.opEquals(rhs);
        // General case => symmetric calls to method opEquals
        return lhs.opEquals(rhs) &&
    else static assert( false, T.stringof ~ " cannot be compared to a " ~
U.stringof );

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to