tmp/tmpfzq0__uv/{from.md → to.md}
RENAMED
|
@@ -26,61 +26,39 @@ For subtraction, one of the following shall hold:
|
|
| 26 |
|
| 27 |
The result of the binary `+` operator is the sum of the operands. The
|
| 28 |
result of the binary `-` operator is the difference resulting from the
|
| 29 |
subtraction of the second operand from the first.
|
| 30 |
|
| 31 |
-
For the purposes of these operators, a pointer to a nonarray object
|
| 32 |
-
behaves the same as a pointer to the first element of an array of length
|
| 33 |
-
one with the type of the object as its element type.
|
| 34 |
-
|
| 35 |
When an expression that has integral type is added to or subtracted from
|
| 36 |
a pointer, the result has the type of the pointer operand. If the
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
`(P)-N` (where `N` has the value n) point to, respectively, the i+n-th
|
| 44 |
-
and i-n-th elements of the array object, provided they exist. Moreover,
|
| 45 |
-
if the expression `P` points to the last element of an array object, the
|
| 46 |
-
expression `(P)+1` points one past the last element of the array object,
|
| 47 |
-
and if the expression `Q` points one past the last element of an array
|
| 48 |
-
object, the expression `(Q)-1` points to the last element of the array
|
| 49 |
-
object. If both the pointer operand and the result point to elements of
|
| 50 |
-
the same array object, or one past the last element of the array object,
|
| 51 |
-
the evaluation shall not produce an overflow; otherwise, the behavior is
|
| 52 |
-
undefined.
|
| 53 |
|
| 54 |
When two pointers to elements of the same array object are subtracted,
|
| 55 |
-
the
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
`
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
past the last element of an array object, and the expression `Q` points
|
| 66 |
-
to the last element of the same array object, the expression
|
| 67 |
-
`((Q)+1)-(P)` has the same value as `((Q)-(P))+1` and as
|
| 68 |
-
`-((P)-((Q)+1))`, and has the value zero if the expression `P` points
|
| 69 |
-
one past the last element of the array object, even though the
|
| 70 |
-
expression `(Q)+1` does not point to an element of the array object.
|
| 71 |
-
Unless both pointers point to elements of the same array object, or one
|
| 72 |
-
past the last element of the array object, the behavior is
|
| 73 |
-
undefined.[^26]
|
| 74 |
|
| 75 |
For addition or subtraction, if the expressions `P` or `Q` have type
|
| 76 |
-
“pointer to cv `T`”, where `T`
|
| 77 |
-
|
| 78 |
-
to a base class cannot be used for pointer arithmetic when the array
|
| 79 |
-
contains objects of a derived class type.
|
| 80 |
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
|
|
|
|
|
|
|
|
|
| 86 |
|
|
|
|
| 26 |
|
| 27 |
The result of the binary `+` operator is the sum of the operands. The
|
| 28 |
result of the binary `-` operator is the difference resulting from the
|
| 29 |
subtraction of the second operand from the first.
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
When an expression that has integral type is added to or subtracted from
|
| 32 |
a pointer, the result has the type of the pointer operand. If the
|
| 33 |
+
expression `P` points to element x[i] of an array object `x` with n
|
| 34 |
+
elements, [^25] the expressions `P + J` and `J + P` (where `J` has the
|
| 35 |
+
value j) point to the (possibly-hypothetical) element x[i + j] if
|
| 36 |
+
0 ≤ i + j ≤ n; otherwise, the behavior is undefined. Likewise, the
|
| 37 |
+
expression `P - J` points to the (possibly-hypothetical) element
|
| 38 |
+
x[i - j] if 0 ≤ i - j ≤ n; otherwise, the behavior is undefined.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
When two pointers to elements of the same array object are subtracted,
|
| 41 |
+
the type of the result is an *implementation-defined* signed integral
|
| 42 |
+
type; this type shall be the same type that is defined as
|
| 43 |
+
`std::ptrdiff_t` in the `<cstddef>` header ([[support.types]]). If the
|
| 44 |
+
expressions `P` and `Q` point to, respectively, elements x[i] and x[j]
|
| 45 |
+
of the same array object `x`, the expression `P - Q` has the value
|
| 46 |
+
i - j; otherwise, the behavior is undefined.
|
| 47 |
+
|
| 48 |
+
[*Note 1*: If the value i - j is not in the range of representable
|
| 49 |
+
values of type `std::ptrdiff_t`, the behavior is
|
| 50 |
+
undefined. — *end note*]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
For addition or subtraction, if the expressions `P` or `Q` have type
|
| 53 |
+
“pointer to cv `T`”, where `T` and the array element type are not
|
| 54 |
+
similar ([[conv.qual]]), the behavior is undefined.
|
|
|
|
|
|
|
| 55 |
|
| 56 |
+
[*Note 2*: In particular, a pointer to a base class cannot be used for
|
| 57 |
+
pointer arithmetic when the array contains objects of a derived class
|
| 58 |
+
type. — *end note*]
|
| 59 |
+
|
| 60 |
+
If the value 0 is added to or subtracted from a null pointer value, the
|
| 61 |
+
result is a null pointer value. If two null pointer values are
|
| 62 |
+
subtracted, the result compares equal to the value 0 converted to the
|
| 63 |
+
type `std::ptrdiff_t`.
|
| 64 |
|