tmp/tmpes0su2ix/{from.md → to.md}
RENAMED
|
@@ -1,32 +1,35 @@
|
|
| 1 |
### Subscripting <a id="over.sub">[[over.sub]]</a>
|
| 2 |
|
| 3 |
-
A *subscripting operator function* is a function named
|
| 4 |
-
|
| 5 |
-
expression of the form
|
| 6 |
|
| 7 |
``` bnf
|
| 8 |
-
postfix-expression '['
|
| 9 |
```
|
| 10 |
|
| 11 |
the operator function is selected by overload resolution
|
| 12 |
[[over.match.oper]]. If a member function is selected, the expression is
|
| 13 |
interpreted as
|
| 14 |
|
| 15 |
``` bnf
|
| 16 |
-
postfix-expression . operator '['']' '('
|
| 17 |
```
|
| 18 |
|
| 19 |
[*Example 1*:
|
| 20 |
|
| 21 |
``` cpp
|
| 22 |
struct X {
|
| 23 |
Z operator[](std::initializer_list<int>);
|
|
|
|
| 24 |
};
|
| 25 |
X x;
|
| 26 |
-
x[{1,2,3}] = 7; // OK
|
|
|
|
| 27 |
int a[10];
|
| 28 |
a[{1,2,3}] = 7; // error: built-in subscript operator
|
|
|
|
| 29 |
```
|
| 30 |
|
| 31 |
— *end example*]
|
| 32 |
|
|
|
|
| 1 |
### Subscripting <a id="over.sub">[[over.sub]]</a>
|
| 2 |
|
| 3 |
+
A *subscripting operator function* is a member function named
|
| 4 |
+
`operator[]` with an arbitrary number of parameters. It may have default
|
| 5 |
+
arguments. For an expression of the form
|
| 6 |
|
| 7 |
``` bnf
|
| 8 |
+
postfix-expression '[' expression-listₒₚₜ ']'
|
| 9 |
```
|
| 10 |
|
| 11 |
the operator function is selected by overload resolution
|
| 12 |
[[over.match.oper]]. If a member function is selected, the expression is
|
| 13 |
interpreted as
|
| 14 |
|
| 15 |
``` bnf
|
| 16 |
+
postfix-expression . operator '['']' '(' expression-listₒₚₜ ')'
|
| 17 |
```
|
| 18 |
|
| 19 |
[*Example 1*:
|
| 20 |
|
| 21 |
``` cpp
|
| 22 |
struct X {
|
| 23 |
Z operator[](std::initializer_list<int>);
|
| 24 |
+
Z operator[](auto...);
|
| 25 |
};
|
| 26 |
X x;
|
| 27 |
+
x[{1,2,3}] = 7; // OK, meaning x.operator[]({1,2,3\)}
|
| 28 |
+
x[1,2,3] = 7; // OK, meaning x.operator[](1,2,3)
|
| 29 |
int a[10];
|
| 30 |
a[{1,2,3}] = 7; // error: built-in subscript operator
|
| 31 |
+
a[1,2,3] = 7; // error: built-in subscript operator
|
| 32 |
```
|
| 33 |
|
| 34 |
— *end example*]
|
| 35 |
|