From Jason Turner

[over.ics.list]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpzkqteq60/{from.md → to.md} +66 -26
tmp/tmpzkqteq60/{from.md → to.md} RENAMED
@@ -2,18 +2,30 @@
2
 
3
  When an argument is an initializer list ([[dcl.init.list]]), it is not
4
  an expression and special rules apply for converting it to a parameter
5
  type.
6
 
7
- If the parameter type is `std::initializer_list<X>` and all the elements
8
- of the initializer list can be implicitly converted to `X`, the implicit
9
- conversion sequence is the worst conversion necessary to convert an
10
- element of the list to `X`, or if the initializer list has no elements,
11
- the identity conversion. This conversion can be a user-defined
 
 
 
 
 
 
 
 
 
 
12
  conversion even in the context of a call to an initializer-list
13
  constructor.
14
 
 
 
15
  ``` cpp
16
  void f(std::initializer_list<int>);
17
  f( {} ); // OK: f(initializer_list<int>) identity conversion
18
  f( {1,2,3} ); // OK: f(initializer_list<int>) identity conversion
19
  f( {'a','b'} ); // OK: f(initializer_list<int>) integral promotion
@@ -32,27 +44,38 @@ g({ "foo", "bar" }); // OK, uses #3
32
  typedef int IA[3];
33
  void h(const IA&);
34
  h({ 1, 2, 3 }); // OK: identity conversion
35
  ```
36
 
37
- Otherwise, if the parameter type is “array of `N` `X`”[^12], if the
38
- initializer list has exactly `N` elements or if it has fewer than `N`
39
- elements and `X` is default-constructible, and if all the elements of
40
- the initializer list can be implicitly converted to `X`, the implicit
41
- conversion sequence is the worst conversion necessary to convert an
42
- element of the list to `X`.
 
43
 
44
  Otherwise, if the parameter is a non-aggregate class `X` and overload
45
- resolution per  [[over.match.list]] chooses a single best constructor of
46
- `X` to perform the initialization of an object of type `X` from the
47
- argument initializer list, the implicit conversion sequence is a
48
- user-defined conversion sequence with the second standard conversion
49
- sequence an identity conversion. If multiple constructors are viable but
50
- none is better than the others, the implicit conversion sequence is the
51
- ambiguous conversion sequence. User-defined conversions are allowed for
52
- conversion of the initializer list elements to the constructor parameter
53
- types except as noted in  [[over.best.ics]].
 
 
 
 
 
 
 
 
 
 
54
 
55
  ``` cpp
56
  struct A {
57
  A(std::initializer_list<int>);
58
  };
@@ -80,16 +103,20 @@ struct D {
80
  };
81
  void i(D);
82
  i({ {1,2}, {"bar"} }); // OK: i(D(A(std::initializer_list<int>{1,2\), C(std::string("bar"))))}
83
  ```
84
 
 
 
85
  Otherwise, if the parameter has an aggregate type which can be
86
  initialized from the initializer list according to the rules for
87
  aggregate initialization ([[dcl.init.aggr]]), the implicit conversion
88
  sequence is a user-defined conversion sequence with the second standard
89
  conversion sequence an identity conversion.
90
 
 
 
91
  ``` cpp
92
  struct A {
93
  int m1;
94
  double m2;
95
  };
@@ -97,13 +124,18 @@ struct A {
97
  void f(A);
98
  f( {'a', 'b'} ); // OK: f(A(int,double)) user-defined conversion
99
  f( {1.0} ); // error: narrowing
100
  ```
101
 
102
- Otherwise, if the parameter is a reference, see  [[over.ics.ref]]. The
103
- rules in this section will apply for initializing the underlying
104
- temporary for the reference.
 
 
 
 
 
105
 
106
  ``` cpp
107
  struct A {
108
  int m1;
109
  double m2;
@@ -115,25 +147,33 @@ f( {1.0} ); // error: narrowing
115
 
116
  void g(const double &);
117
  g({1}); // same conversion as int to double
118
  ```
119
 
 
 
120
  Otherwise, if the parameter type is not a class:
121
 
122
- - if the initializer list has one element, the implicit conversion
123
- sequence is the one required to convert the element to the parameter
124
- type;
 
125
  ``` cpp
126
  void f(int);
127
  f( {'a'} ); // OK: same conversion as char to int
128
  f( {1.0} ); // error: narrowing
129
  ```
 
 
130
  - if the initializer list has no elements, the implicit conversion
131
  sequence is the identity conversion.
 
132
  ``` cpp
133
  void f(int);
134
  f( { } ); // OK: identity conversion
135
  ```
136
 
 
 
137
  In all cases other than those enumerated above, no conversion is
138
  possible.
139
 
 
2
 
3
  When an argument is an initializer list ([[dcl.init.list]]), it is not
4
  an expression and special rules apply for converting it to a parameter
5
  type.
6
 
7
+ If the parameter type is an aggregate class `X` and the initializer list
8
+ has a single element of type cv `U`, where `U` is `X` or a class derived
9
+ from `X`, the implicit conversion sequence is the one required to
10
+ convert the element to the parameter type.
11
+
12
+ Otherwise, if the parameter type is a character array [^11] and the
13
+ initializer list has a single element that is an appropriately-typed
14
+ string literal ([[dcl.init.string]]), the implicit conversion sequence
15
+ is the identity conversion.
16
+
17
+ Otherwise, if the parameter type is `std::initializer_list<X>` and all
18
+ the elements of the initializer list can be implicitly converted to `X`,
19
+ the implicit conversion sequence is the worst conversion necessary to
20
+ convert an element of the list to `X`, or if the initializer list has no
21
+ elements, the identity conversion. This conversion can be a user-defined
22
  conversion even in the context of a call to an initializer-list
23
  constructor.
24
 
25
+ [*Example 6*:
26
+
27
  ``` cpp
28
  void f(std::initializer_list<int>);
29
  f( {} ); // OK: f(initializer_list<int>) identity conversion
30
  f( {1,2,3} ); // OK: f(initializer_list<int>) identity conversion
31
  f( {'a','b'} ); // OK: f(initializer_list<int>) integral promotion
 
44
  typedef int IA[3];
45
  void h(const IA&);
46
  h({ 1, 2, 3 }); // OK: identity conversion
47
  ```
48
 
49
+ *end example*]
50
+
51
+ Otherwise, if the parameter type is “array of `N` `X`”, if there exists
52
+ an implicit conversion sequence for each element of the array from the
53
+ corresponding element of the initializer list (or from `{}` if there is
54
+ no such element), the implicit conversion sequence is the worst such
55
+ implicit conversion sequence.
56
 
57
  Otherwise, if the parameter is a non-aggregate class `X` and overload
58
+ resolution per  [[over.match.list]] chooses a single best constructor
59
+ `C` of `X` to perform the initialization of an object of type `X` from
60
+ the argument initializer list:
61
+
62
+ - If `C` is not an initializer-list constructor and the initializer list
63
+ has a single element of type cv `U`, where `U` is `X` or a class
64
+ derived from `X`, the implicit conversion sequence has Exact Match
65
+ rank if `U` is `X`, or Conversion rank if `U` is derived from `X`.
66
+ - Otherwise, the implicit conversion sequence is a user-defined
67
+ conversion sequence with the second standard conversion sequence an
68
+ identity conversion.
69
+
70
+ If multiple constructors are viable but none is better than the others,
71
+ the implicit conversion sequence is the ambiguous conversion sequence.
72
+ User-defined conversions are allowed for conversion of the initializer
73
+ list elements to the constructor parameter types except as noted in 
74
+ [[over.best.ics]].
75
+
76
+ [*Example 7*:
77
 
78
  ``` cpp
79
  struct A {
80
  A(std::initializer_list<int>);
81
  };
 
103
  };
104
  void i(D);
105
  i({ {1,2}, {"bar"} }); // OK: i(D(A(std::initializer_list<int>{1,2\), C(std::string("bar"))))}
106
  ```
107
 
108
+ — *end example*]
109
+
110
  Otherwise, if the parameter has an aggregate type which can be
111
  initialized from the initializer list according to the rules for
112
  aggregate initialization ([[dcl.init.aggr]]), the implicit conversion
113
  sequence is a user-defined conversion sequence with the second standard
114
  conversion sequence an identity conversion.
115
 
116
+ [*Example 8*:
117
+
118
  ``` cpp
119
  struct A {
120
  int m1;
121
  double m2;
122
  };
 
124
  void f(A);
125
  f( {'a', 'b'} ); // OK: f(A(int,double)) user-defined conversion
126
  f( {1.0} ); // error: narrowing
127
  ```
128
 
129
+ *end example*]
130
+
131
+ Otherwise, if the parameter is a reference, see  [[over.ics.ref]].
132
+
133
+ [*Note 8*: The rules in this section will apply for initializing the
134
+ underlying temporary for the reference. — *end note*]
135
+
136
+ [*Example 9*:
137
 
138
  ``` cpp
139
  struct A {
140
  int m1;
141
  double m2;
 
147
 
148
  void g(const double &);
149
  g({1}); // same conversion as int to double
150
  ```
151
 
152
+ — *end example*]
153
+
154
  Otherwise, if the parameter type is not a class:
155
 
156
+ - if the initializer list has one element that is not itself an
157
+ initializer list, the implicit conversion sequence is the one required
158
+ to convert the element to the parameter type;
159
+ \[*Example 10*:
160
  ``` cpp
161
  void f(int);
162
  f( {'a'} ); // OK: same conversion as char to int
163
  f( {1.0} ); // error: narrowing
164
  ```
165
+
166
+ — *end example*]
167
  - if the initializer list has no elements, the implicit conversion
168
  sequence is the identity conversion.
169
+ \[*Example 11*:
170
  ``` cpp
171
  void f(int);
172
  f( { } ); // OK: identity conversion
173
  ```
174
 
175
+ — *end example*]
176
+
177
  In all cases other than those enumerated above, no conversion is
178
  possible.
179