tmp/tmpnug1e6oe/{from.md → to.md}
RENAMED
|
@@ -13,16 +13,23 @@ or pointer to member type, or type `std::nullptr_t`. The operators `==`
|
|
| 13 |
and `!=` both yield `true` or `false`, i.e., a result of type `bool`. In
|
| 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 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
function, or both represent the same address ([[basic.compound]]),
|
| 23 |
-
|
|
|
|
| 24 |
|
| 25 |
If at least one of the operands is a pointer to member, pointer to
|
| 26 |
member conversions ([[conv.mem]]) and qualification conversions (
|
| 27 |
[[conv.qual]]) are performed on both operands to bring them to their
|
| 28 |
composite pointer type (Clause [[expr]]). Comparing pointers to members
|
|
@@ -35,24 +42,30 @@ is defined as follows:
|
|
| 35 |
- If either is a pointer to a virtual member function, the result is
|
| 36 |
unspecified.
|
| 37 |
- If one refers to a member of class `C1` and the other refers to a
|
| 38 |
member of a different class `C2`, where neither is a base class of the
|
| 39 |
other, the result is unspecified.
|
|
|
|
| 40 |
``` cpp
|
| 41 |
struct A {};
|
| 42 |
struct B : A { int x; };
|
| 43 |
struct C : A { int x; };
|
| 44 |
|
| 45 |
int A::*bx = (int(A::*))&B::x;
|
| 46 |
int A::*cx = (int(A::*))&C::x;
|
| 47 |
|
| 48 |
bool b1 = (bx == cx); // unspecified
|
| 49 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
- Otherwise, two pointers to members compare equal if they would refer
|
| 51 |
to the same member of the same most derived object ([[intro.object]])
|
| 52 |
or the same subobject if indirection with a hypothetical object of the
|
| 53 |
associated class type were performed, otherwise they compare unequal.
|
|
|
|
| 54 |
``` cpp
|
| 55 |
struct B {
|
| 56 |
int f();
|
| 57 |
};
|
| 58 |
struct L : B { };
|
|
@@ -66,10 +79,12 @@ is defined as follows:
|
|
| 66 |
int (D::*pdr)() = pr;
|
| 67 |
bool x = (pdl == pdr); // false
|
| 68 |
bool y = (pb == pl); // true
|
| 69 |
```
|
| 70 |
|
|
|
|
|
|
|
| 71 |
Two operands of type `std::nullptr_t` or one operand of type
|
| 72 |
`std::nullptr_t` and the other a null pointer constant compare equal.
|
| 73 |
|
| 74 |
If two operands compare equal, the result is `true` for the `==`
|
| 75 |
operator and `false` for the `!=` operator. If two operands compare
|
|
|
|
| 13 |
and `!=` both yield `true` or `false`, i.e., a result of type `bool`. In
|
| 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]]), function pointer conversions ([[conv.fctptr]]), and
|
| 19 |
+
qualification conversions ([[conv.qual]]) are performed on both
|
| 20 |
+
operands to bring them to their composite pointer type (Clause
|
| 21 |
+
[[expr]]). Comparing pointers is defined as follows:
|
| 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,[^27] the result of the comparison is
|
| 26 |
+
unspecified.
|
| 27 |
+
- Otherwise, if the pointers are both null, both point to the same
|
| 28 |
function, or both represent the same address ([[basic.compound]]),
|
| 29 |
+
they compare equal.
|
| 30 |
+
- Otherwise, the pointers compare unequal.
|
| 31 |
|
| 32 |
If at least one of the operands is a pointer to member, pointer to
|
| 33 |
member conversions ([[conv.mem]]) and qualification conversions (
|
| 34 |
[[conv.qual]]) are performed on both operands to bring them to their
|
| 35 |
composite pointer type (Clause [[expr]]). Comparing pointers to members
|
|
|
|
| 42 |
- If either is a pointer to a virtual member function, the result is
|
| 43 |
unspecified.
|
| 44 |
- If one refers to a member of class `C1` and the other refers to a
|
| 45 |
member of a different class `C2`, where neither is a base class of the
|
| 46 |
other, the result is unspecified.
|
| 47 |
+
\[*Example 1*:
|
| 48 |
``` cpp
|
| 49 |
struct A {};
|
| 50 |
struct B : A { int x; };
|
| 51 |
struct C : A { int x; };
|
| 52 |
|
| 53 |
int A::*bx = (int(A::*))&B::x;
|
| 54 |
int A::*cx = (int(A::*))&C::x;
|
| 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]]), they compare equal.
|
| 62 |
- Otherwise, two pointers to members compare equal if they would refer
|
| 63 |
to the same member of the same most derived object ([[intro.object]])
|
| 64 |
or the same subobject if indirection with a hypothetical object of the
|
| 65 |
associated class type were performed, otherwise they compare unequal.
|
| 66 |
+
\[*Example 2*:
|
| 67 |
``` cpp
|
| 68 |
struct B {
|
| 69 |
int f();
|
| 70 |
};
|
| 71 |
struct L : B { };
|
|
|
|
| 79 |
int (D::*pdr)() = pr;
|
| 80 |
bool x = (pdl == pdr); // false
|
| 81 |
bool y = (pb == pl); // true
|
| 82 |
```
|
| 83 |
|
| 84 |
+
— *end example*]
|
| 85 |
+
|
| 86 |
Two operands of type `std::nullptr_t` or one operand of type
|
| 87 |
`std::nullptr_t` and the other a null pointer constant compare equal.
|
| 88 |
|
| 89 |
If two operands compare equal, the result is `true` for the `==`
|
| 90 |
operator and `false` for the `!=` operator. If two operands compare
|