Bug 5459 – comparison of interfaces not implemented
Status
RESOLVED
Resolution
DUPLICATE
Severity
enhancement
Priority
P2
Component
druntime
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2011-01-17T09:08:09Z
Last change time
2018-02-13T07:49:56Z
Keywords
patch
Assigned to
Sean Kelly
Creator
Simen Kjaeraas
Comments
Comment #0 by simen.kjaras — 2011-01-17T09:08:09Z
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 );
}
Comment #1 by simen.kjaras — 2018-02-13T07:49:56Z
*** This issue has been marked as a duplicate of issue 4088 ***