[Issue 16657] alias this interacts with generated opCmp and opEquals
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Sat May 13 08:48:38 PDT 2017
https://issues.dlang.org/show_bug.cgi?id=16657
Walter Bright <bugzilla at digitalmars.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |bugzilla at digitalmars.com
--- Comment #2 from Walter Bright <bugzilla at digitalmars.com> ---
Since the auto-generated opEquals() theoretically always exists, having it take
precedence makes it a problem to wrap other types and defer to it. But the
problem does come in when the auto-generated opEquals() would be non-trivial,
as in:
---
struct A {
int x;
bool opEquals(int y) { return y == x; }
}
struct C {
int a;
A b;
alias a this;
}
static assert(C(1, A(1)) != C(1, A(2)));
---
The current state of affairs is that you'll need to write an explicit
C.opEquals() if using an 'alias this' and do not wish the operation to be
forwarded to it, even if the other fields have non-trivial opEquals()
implementations.
I suspect that this is the best solution if only because it is easy to
understand. It doesn't have any special cases and exceptions.
--
More information about the Digitalmars-d-bugs
mailing list