tmp/tmph75c8r44/{from.md → to.md}
RENAMED
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### General <a id="over.oper.general">[[over.oper.general]]</a>
|
| 2 |
+
|
| 3 |
+
A declaration whose *declarator-id* is an *operator-function-id* shall
|
| 4 |
+
declare a function or function template or an explicit instantiation or
|
| 5 |
+
specialization of a function template. A function so declared is an
|
| 6 |
+
*operator function*. A function template so declared is an *operator
|
| 7 |
+
function template*. A specialization of an operator function template is
|
| 8 |
+
also an operator function. An operator function is said to *implement*
|
| 9 |
+
the operator named in its *operator-function-id*.
|
| 10 |
+
|
| 11 |
+
``` bnf
|
| 12 |
+
operator-function-id:
|
| 13 |
+
operator operator
|
| 14 |
+
```
|
| 15 |
+
|
| 16 |
+
``` bnf
|
| 17 |
+
%% Ed. note: character protrusion would misalign various operators.
|
| 18 |
+
operator: one of
|
| 19 |
+
'new delete new[] delete[] co_await ( ) [ ] -> ->*'
|
| 20 |
+
'~ ! + - * / % ^ &'
|
| 21 |
+
'| = += -= *= /= %= ^= &='
|
| 22 |
+
'|= == != < > <= >= <=> &&'
|
| 23 |
+
'|| << >> <<= >>= ++ -- ,'
|
| 24 |
+
```
|
| 25 |
+
|
| 26 |
+
[*Note 1*: The operators `new[]`, `delete[]`, `()`, and `[]` are formed
|
| 27 |
+
from more than one token. The latter two operators are function call
|
| 28 |
+
[[expr.call]] and subscripting [[expr.sub]]. — *end note*]
|
| 29 |
+
|
| 30 |
+
Both the unary and binary forms of
|
| 31 |
+
|
| 32 |
+
``` bnf
|
| 33 |
+
'+ - * &'
|
| 34 |
+
```
|
| 35 |
+
|
| 36 |
+
can be overloaded.
|
| 37 |
+
|
| 38 |
+
[*Note 2*:
|
| 39 |
+
|
| 40 |
+
The following operators cannot be overloaded:
|
| 41 |
+
|
| 42 |
+
``` bnf
|
| 43 |
+
'. .* :: ?:'
|
| 44 |
+
```
|
| 45 |
+
|
| 46 |
+
nor can the preprocessing symbols `#` [[cpp.stringize]] and `##`
|
| 47 |
+
[[cpp.concat]].
|
| 48 |
+
|
| 49 |
+
— *end note*]
|
| 50 |
+
|
| 51 |
+
Operator functions are usually not called directly; instead they are
|
| 52 |
+
invoked to evaluate the operators they implement ([[over.unary]] –
|
| 53 |
+
[[over.inc]]). They can be explicitly called, however, using the
|
| 54 |
+
*operator-function-id* as the name of the function in the function call
|
| 55 |
+
syntax [[expr.call]].
|
| 56 |
+
|
| 57 |
+
[*Example 1*:
|
| 58 |
+
|
| 59 |
+
``` cpp
|
| 60 |
+
complex z = a.operator+(b); // complex z = a+b;
|
| 61 |
+
void* p = operator new(sizeof(int)*n);
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
— *end example*]
|
| 65 |
+
|
| 66 |
+
The allocation and deallocation functions, `operator` `new`, `operator`
|
| 67 |
+
`new[]`, `operator` `delete`, and `operator` `delete[]`, are described
|
| 68 |
+
completely in [[basic.stc.dynamic]]. The attributes and restrictions
|
| 69 |
+
found in the rest of [[over.oper]] do not apply to them unless
|
| 70 |
+
explicitly stated in [[basic.stc.dynamic]].
|
| 71 |
+
|
| 72 |
+
The `co_await` operator is described completely in [[expr.await]]. The
|
| 73 |
+
attributes and restrictions found in the rest of [[over.oper]] do not
|
| 74 |
+
apply to it unless explicitly stated in [[expr.await]].
|
| 75 |
+
|
| 76 |
+
An operator function shall either
|
| 77 |
+
|
| 78 |
+
- be a member function or
|
| 79 |
+
- be a non-member function that has at least one non-object parameter
|
| 80 |
+
whose type is a class, a reference to a class, an enumeration, or a
|
| 81 |
+
reference to an enumeration.
|
| 82 |
+
|
| 83 |
+
It is not possible to change the precedence, grouping, or number of
|
| 84 |
+
operands of operators. The meaning of the operators `=`, (unary) `&`,
|
| 85 |
+
and `,` (comma), predefined for each type, can be changed for specific
|
| 86 |
+
class types by defining operator functions that implement these
|
| 87 |
+
operators. Likewise, the meaning of the operators (unary) `&` and `,`
|
| 88 |
+
(comma) can be changed for specific enumeration types. Operator
|
| 89 |
+
functions are inherited in the same manner as other base class
|
| 90 |
+
functions.
|
| 91 |
+
|
| 92 |
+
An operator function shall be a prefix unary, binary, function call,
|
| 93 |
+
subscripting, class member access, increment, or decrement operator
|
| 94 |
+
function.
|
| 95 |
+
|
| 96 |
+
[*Note 3*: The identities among certain predefined operators applied to
|
| 97 |
+
basic types (for example, `++a` ≡ `a+=1`) need not hold for operator
|
| 98 |
+
functions. Some predefined operators, such as `+=`, require an operand
|
| 99 |
+
to be an lvalue when applied to basic types; this is not required by
|
| 100 |
+
operator functions. — *end note*]
|
| 101 |
+
|
| 102 |
+
An operator function cannot have default arguments [[dcl.fct.default]],
|
| 103 |
+
except where explicitly stated below. Operator functions cannot have
|
| 104 |
+
more or fewer parameters than the number required for the corresponding
|
| 105 |
+
operator, as described in the rest of [[over.oper]].
|
| 106 |
+
|
| 107 |
+
Operators not mentioned explicitly in subclauses [[over.ass]] through
|
| 108 |
+
[[over.inc]] act as ordinary unary and binary operators obeying the
|
| 109 |
+
rules of [[over.unary]] or [[over.binary]].
|
| 110 |
+
|