tmp/tmpkekdivl3/{from.md → to.md}
RENAMED
|
@@ -9,26 +9,28 @@ sequence S1 is neither better than nor worse than conversion sequence
|
|
| 9 |
S2, S1 and S2 are said to be *indistinguishable conversion sequences*.
|
| 10 |
|
| 11 |
When comparing the basic forms of implicit conversion sequences (as
|
| 12 |
defined in [[over.best.ics]])
|
| 13 |
|
| 14 |
-
- a standard conversion sequence
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
- a user-defined conversion sequence
|
| 18 |
-
conversion sequence than an ellipsis conversion sequence
|
| 19 |
-
[[over.ics.ellipsis]]
|
| 20 |
|
| 21 |
Two implicit conversion sequences of the same form are indistinguishable
|
| 22 |
conversion sequences unless one of the following rules applies:
|
| 23 |
|
| 24 |
- List-initialization sequence `L1` is a better conversion sequence than
|
| 25 |
list-initialization sequence `L2` if
|
| 26 |
- `L1` converts to `std::initializer_list<X>` for some `X` and `L2`
|
| 27 |
does not, or, if not that,
|
| 28 |
-
- `L1`
|
| 29 |
-
|
|
|
|
|
|
|
| 30 |
|
| 31 |
even if one of the other rules in this paragraph would otherwise
|
| 32 |
apply.
|
| 33 |
\[*Example 1*:
|
| 34 |
``` cpp
|
|
@@ -39,10 +41,24 @@ conversion sequences unless one of the following rules applies:
|
|
| 39 |
void f2(std::pair<const char*, const char*>); // #3
|
| 40 |
void f2(std::initializer_list<std::string>); // #4
|
| 41 |
void g2() { f2({"foo","bar"}); } // chooses #4
|
| 42 |
```
|
| 43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
— *end example*]
|
| 45 |
- Standard conversion sequence `S1` is a better conversion sequence than
|
| 46 |
standard conversion sequence `S2` if
|
| 47 |
- `S1` is a proper subsequence of `S2` (comparing the conversion
|
| 48 |
sequences in the canonical form defined by [[over.ics.scs]],
|
|
@@ -50,15 +66,15 @@ conversion sequences unless one of the following rules applies:
|
|
| 50 |
sequence is considered to be a subsequence of any non-identity
|
| 51 |
conversion sequence) or, if not that,
|
| 52 |
- the rank of `S1` is better than the rank of `S2`, or `S1` and `S2`
|
| 53 |
have the same rank and are distinguishable by the rules in the
|
| 54 |
paragraph below, or, if not that,
|
| 55 |
-
- `S1` and `S2`
|
| 56 |
-
refers to an implicit object parameter of a non-static
|
| 57 |
-
function declared without a *ref-qualifier*, and `S1` binds
|
| 58 |
-
rvalue reference to an rvalue and `S2` binds an lvalue reference
|
| 59 |
-
\[*Example
|
| 60 |
``` cpp
|
| 61 |
int i;
|
| 62 |
int f1();
|
| 63 |
int&& f2();
|
| 64 |
int g(const int&);
|
|
@@ -82,45 +98,43 @@ conversion sequences unless one of the following rules applies:
|
|
| 82 |
a.p(); // calls A::p()&
|
| 83 |
```
|
| 84 |
|
| 85 |
— *end example*]
|
| 86 |
or, if not that,
|
| 87 |
-
- `S1` and `S2`
|
| 88 |
binds an lvalue reference to a function lvalue and `S2` binds an
|
| 89 |
rvalue reference to a function lvalue
|
| 90 |
-
\[*Example
|
| 91 |
``` cpp
|
| 92 |
int f(void(&)()); // #1
|
| 93 |
int f(void(&&)()); // #2
|
| 94 |
void g();
|
| 95 |
int i1 = f(g); // calls #1
|
| 96 |
```
|
| 97 |
|
| 98 |
— *end example*]
|
| 99 |
or, if not that,
|
| 100 |
-
- `S1`
|
| 101 |
-
and
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
cv-qualification signature of type `T2`
|
| 105 |
-
\[*Example 4*:
|
| 106 |
``` cpp
|
| 107 |
int f(const volatile int *);
|
| 108 |
int f(const int *);
|
| 109 |
int i;
|
| 110 |
int j = f(&i); // calls f(const int*)
|
| 111 |
```
|
| 112 |
|
| 113 |
— *end example*]
|
| 114 |
or, if not that,
|
| 115 |
- `S1`
|
| 116 |
-
and `S2`
|
| 117 |
to which the references refer are the same type except for top-level
|
| 118 |
cv-qualifiers, and the type to which the reference initialized by
|
| 119 |
`S2` refers is more cv-qualified than the type to which the
|
| 120 |
reference initialized by `S1` refers.
|
| 121 |
-
\[*Example
|
| 122 |
``` cpp
|
| 123 |
int f(const int &);
|
| 124 |
int f(int &);
|
| 125 |
int g(const int &);
|
| 126 |
int g(int);
|
|
@@ -144,11 +158,11 @@ conversion sequences unless one of the following rules applies:
|
|
| 144 |
than another user-defined conversion sequence `U2` if they contain the
|
| 145 |
same user-defined conversion function or constructor or they
|
| 146 |
initialize the same class in an aggregate initialization and in either
|
| 147 |
case the second standard conversion sequence of `U1` is better than
|
| 148 |
the second standard conversion sequence of `U2`.
|
| 149 |
-
\[*Example
|
| 150 |
``` cpp
|
| 151 |
struct A {
|
| 152 |
operator short();
|
| 153 |
} a;
|
| 154 |
int f(int);
|
|
@@ -162,12 +176,12 @@ conversion sequences unless one of the following rules applies:
|
|
| 162 |
Standard conversion sequences are ordered by their ranks: an Exact Match
|
| 163 |
is a better conversion than a Promotion, which is a better conversion
|
| 164 |
than a Conversion. Two conversion sequences with the same rank are
|
| 165 |
indistinguishable unless one of the following rules applies:
|
| 166 |
|
| 167 |
-
- A conversion that does not convert a pointer
|
| 168 |
-
`
|
| 169 |
- A conversion that promotes an enumeration whose underlying type is
|
| 170 |
fixed to its underlying type is better than one that promotes to the
|
| 171 |
promoted underlying type, if the two are different.
|
| 172 |
- If class `B` is derived directly or indirectly from class `A`,
|
| 173 |
conversion of `B*` to `A*` is better than conversion of `B*` to
|
|
@@ -175,11 +189,11 @@ indistinguishable unless one of the following rules applies:
|
|
| 175 |
of `B*` to `void*`.
|
| 176 |
- If class `B` is derived directly or indirectly from class `A` and
|
| 177 |
class `C` is derived directly or indirectly from `B`,
|
| 178 |
- conversion of `C*` to `B*` is better than conversion of `C*` to
|
| 179 |
`A*`,
|
| 180 |
-
\[*Example
|
| 181 |
``` cpp
|
| 182 |
struct A {};
|
| 183 |
struct B : public A {};
|
| 184 |
struct C : public B {};
|
| 185 |
C* pc;
|
|
|
|
| 9 |
S2, S1 and S2 are said to be *indistinguishable conversion sequences*.
|
| 10 |
|
| 11 |
When comparing the basic forms of implicit conversion sequences (as
|
| 12 |
defined in [[over.best.ics]])
|
| 13 |
|
| 14 |
+
- a standard conversion sequence [[over.ics.scs]] is a better conversion
|
| 15 |
+
sequence than a user-defined conversion sequence or an ellipsis
|
| 16 |
+
conversion sequence, and
|
| 17 |
+
- a user-defined conversion sequence [[over.ics.user]] is a better
|
| 18 |
+
conversion sequence than an ellipsis conversion sequence
|
| 19 |
+
[[over.ics.ellipsis]].
|
| 20 |
|
| 21 |
Two implicit conversion sequences of the same form are indistinguishable
|
| 22 |
conversion sequences unless one of the following rules applies:
|
| 23 |
|
| 24 |
- List-initialization sequence `L1` is a better conversion sequence than
|
| 25 |
list-initialization sequence `L2` if
|
| 26 |
- `L1` converts to `std::initializer_list<X>` for some `X` and `L2`
|
| 27 |
does not, or, if not that,
|
| 28 |
+
- `L1` and `L2` convert to arrays of the same element type, and either
|
| 29 |
+
the number of elements n₁ initialized by `L1` is less than the
|
| 30 |
+
number of elements n₂ initialized by `L2`, or n₁ = n₂ and `L2`
|
| 31 |
+
converts to an array of unknown bound and `L1` does not,
|
| 32 |
|
| 33 |
even if one of the other rules in this paragraph would otherwise
|
| 34 |
apply.
|
| 35 |
\[*Example 1*:
|
| 36 |
``` cpp
|
|
|
|
| 41 |
void f2(std::pair<const char*, const char*>); // #3
|
| 42 |
void f2(std::initializer_list<std::string>); // #4
|
| 43 |
void g2() { f2({"foo","bar"}); } // chooses #4
|
| 44 |
```
|
| 45 |
|
| 46 |
+
— *end example*]
|
| 47 |
+
\[*Example 2*:
|
| 48 |
+
``` cpp
|
| 49 |
+
void f(int (&&)[] ); // #1
|
| 50 |
+
void f(double (&&)[] ); // #2
|
| 51 |
+
void f(int (&&)[2]); // #3
|
| 52 |
+
|
| 53 |
+
f( {1} ); // Calls #1: Better than #2 due to conversion, better than #3 due to bounds
|
| 54 |
+
f( {1.0} ); // Calls #2: Identity conversion is better than floating-integral conversion
|
| 55 |
+
f( {1.0, 2.0} ); // Calls #2: Identity conversion is better than floating-integral conversion
|
| 56 |
+
f( {1, 2} ); // Calls #3: Converting to array of known bound is better than to unknown bound,
|
| 57 |
+
// and an identity conversion is better than floating-integral conversion
|
| 58 |
+
```
|
| 59 |
+
|
| 60 |
— *end example*]
|
| 61 |
- Standard conversion sequence `S1` is a better conversion sequence than
|
| 62 |
standard conversion sequence `S2` if
|
| 63 |
- `S1` is a proper subsequence of `S2` (comparing the conversion
|
| 64 |
sequences in the canonical form defined by [[over.ics.scs]],
|
|
|
|
| 66 |
sequence is considered to be a subsequence of any non-identity
|
| 67 |
conversion sequence) or, if not that,
|
| 68 |
- the rank of `S1` is better than the rank of `S2`, or `S1` and `S2`
|
| 69 |
have the same rank and are distinguishable by the rules in the
|
| 70 |
paragraph below, or, if not that,
|
| 71 |
+
- `S1` and `S2` include reference bindings [[dcl.init.ref]] and
|
| 72 |
+
neither refers to an implicit object parameter of a non-static
|
| 73 |
+
member function declared without a *ref-qualifier*, and `S1` binds
|
| 74 |
+
an rvalue reference to an rvalue and `S2` binds an lvalue reference
|
| 75 |
+
\[*Example 3*:
|
| 76 |
``` cpp
|
| 77 |
int i;
|
| 78 |
int f1();
|
| 79 |
int&& f2();
|
| 80 |
int g(const int&);
|
|
|
|
| 98 |
a.p(); // calls A::p()&
|
| 99 |
```
|
| 100 |
|
| 101 |
— *end example*]
|
| 102 |
or, if not that,
|
| 103 |
+
- `S1` and `S2` include reference bindings [[dcl.init.ref]] and `S1`
|
| 104 |
binds an lvalue reference to a function lvalue and `S2` binds an
|
| 105 |
rvalue reference to a function lvalue
|
| 106 |
+
\[*Example 4*:
|
| 107 |
``` cpp
|
| 108 |
int f(void(&)()); // #1
|
| 109 |
int f(void(&&)()); // #2
|
| 110 |
void g();
|
| 111 |
int i1 = f(g); // calls #1
|
| 112 |
```
|
| 113 |
|
| 114 |
— *end example*]
|
| 115 |
or, if not that,
|
| 116 |
+
- `S1` and `S2` differ only in their qualification conversion
|
| 117 |
+
[[conv.qual]] and yield similar types `T1` and `T2`, respectively,
|
| 118 |
+
where `T1` can be converted to `T2` by a qualification conversion.
|
| 119 |
+
\[*Example 5*:
|
|
|
|
|
|
|
| 120 |
``` cpp
|
| 121 |
int f(const volatile int *);
|
| 122 |
int f(const int *);
|
| 123 |
int i;
|
| 124 |
int j = f(&i); // calls f(const int*)
|
| 125 |
```
|
| 126 |
|
| 127 |
— *end example*]
|
| 128 |
or, if not that,
|
| 129 |
- `S1`
|
| 130 |
+
and `S2` include reference bindings [[dcl.init.ref]], and the types
|
| 131 |
to which the references refer are the same type except for top-level
|
| 132 |
cv-qualifiers, and the type to which the reference initialized by
|
| 133 |
`S2` refers is more cv-qualified than the type to which the
|
| 134 |
reference initialized by `S1` refers.
|
| 135 |
+
\[*Example 6*:
|
| 136 |
``` cpp
|
| 137 |
int f(const int &);
|
| 138 |
int f(int &);
|
| 139 |
int g(const int &);
|
| 140 |
int g(int);
|
|
|
|
| 158 |
than another user-defined conversion sequence `U2` if they contain the
|
| 159 |
same user-defined conversion function or constructor or they
|
| 160 |
initialize the same class in an aggregate initialization and in either
|
| 161 |
case the second standard conversion sequence of `U1` is better than
|
| 162 |
the second standard conversion sequence of `U2`.
|
| 163 |
+
\[*Example 7*:
|
| 164 |
``` cpp
|
| 165 |
struct A {
|
| 166 |
operator short();
|
| 167 |
} a;
|
| 168 |
int f(int);
|
|
|
|
| 176 |
Standard conversion sequences are ordered by their ranks: an Exact Match
|
| 177 |
is a better conversion than a Promotion, which is a better conversion
|
| 178 |
than a Conversion. Two conversion sequences with the same rank are
|
| 179 |
indistinguishable unless one of the following rules applies:
|
| 180 |
|
| 181 |
+
- A conversion that does not convert a pointer or a pointer to member to
|
| 182 |
+
`bool` is better than one that does.
|
| 183 |
- A conversion that promotes an enumeration whose underlying type is
|
| 184 |
fixed to its underlying type is better than one that promotes to the
|
| 185 |
promoted underlying type, if the two are different.
|
| 186 |
- If class `B` is derived directly or indirectly from class `A`,
|
| 187 |
conversion of `B*` to `A*` is better than conversion of `B*` to
|
|
|
|
| 189 |
of `B*` to `void*`.
|
| 190 |
- If class `B` is derived directly or indirectly from class `A` and
|
| 191 |
class `C` is derived directly or indirectly from `B`,
|
| 192 |
- conversion of `C*` to `B*` is better than conversion of `C*` to
|
| 193 |
`A*`,
|
| 194 |
+
\[*Example 8*:
|
| 195 |
``` cpp
|
| 196 |
struct A {};
|
| 197 |
struct B : public A {};
|
| 198 |
struct C : public B {};
|
| 199 |
C* pc;
|