From Jason Turner

[over.binary]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpvhtw1jo4/{from.md → to.md} +79 -6
tmp/tmpvhtw1jo4/{from.md → to.md} RENAMED
@@ -1,9 +1,82 @@
1
  ### Binary operators <a id="over.binary">[[over.binary]]</a>
2
 
3
- A binary operator shall be implemented either by a non-static member
4
- function ([[class.mfct]]) with one parameter or by a non-member
5
- function with two parameters. Thus, for any binary operator `@`, `x@y`
6
- can be interpreted as either `x.operator@(y)` or `operator@(x,y)`. If
7
- both forms of the operator function have been declared, the rules in 
8
- [[over.match.oper]] determine which, if any, interpretation is used.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
 
1
  ### Binary operators <a id="over.binary">[[over.binary]]</a>
2
 
3
+ A *binary operator function* is a function named `operator@` for a
4
+ binary operator `@` that is either a non-static member function
5
+ [[class.mfct]] with one parameter or a non-member function with two
6
+ parameters. For an expression `x @ y` with subexpressions x and y, the
7
+ operator function is selected by overload resolution
8
+ [[over.match.oper]]. If a member function is selected, the expression is
9
+ interpreted as
10
+
11
+ ``` bnf
12
+ x '.' operator '@' '(' y ')'
13
+ ```
14
+
15
+ Otherwise, if a non-member function is selected, the expression is
16
+ interpreted as
17
+
18
+ ``` bnf
19
+ operator '@' '(' x ',' y ')'
20
+ ```
21
+
22
+ An *equality operator function* is an operator function for an equality
23
+ operator [[expr.eq]]. A *relational operator function* is an operator
24
+ function for a relational operator [[expr.rel]]. A
25
+ *three-way comparison operator function* is an operator function for the
26
+ three-way comparison operator [[expr.spaceship]]. A
27
+ *comparison operator function* is an equality operator function, a
28
+ relational operator function, or a three-way comparison operator
29
+ function.
30
+
31
+ #### Simple assignment <a id="over.ass">[[over.ass]]</a>
32
+
33
+ A *simple assignment operator function* is a binary operator function
34
+ named `operator=`. A simple assignment operator function shall be a
35
+ non-static member function.
36
+
37
+ [*Note 1*: Because only standard conversion sequences are considered
38
+ when converting to the left operand of an assignment operation
39
+ [[over.best.ics]], an expression `x = y` with a subexpression x of class
40
+ type is always interpreted as `x.operator=(y)`. — *end note*]
41
+
42
+ [*Note 2*: Since a copy assignment operator is implicitly declared for
43
+ a class if not declared by the user [[class.copy.assign]], a base class
44
+ assignment operator function is always hidden by the copy assignment
45
+ operator function of the derived class. — *end note*]
46
+
47
+ [*Note 3*:
48
+
49
+ Any assignment operator function, even the copy and move assignment
50
+ operators, can be virtual. For a derived class `D` with a base class `B`
51
+ for which a virtual copy/move assignment has been declared, the
52
+ copy/move assignment operator in `D` does not override `B`’s virtual
53
+ copy/move assignment operator.
54
+
55
+ [*Example 1*:
56
+
57
+ ``` cpp
58
+ struct B {
59
+ virtual int operator= (int);
60
+ virtual B& operator= (const B&);
61
+ };
62
+ struct D : B {
63
+ virtual int operator= (int);
64
+ virtual D& operator= (const B&);
65
+ };
66
+
67
+ D dobj1;
68
+ D dobj2;
69
+ B* bptr = &dobj1;
70
+ void f() {
71
+ bptr->operator=(99); // calls D::operator=(int)
72
+ *bptr = 99; // ditto
73
+ bptr->operator=(dobj2); // calls D::operator=(const B&)
74
+ *bptr = dobj2; // ditto
75
+ dobj1 = dobj2; // calls implicitly-declared D::operator=(const D&)
76
+ }
77
+ ```
78
+
79
+ — *end example*]
80
+
81
+ — *end note*]
82