[Issue 11161] Document the default struct equality comparison and operator overloading
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Nov 5 00:31:28 PST 2013
http://d.puremagic.com/issues/show_bug.cgi?id=11161
Denis Shelomovskij <verylonglogin.reg at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |major
--- Comment #6 from Denis Shelomovskij <verylonglogin.reg at gmail.com> 2013-11-05 11:31:21 MSK ---
(In reply to comment #2)
> 1. Find opEquals method from the type of operands
> 2. If 'alias this' declaration exists, compiler tries to resolve equality
> operation via alias this. -> `t1.value != t2.value` is tested, and succeeds to
> compile.
Just to be clear, currently we have this:
---
struct S
{
int i, j;
alias j this;
}
void main()
{
S s1 = {0}, s2 = {1};
assert(s1 == s2); // ok, resolved as `s1.j == s2.j`
}
---
And I'm quite sure it must be clearly documented.
Also it should be mentioned one have to add:
---
bool opEquals(in typeof(this) other)
{ return this.tupleof == other.tupleof; }
---
if "old" comparison behavior is needed.
--
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