[Issue 5459] New: comparison of interfaces not implemented

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jan 17 09:10:05 PST 2011


http://d.puremagic.com/issues/show_bug.cgi?id=5459

           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
        AssignedTo: sean at invisibleduck.org
        ReportedBy: simen.kjaras at gmail.com


--- Comment #0 from Simen Kjaeraas <simen.kjaras at gmail.com> 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 ==
interface)))
{
    // 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) &&
            rhs.opEquals(lhs);
    }
    else static assert( false, T.stringof ~ " cannot be compared to a " ~
U.stringof );
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list