tmp/tmp6qo08scj/{from.md → to.md}
RENAMED
|
@@ -1,41 +1,47 @@
|
|
| 1 |
-
## Equality operators <a id="expr.eq">[[expr.eq]]</a>
|
| 2 |
|
| 3 |
``` bnf
|
| 4 |
equality-expression:
|
| 5 |
relational-expression
|
| 6 |
equality-expression '==' relational-expression
|
| 7 |
equality-expression '!=' relational-expression
|
| 8 |
```
|
| 9 |
|
| 10 |
The `==` (equal to) and the `!=` (not equal to) operators group
|
| 11 |
-
left-to-right. The
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
each case below, the operands shall have the same type after the
|
| 15 |
specified conversions have been applied.
|
| 16 |
|
| 17 |
-
If at least one of the operands is a pointer, pointer conversions
|
| 18 |
-
[[conv.ptr]]
|
| 19 |
-
qualification conversions
|
| 20 |
-
|
| 21 |
-
|
| 22 |
|
| 23 |
- If one pointer represents the address of a complete object, and
|
| 24 |
another pointer represents the address one past the last element of a
|
| 25 |
-
different complete object,[^
|
| 26 |
unspecified.
|
| 27 |
- Otherwise, if the pointers are both null, both point to the same
|
| 28 |
-
function, or both represent the same address
|
| 29 |
-
|
| 30 |
- Otherwise, the pointers compare unequal.
|
| 31 |
|
| 32 |
-
If at least one of the operands is a pointer to member,
|
| 33 |
-
member conversions
|
| 34 |
-
[[conv.
|
| 35 |
-
|
| 36 |
-
is defined as follows:
|
| 37 |
|
| 38 |
- If two pointers to members are both the null member pointer value,
|
| 39 |
they compare equal.
|
| 40 |
- If only one of two pointers to members is the null member pointer
|
| 41 |
value, they compare unequal.
|
|
@@ -55,15 +61,15 @@ is defined as follows:
|
|
| 55 |
|
| 56 |
bool b1 = (bx == cx); // unspecified
|
| 57 |
```
|
| 58 |
|
| 59 |
— *end example*]
|
| 60 |
-
- If both refer to (possibly different) members of the same union
|
| 61 |
-
[[class.union]]
|
| 62 |
- Otherwise, two pointers to members compare equal if they would refer
|
| 63 |
-
to the same member of the same most derived object
|
| 64 |
-
|
| 65 |
associated class type were performed, otherwise they compare unequal.
|
| 66 |
\[*Example 2*:
|
| 67 |
``` cpp
|
| 68 |
struct B {
|
| 69 |
int f();
|
|
@@ -91,9 +97,9 @@ operator and `false` for the `!=` operator. If two operands compare
|
|
| 91 |
unequal, the result is `false` for the `==` operator and `true` for the
|
| 92 |
`!=` operator. Otherwise, the result of each of the operators is
|
| 93 |
unspecified.
|
| 94 |
|
| 95 |
If both operands are of arithmetic or enumeration type, the usual
|
| 96 |
-
arithmetic conversions are performed on both
|
| 97 |
-
operators shall yield `true` if the specified
|
| 98 |
-
`false` if it is false.
|
| 99 |
|
|
|
|
| 1 |
+
### Equality operators <a id="expr.eq">[[expr.eq]]</a>
|
| 2 |
|
| 3 |
``` bnf
|
| 4 |
equality-expression:
|
| 5 |
relational-expression
|
| 6 |
equality-expression '==' relational-expression
|
| 7 |
equality-expression '!=' relational-expression
|
| 8 |
```
|
| 9 |
|
| 10 |
The `==` (equal to) and the `!=` (not equal to) operators group
|
| 11 |
+
left-to-right. The lvalue-to-rvalue [[conv.lval]], array-to-pointer
|
| 12 |
+
[[conv.array]], and function-to-pointer [[conv.func]] standard
|
| 13 |
+
conversions are performed on the operands. The comparison is deprecated
|
| 14 |
+
if both operands were of array type prior to these conversions
|
| 15 |
+
[[depr.array.comp]].
|
| 16 |
+
|
| 17 |
+
The converted operands shall have arithmetic, enumeration, pointer, or
|
| 18 |
+
pointer-to-member type, or type `std::nullptr_t`. The operators `==` and
|
| 19 |
+
`!=` both yield `true` or `false`, i.e., a result of type `bool`. In
|
| 20 |
each case below, the operands shall have the same type after the
|
| 21 |
specified conversions have been applied.
|
| 22 |
|
| 23 |
+
If at least one of the operands is a pointer, pointer conversions
|
| 24 |
+
[[conv.ptr]], function pointer conversions [[conv.fctptr]], and
|
| 25 |
+
qualification conversions [[conv.qual]] are performed on both operands
|
| 26 |
+
to bring them to their composite pointer type [[expr.type]]. Comparing
|
| 27 |
+
pointers is defined as follows:
|
| 28 |
|
| 29 |
- If one pointer represents the address of a complete object, and
|
| 30 |
another pointer represents the address one past the last element of a
|
| 31 |
+
different complete object, [^31] the result of the comparison is
|
| 32 |
unspecified.
|
| 33 |
- Otherwise, if the pointers are both null, both point to the same
|
| 34 |
+
function, or both represent the same address [[basic.compound]], they
|
| 35 |
+
compare equal.
|
| 36 |
- Otherwise, the pointers compare unequal.
|
| 37 |
|
| 38 |
+
If at least one of the operands is a pointer to member,
|
| 39 |
+
pointer-to-member conversions [[conv.mem]], function pointer conversions
|
| 40 |
+
[[conv.fctptr]], and qualification conversions [[conv.qual]] are
|
| 41 |
+
performed on both operands to bring them to their composite pointer type
|
| 42 |
+
[[expr.type]]. Comparing pointers to members is defined as follows:
|
| 43 |
|
| 44 |
- If two pointers to members are both the null member pointer value,
|
| 45 |
they compare equal.
|
| 46 |
- If only one of two pointers to members is the null member pointer
|
| 47 |
value, they compare unequal.
|
|
|
|
| 61 |
|
| 62 |
bool b1 = (bx == cx); // unspecified
|
| 63 |
```
|
| 64 |
|
| 65 |
— *end example*]
|
| 66 |
+
- If both refer to (possibly different) members of the same union
|
| 67 |
+
[[class.union]], they compare equal.
|
| 68 |
- Otherwise, two pointers to members compare equal if they would refer
|
| 69 |
+
to the same member of the same most derived object [[intro.object]] or
|
| 70 |
+
the same subobject if indirection with a hypothetical object of the
|
| 71 |
associated class type were performed, otherwise they compare unequal.
|
| 72 |
\[*Example 2*:
|
| 73 |
``` cpp
|
| 74 |
struct B {
|
| 75 |
int f();
|
|
|
|
| 97 |
unequal, the result is `false` for the `==` operator and `true` for the
|
| 98 |
`!=` operator. Otherwise, the result of each of the operators is
|
| 99 |
unspecified.
|
| 100 |
|
| 101 |
If both operands are of arithmetic or enumeration type, the usual
|
| 102 |
+
arithmetic conversions [[expr.arith.conv]] are performed on both
|
| 103 |
+
operands; each of the operators shall yield `true` if the specified
|
| 104 |
+
relationship is true and `false` if it is false.
|
| 105 |
|