Skip to content

Commit

Permalink
Merge pull request #190 from AndrejMitrovic/FixOpEquals
Browse files Browse the repository at this point in the history
Fix opEquals signature for structs
  • Loading branch information
Alex Rønne Petersen committed Nov 8, 2012
2 parents 91dcc6d + 37c7ff9 commit 10acaff
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions operatoroverloading.dd
Expand Up @@ -327,10 +327,20 @@ class C {
form:)
---
struct S {
int opEquals(ref const S s) { ... }
bool opEquals(ref const S s) { ... } // for l-values (e.g. variables)
bool opEquals(const S s) { ... } // for r-values (e.g. temporaries)
}
---

$(V2
$(P Alternatively you can declare a single opEquals function with an $(LINK2 template.html#auto-ref-parameters, auto ref) parameter:)
---
struct S {
bool opEquals(auto ref S s) { ... } // for l-values and r-values
}
---
)

<h2><a name="compare">Overloading &lt; &lt;=, &gt; and &gt;=</a></h2>

$(P Comparison operations are rewritten as follows:)
Expand Down Expand Up @@ -712,7 +722,7 @@ a.$(I opfunc)()

<h3>Examples</h3>

$(OL
$(OL
$(LI
-------
class A { int $(B opNeg)(); }
Expand Down Expand Up @@ -847,7 +857,7 @@ a $(I op) b
the following sequence of rules is applied, in order, to determine
which form is used:

$(OL
$(OL
$(LI The expression is rewritten as both:
---
a.$(I opfunc)(b)
Expand All @@ -874,7 +884,7 @@ b.$(I opfunc)(a)

<h4>Examples</h4>

$(OL
$(OL
$(LI

-------
Expand Down

0 comments on commit 10acaff

Please sign in to comment.