tmp/tmpbiep41wj/{from.md → to.md}
RENAMED
|
@@ -9,11 +9,11 @@ is only possible if the parameter has an aggregate type that can be
|
|
| 9 |
initialized from the initializer list according to the rules for
|
| 10 |
aggregate initialization [[dcl.init.aggr]], in which case the implicit
|
| 11 |
conversion sequence is a user-defined conversion sequence whose second
|
| 12 |
standard conversion sequence is an identity conversion.
|
| 13 |
|
| 14 |
-
[*Note
|
| 15 |
|
| 16 |
Aggregate initialization does not require that the members are declared
|
| 17 |
in designation order. If, after overload resolution, the order does not
|
| 18 |
match for the selected overload, the initialization of the parameter
|
| 19 |
will be ill-formed [[dcl.init.list]].
|
|
@@ -42,14 +42,15 @@ void h() {
|
|
| 42 |
Otherwise, if the parameter type is an aggregate class `X` and the
|
| 43 |
initializer list has a single element of type cv `U`, where `U` is `X`
|
| 44 |
or a class derived from `X`, the implicit conversion sequence is the one
|
| 45 |
required to convert the element to the parameter type.
|
| 46 |
|
| 47 |
-
Otherwise, if the parameter type is a character array
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
|
|
|
| 51 |
|
| 52 |
Otherwise, if the parameter type is `std::initializer_list<X>` and all
|
| 53 |
the elements of the initializer list can be implicitly converted to `X`,
|
| 54 |
the implicit conversion sequence is the worst conversion necessary to
|
| 55 |
convert an element of the list to `X`, or if the initializer list has no
|
|
@@ -59,13 +60,13 @@ constructor.
|
|
| 59 |
|
| 60 |
[*Example 7*:
|
| 61 |
|
| 62 |
``` cpp
|
| 63 |
void f(std::initializer_list<int>);
|
| 64 |
-
f( {} ); // OK
|
| 65 |
-
f( {1,2,3} ); // OK
|
| 66 |
-
f( {'a','b'} ); // OK
|
| 67 |
f( {1.0} ); // error: narrowing
|
| 68 |
|
| 69 |
struct A {
|
| 70 |
A(std::initializer_list<double>); // #1
|
| 71 |
A(std::initializer_list<complex<double>>); // #2
|
|
@@ -76,11 +77,11 @@ A a{ 1.0,2.0 }; // OK, uses #1
|
|
| 76 |
void g(A);
|
| 77 |
g({ "foo", "bar" }); // OK, uses #3
|
| 78 |
|
| 79 |
typedef int IA[3];
|
| 80 |
void h(const IA&);
|
| 81 |
-
h({ 1, 2, 3 }); // OK
|
| 82 |
```
|
| 83 |
|
| 84 |
— *end example*]
|
| 85 |
|
| 86 |
Otherwise, if the parameter type is “array of `N` `X`” or “array of
|
|
@@ -98,11 +99,11 @@ the argument initializer list:
|
|
| 98 |
- If `C` is not an initializer-list constructor and the initializer list
|
| 99 |
has a single element of type cv `U`, where `U` is `X` or a class
|
| 100 |
derived from `X`, the implicit conversion sequence has Exact Match
|
| 101 |
rank if `U` is `X`, or Conversion rank if `U` is derived from `X`.
|
| 102 |
- Otherwise, the implicit conversion sequence is a user-defined
|
| 103 |
-
conversion sequence
|
| 104 |
identity conversion.
|
| 105 |
|
| 106 |
If multiple constructors are viable but none is better than the others,
|
| 107 |
the implicit conversion sequence is the ambiguous conversion sequence.
|
| 108 |
User-defined conversions are allowed for conversion of the initializer
|
|
@@ -114,61 +115,61 @@ list elements to the constructor parameter types except as noted in
|
|
| 114 |
``` cpp
|
| 115 |
struct A {
|
| 116 |
A(std::initializer_list<int>);
|
| 117 |
};
|
| 118 |
void f(A);
|
| 119 |
-
f( {'a', 'b'} ); // OK
|
| 120 |
|
| 121 |
struct B {
|
| 122 |
B(int, double);
|
| 123 |
};
|
| 124 |
void g(B);
|
| 125 |
-
g( {'a', 'b'} ); // OK
|
| 126 |
g( {1.0, 1.0} ); // error: narrowing
|
| 127 |
|
| 128 |
void f(B);
|
| 129 |
f( {'a', 'b'} ); // error: ambiguous f(A) or f(B)
|
| 130 |
|
| 131 |
struct C {
|
| 132 |
C(std::string);
|
| 133 |
};
|
| 134 |
void h(C);
|
| 135 |
-
h({"foo"}); // OK
|
| 136 |
|
| 137 |
struct D {
|
| 138 |
D(A, C);
|
| 139 |
};
|
| 140 |
void i(D);
|
| 141 |
-
i({ {1,2}, {"bar"} }); // OK
|
| 142 |
```
|
| 143 |
|
| 144 |
— *end example*]
|
| 145 |
|
| 146 |
Otherwise, if the parameter has an aggregate type which can be
|
| 147 |
initialized from the initializer list according to the rules for
|
| 148 |
aggregate initialization [[dcl.init.aggr]], the implicit conversion
|
| 149 |
-
sequence is a user-defined conversion sequence
|
| 150 |
-
conversion sequence an identity conversion.
|
| 151 |
|
| 152 |
[*Example 9*:
|
| 153 |
|
| 154 |
``` cpp
|
| 155 |
struct A {
|
| 156 |
int m1;
|
| 157 |
double m2;
|
| 158 |
};
|
| 159 |
|
| 160 |
void f(A);
|
| 161 |
-
f( {'a', 'b'} ); // OK
|
| 162 |
f( {1.0} ); // error: narrowing
|
| 163 |
```
|
| 164 |
|
| 165 |
— *end example*]
|
| 166 |
|
| 167 |
Otherwise, if the parameter is a reference, see [[over.ics.ref]].
|
| 168 |
|
| 169 |
-
[*Note
|
| 170 |
underlying temporary for the reference. — *end note*]
|
| 171 |
|
| 172 |
[*Example 10*:
|
| 173 |
|
| 174 |
``` cpp
|
|
@@ -176,11 +177,11 @@ struct A {
|
|
| 176 |
int m1;
|
| 177 |
double m2;
|
| 178 |
};
|
| 179 |
|
| 180 |
void f(const A&);
|
| 181 |
-
f( {'a', 'b'} ); // OK
|
| 182 |
f( {1.0} ); // error: narrowing
|
| 183 |
|
| 184 |
void g(const double &);
|
| 185 |
g({1}); // same conversion as int to double
|
| 186 |
```
|
|
@@ -193,21 +194,21 @@ Otherwise, if the parameter type is not a class:
|
|
| 193 |
initializer list, the implicit conversion sequence is the one required
|
| 194 |
to convert the element to the parameter type;
|
| 195 |
\[*Example 11*:
|
| 196 |
``` cpp
|
| 197 |
void f(int);
|
| 198 |
-
f( {'a'} ); // OK
|
| 199 |
f( {1.0} ); // error: narrowing
|
| 200 |
```
|
| 201 |
|
| 202 |
— *end example*]
|
| 203 |
- if the initializer list has no elements, the implicit conversion
|
| 204 |
sequence is the identity conversion.
|
| 205 |
\[*Example 12*:
|
| 206 |
``` cpp
|
| 207 |
void f(int);
|
| 208 |
-
f( { } ); // OK
|
| 209 |
```
|
| 210 |
|
| 211 |
— *end example*]
|
| 212 |
|
| 213 |
In all cases other than those enumerated above, no conversion is
|
|
|
|
| 9 |
initialized from the initializer list according to the rules for
|
| 10 |
aggregate initialization [[dcl.init.aggr]], in which case the implicit
|
| 11 |
conversion sequence is a user-defined conversion sequence whose second
|
| 12 |
standard conversion sequence is an identity conversion.
|
| 13 |
|
| 14 |
+
[*Note 10*:
|
| 15 |
|
| 16 |
Aggregate initialization does not require that the members are declared
|
| 17 |
in designation order. If, after overload resolution, the order does not
|
| 18 |
match for the selected overload, the initialization of the parameter
|
| 19 |
will be ill-formed [[dcl.init.list]].
|
|
|
|
| 42 |
Otherwise, if the parameter type is an aggregate class `X` and the
|
| 43 |
initializer list has a single element of type cv `U`, where `U` is `X`
|
| 44 |
or a class derived from `X`, the implicit conversion sequence is the one
|
| 45 |
required to convert the element to the parameter type.
|
| 46 |
|
| 47 |
+
Otherwise, if the parameter type is a character array[^8]
|
| 48 |
+
|
| 49 |
+
and the initializer list has a single element that is an
|
| 50 |
+
appropriately-typed *string-literal* [[dcl.init.string]], the implicit
|
| 51 |
+
conversion sequence is the identity conversion.
|
| 52 |
|
| 53 |
Otherwise, if the parameter type is `std::initializer_list<X>` and all
|
| 54 |
the elements of the initializer list can be implicitly converted to `X`,
|
| 55 |
the implicit conversion sequence is the worst conversion necessary to
|
| 56 |
convert an element of the list to `X`, or if the initializer list has no
|
|
|
|
| 60 |
|
| 61 |
[*Example 7*:
|
| 62 |
|
| 63 |
``` cpp
|
| 64 |
void f(std::initializer_list<int>);
|
| 65 |
+
f( {} ); // OK, f(initializer_list<int>) identity conversion
|
| 66 |
+
f( {1,2,3} ); // OK, f(initializer_list<int>) identity conversion
|
| 67 |
+
f( {'a','b'} ); // OK, f(initializer_list<int>) integral promotion
|
| 68 |
f( {1.0} ); // error: narrowing
|
| 69 |
|
| 70 |
struct A {
|
| 71 |
A(std::initializer_list<double>); // #1
|
| 72 |
A(std::initializer_list<complex<double>>); // #2
|
|
|
|
| 77 |
void g(A);
|
| 78 |
g({ "foo", "bar" }); // OK, uses #3
|
| 79 |
|
| 80 |
typedef int IA[3];
|
| 81 |
void h(const IA&);
|
| 82 |
+
h({ 1, 2, 3 }); // OK, identity conversion
|
| 83 |
```
|
| 84 |
|
| 85 |
— *end example*]
|
| 86 |
|
| 87 |
Otherwise, if the parameter type is “array of `N` `X`” or “array of
|
|
|
|
| 99 |
- If `C` is not an initializer-list constructor and the initializer list
|
| 100 |
has a single element of type cv `U`, where `U` is `X` or a class
|
| 101 |
derived from `X`, the implicit conversion sequence has Exact Match
|
| 102 |
rank if `U` is `X`, or Conversion rank if `U` is derived from `X`.
|
| 103 |
- Otherwise, the implicit conversion sequence is a user-defined
|
| 104 |
+
conversion sequence whose second standard conversion sequence is an
|
| 105 |
identity conversion.
|
| 106 |
|
| 107 |
If multiple constructors are viable but none is better than the others,
|
| 108 |
the implicit conversion sequence is the ambiguous conversion sequence.
|
| 109 |
User-defined conversions are allowed for conversion of the initializer
|
|
|
|
| 115 |
``` cpp
|
| 116 |
struct A {
|
| 117 |
A(std::initializer_list<int>);
|
| 118 |
};
|
| 119 |
void f(A);
|
| 120 |
+
f( {'a', 'b'} ); // OK, f(A(std::initializer_list<int>)) user-defined conversion
|
| 121 |
|
| 122 |
struct B {
|
| 123 |
B(int, double);
|
| 124 |
};
|
| 125 |
void g(B);
|
| 126 |
+
g( {'a', 'b'} ); // OK, g(B(int, double)) user-defined conversion
|
| 127 |
g( {1.0, 1.0} ); // error: narrowing
|
| 128 |
|
| 129 |
void f(B);
|
| 130 |
f( {'a', 'b'} ); // error: ambiguous f(A) or f(B)
|
| 131 |
|
| 132 |
struct C {
|
| 133 |
C(std::string);
|
| 134 |
};
|
| 135 |
void h(C);
|
| 136 |
+
h({"foo"}); // OK, h(C(std::string("foo")))
|
| 137 |
|
| 138 |
struct D {
|
| 139 |
D(A, C);
|
| 140 |
};
|
| 141 |
void i(D);
|
| 142 |
+
i({ {1,2}, {"bar"} }); // OK, i(D(A(std::initializer_list<int>{1,2\), C(std::string("bar"))))}
|
| 143 |
```
|
| 144 |
|
| 145 |
— *end example*]
|
| 146 |
|
| 147 |
Otherwise, if the parameter has an aggregate type which can be
|
| 148 |
initialized from the initializer list according to the rules for
|
| 149 |
aggregate initialization [[dcl.init.aggr]], the implicit conversion
|
| 150 |
+
sequence is a user-defined conversion sequence whose second standard
|
| 151 |
+
conversion sequence is an identity conversion.
|
| 152 |
|
| 153 |
[*Example 9*:
|
| 154 |
|
| 155 |
``` cpp
|
| 156 |
struct A {
|
| 157 |
int m1;
|
| 158 |
double m2;
|
| 159 |
};
|
| 160 |
|
| 161 |
void f(A);
|
| 162 |
+
f( {'a', 'b'} ); // OK, f(A(int,double)) user-defined conversion
|
| 163 |
f( {1.0} ); // error: narrowing
|
| 164 |
```
|
| 165 |
|
| 166 |
— *end example*]
|
| 167 |
|
| 168 |
Otherwise, if the parameter is a reference, see [[over.ics.ref]].
|
| 169 |
|
| 170 |
+
[*Note 11*: The rules in this subclause will apply for initializing the
|
| 171 |
underlying temporary for the reference. — *end note*]
|
| 172 |
|
| 173 |
[*Example 10*:
|
| 174 |
|
| 175 |
``` cpp
|
|
|
|
| 177 |
int m1;
|
| 178 |
double m2;
|
| 179 |
};
|
| 180 |
|
| 181 |
void f(const A&);
|
| 182 |
+
f( {'a', 'b'} ); // OK, f(A(int,double)) user-defined conversion
|
| 183 |
f( {1.0} ); // error: narrowing
|
| 184 |
|
| 185 |
void g(const double &);
|
| 186 |
g({1}); // same conversion as int to double
|
| 187 |
```
|
|
|
|
| 194 |
initializer list, the implicit conversion sequence is the one required
|
| 195 |
to convert the element to the parameter type;
|
| 196 |
\[*Example 11*:
|
| 197 |
``` cpp
|
| 198 |
void f(int);
|
| 199 |
+
f( {'a'} ); // OK, same conversion as char to int
|
| 200 |
f( {1.0} ); // error: narrowing
|
| 201 |
```
|
| 202 |
|
| 203 |
— *end example*]
|
| 204 |
- if the initializer list has no elements, the implicit conversion
|
| 205 |
sequence is the identity conversion.
|
| 206 |
\[*Example 12*:
|
| 207 |
``` cpp
|
| 208 |
void f(int);
|
| 209 |
+
f( { } ); // OK, identity conversion
|
| 210 |
```
|
| 211 |
|
| 212 |
— *end example*]
|
| 213 |
|
| 214 |
In all cases other than those enumerated above, no conversion is
|