Topic: a fixed-size std::initializer_list
Author: "ma.kalbfuss via ISO C++ Standard - Future Proposals" <std-proposals@isocpp.org>
Date: Tue, 31 Oct 2017 11:05:29 -0700 (PDT)
Raw View
------=_Part_8871_134052216.1509473129517
Content-Type: multipart/alternative;
boundary="----=_Part_8872_510712270.1509473129519"
------=_Part_8872_510712270.1509473129519
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Hi Guys,
If we have a container type like...
=20
template <typename E, size_t S>
class Container
{
public:
template <typename... Args>
Container(Args&&... args)
: data(std::forward<Args>(args)...)
{ }
private:
E data[S];
};
We can initialize the container with
Container<int, 5> c{ 0, 1, 2, 3, 4, 5 };
But if we have a more complex element type like a class or struct we cannot=
write
Container<Element, 5> c{ { 1, "1" }, { 2, "2" }, { 3, "3" }, { 4, "4" }, { =
5, "5" } };
The compiler cannot deduce the type. We would have to write
Container<Element, 5> c{ Element{ 1, "1" }, Element{ 2, "2" }, Element{ 3, =
"3" }, Element{ 4, "4" }, Element{ 5, "5" } };
That is not what we want. We could use std::initializer_list, but the initi=
alizer list could be of different size. We would have to add a runtime chec=
k.
If initializer_list would allow an optional size parameter. The container c=
ode could look like the following
template <typename E, size_t N>
class Container
{
public:
Container(std::initializer_list<E, N> il)
{
std::copy_n(il.begin(), N, data);
}
private:
E data[N];
};
Now we could write
Container<Element, 5> c{ { 1, "1" }, { 2, "2" }, { 3, "3" }, { 4, "4" }, { =
5, "5" } };
If the number of elements differ the compiler can detect the error:
Container<Element, 5> c{ { 1, "1" }, { 2, "2" }, { 3, "3" }, { 4, "4" }, { =
5, "5" }, { 6, "6"} }; // error: too much elements
In combination with deduction guides, allowing a partial deduction, it woul=
d be possible to write
Container<Element> c{ { 1, "1" }, { 2, "2" }, { 3, "3" }, { 4, "4" }, { 5, =
"5" } };
Kind Regards,
Martin Kalbfu=C3=9F
--=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/0649c0ae-0e27-4fd5-8c31-3f418989e581%40isocpp.or=
g.
------=_Part_8872_510712270.1509473129519
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div><div style=3D"overflow: auto"><div style=3D"max-heigh=
t: 10000px;"><div dir=3D"ltr"><pre>Hi Guys,
If we have a container type like...<br>=C2=A0<div style=3D"background-color=
:rgb(250,250,250);border-color:rgb(187,187,187);border-style:solid;border-w=
idth:1px"><code><div><span style=3D"color:#008">template</span><span style=
=3D"color:#000"> </span><span style=3D"color:#660"><</span><span style=
=3D"color:#008">typename</span><span style=3D"color:#000"> E</span><span st=
yle=3D"color:#660">,</span><span style=3D"color:#000"> size_t S</span><span=
style=3D"color:#660">></span><span style=3D"color:#000"><br></span><spa=
n style=3D"color:#008">class</span><span style=3D"color:#000"> </span><span=
style=3D"color:#606">Container</span><span style=3D"color:#000"><br></span=
><span style=3D"color:#660">{</span><span style=3D"color:#000"><br><br>=C2=
=A0 </span><span style=3D"color:#008">public</span><span style=3D"color:#66=
0">:</span><span style=3D"color:#000"><br><br>=C2=A0 =C2=A0 </span><span st=
yle=3D"color:#008">template</span><span style=3D"color:#000"> </span><span =
style=3D"color:#660"><</span><span style=3D"color:#008">typename</span><=
span style=3D"color:#660">...</span><span style=3D"color:#000"> </span><spa=
n style=3D"color:#606">Args</span><span style=3D"color:#660">></span><sp=
an style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#606"=
>Container</span><span style=3D"color:#660">(</span><span style=3D"color:#6=
06">Args</span><span style=3D"color:#660">&&...</span><span style=
=3D"color:#000"> args</span><span style=3D"color:#660">)</span><span style=
=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color=
:#660">:</span><span style=3D"color:#000"> data</span><span style=3D"color:=
#660">(</span><span style=3D"color:#000">std</span><span style=3D"color:#66=
0">::</span><span style=3D"color:#000">forward</span><span style=3D"color:#=
660"><</span><span style=3D"color:#606">Args</span><span style=3D"color:=
#660">>(</span><span style=3D"color:#000">args</span><span style=3D"colo=
r:#660">).<wbr>..)</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </spa=
n><span style=3D"color:#660">{</span><span style=3D"color:#000"> </span><sp=
an style=3D"color:#660">}</span><span style=3D"color:#000"><br><br>=C2=A0 <=
/span><span style=3D"color:#008">private</span><span style=3D"color:#660">:=
</span><span style=3D"color:#000"><br><br>=C2=A0 =C2=A0 E data</span><span =
style=3D"color:#660">[</span><span style=3D"color:#000">S</span><span style=
=3D"color:#660">];</span><span style=3D"color:#000"><br><br></span><span st=
yle=3D"color:#660">};</span></div></code></div>
We can initialize the container with
<div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,18=
7);border-style:solid;border-width:1px"><code><div><span style=3D"color:#60=
6">Container</span><span style=3D"color:#660"><</span><span style=3D"col=
or:#008">int</span><span style=3D"color:#660">,</span><span style=3D"color:=
#000"> </span><span style=3D"color:#066">5</span><span style=3D"color:#660"=
>></span><span style=3D"color:#000"> c</span><span style=3D"color:#660">=
{</span><span style=3D"color:#000"> </span><span style=3D"color:#066">0</sp=
an><span style=3D"color:#660">,</span><span style=3D"color:#000"> </span><s=
pan style=3D"color:#066">1</span><span style=3D"color:#660">,</span><span s=
tyle=3D"color:#000"> </span><span style=3D"color:#066">2</span><span style=
=3D"color:#660">,</span><span style=3D"color:#000"> </span><span style=3D"c=
olor:#066">3</span><span style=3D"color:#660">,</span><span style=3D"color:=
#000"> </span><span style=3D"color:#066">4</span><span style=3D"color:#660"=
>,</span><span style=3D"color:#000"> </span><span style=3D"color:#066">5</s=
pan><span style=3D"color:#000"> </span><span style=3D"color:#660">};</span>=
</div></code></div>
But if we have a more complex element type like a class or struct we cannot=
write
<div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,18=
7);border-style:solid;border-width:1px"><code><div><span style=3D"color:#60=
6">Container</span><span style=3D"color:#660"><</span><span style=3D"col=
or:#606">Element</span><span style=3D"color:#660">,</span><span style=3D"co=
lor:#000"> </span><span style=3D"color:#066">5</span><span style=3D"color:#=
660">></span><span style=3D"color:#000"> c</span><span style=3D"color:#6=
60">{</span><span style=3D"color:#000"> </span><span style=3D"color:#660">{=
</span><span style=3D"color:#000"> </span><span style=3D"color:#066">1</spa=
n><span style=3D"color:#660">,</span><span style=3D"color:#000"> </span><sp=
an style=3D"color:#080">"1"</span><span style=3D"color:#000"> </s=
pan><span style=3D"color:#660">},</span><span style=3D"color:#000"> </span>=
<span style=3D"color:#660">{</span><span style=3D"color:#000"> </span><span=
style=3D"color:#066">2</span><span style=3D"color:#660">,</span><span styl=
e=3D"color:#000"> </span><span style=3D"color:#080">"2"</span><sp=
an style=3D"color:#000"> </span><span style=3D"color:#660">},</span><span s=
tyle=3D"color:#000"> </span><span style=3D"color:#660">{</span><span style=
=3D"color:#000"> </span><span style=3D"color:#066">3</span><span style=3D"c=
olor:#660">,</span><span style=3D"color:#000"> </span><span style=3D"color:=
#080">"3"</span><span style=3D"color:#000"> </span><span style=3D=
"color:#660">},</span><span style=3D"color:#000"> </span><span style=3D"col=
or:#660">{</span><span style=3D"color:#000"> </span><span style=3D"color:#0=
66">4</span><span style=3D"color:#660">,</span><span style=3D"color:#000"> =
</span><span style=3D"color:#080">"4"</span><span style=3D"color:=
#000"> </span><span style=3D"color:#660">},</span><span style=3D"color:#000=
"> </span><span style=3D"color:#660">{</span><span style=3D"color:#000"> </=
span><span style=3D"color:#066">5</span><span style=3D"color:#660">,</span>=
<span style=3D"color:#000"> </span><span style=3D"color:#080">"5"=
</span><span style=3D"color:#000"> </span><span style=3D"color:#660">}</spa=
n><span style=3D"color:#000"> </span><span style=3D"color:#660">};</span></=
div></code></div>
The compiler cannot deduce the type. We would have to write
<div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,18=
7);border-style:solid;border-width:1px"><code><div><span style=3D"color:#60=
6">Container</span><span style=3D"color:#660"><</span><span style=3D"col=
or:#606">Element</span><span style=3D"color:#660">,</span><span style=3D"co=
lor:#000"> </span><span style=3D"color:#066">5</span><span style=3D"color:#=
660">></span><span style=3D"color:#000"> c</span><span style=3D"color:#6=
60">{</span><span style=3D"color:#000"> </span><span style=3D"color:#606">E=
lement</span><span style=3D"color:#660">{</span><span style=3D"color:#000">=
</span><span style=3D"color:#066">1</span><span style=3D"color:#660">,</sp=
an><span style=3D"color:#000"> </span><span style=3D"color:#080">"1&qu=
ot;</span><span style=3D"color:#000"> </span><span style=3D"color:#660">},<=
/span><span style=3D"color:#000"> </span><span style=3D"color:#606">Element=
</span><span style=3D"color:#660">{</span><span style=3D"color:#000"> </spa=
n><span style=3D"color:#066">2</span><span style=3D"color:#660">,</span><sp=
an style=3D"color:#000"> </span><span style=3D"color:#080">"2"</s=
pan><span style=3D"color:#000"> </span><span style=3D"color:#660">},</span>=
<span style=3D"color:#000"> </span><span style=3D"color:#606">Element</span=
><span style=3D"color:#660">{</span><span style=3D"color:#000"> </span><spa=
n style=3D"color:#066">3</span><span style=3D"color:#660">,</span><span sty=
le=3D"color:#000"> </span><span style=3D"color:#080">"3"</span><s=
pan style=3D"color:#000"> </span><span style=3D"color:#660">},</span><span =
style=3D"color:#000"> </span><span style=3D"color:#606">Element</span><span=
style=3D"color:#660">{</span><span style=3D"color:#000"> </span><span styl=
e=3D"color:#066">4</span><span style=3D"color:#660">,</span><span style=3D"=
color:#000"> </span><span style=3D"color:#080">"4"</span><span st=
yle=3D"color:#000"> </span><span style=3D"color:#660">},</span><span style=
=3D"color:#000"> </span><span style=3D"color:#606">Element</span><span styl=
e=3D"color:#660">{</span><span style=3D"color:#000"> </span><span style=3D"=
color:#066">5</span><span style=3D"color:#660">,</span><span style=3D"color=
:#000"> </span><span style=3D"color:#080">"5"</span><span style=
=3D"color:#000"> </span><span style=3D"color:#660">}</span><span style=3D"c=
olor:#000"> </span><span style=3D"color:#660">};</span></div></code></div>
That is not what we want. We could use std::initializer_list, but the initi=
alizer list could be of different size. We would have to add a runtime chec=
k.
If initializer_list would allow an optional size parameter. The container c=
ode could look like the following
<div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,18=
7);border-style:solid;border-width:1px"><code><div><span style=3D"color:#00=
8">template</span><span style=3D"color:#000"> </span><span style=3D"color:#=
660"><</span><span style=3D"color:#008">typename</span><span style=3D"co=
lor:#000"> E</span><span style=3D"color:#660">,</span><span style=3D"color:=
#000"> size_t N</span><span style=3D"color:#660">></span><span style=3D"=
color:#000"><br></span><span style=3D"color:#008">class</span><span style=
=3D"color:#000"> </span><span style=3D"color:#606">Container</span><span st=
yle=3D"color:#000"><br></span><span style=3D"color:#660">{</span><span styl=
e=3D"color:#000"><br><br>=C2=A0 </span><span style=3D"color:#008">public</s=
pan><span style=3D"color:#660">:</span><span style=3D"color:#000"><br><br>=
=C2=A0 =C2=A0 </span><span style=3D"color:#606">Container</span><span style=
=3D"color:#660">(</span><span style=3D"color:#000">std</span><span style=3D=
"color:#660">::</span><span style=3D"color:#000">initializer_<wbr>list</spa=
n><span style=3D"color:#660"><</span><span style=3D"color:#000">E</span>=
<span style=3D"color:#660">,</span><span style=3D"color:#000"> N</span><spa=
n style=3D"color:#660">></span><span style=3D"color:#000"> il</span><spa=
n style=3D"color:#660">)</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0=
</span><span style=3D"color:#660">{</span><span style=3D"color:#000"><br>=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 std</span><span style=3D"color:#660">::</span><=
span style=3D"color:#000">copy_n</span><span style=3D"color:#660">(</span><=
span style=3D"color:#000">il</span><span style=3D"color:#660">.</span><span=
style=3D"color:#008">begin</span><span style=3D"color:#660">(),</span><spa=
n style=3D"color:#000"> N</span><span style=3D"color:#660">,</span><span st=
yle=3D"color:#000"> data</span><span style=3D"color:#660">);</span><span st=
yle=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#660">}</s=
pan><span style=3D"color:#000"><br><br>=C2=A0 </span><span style=3D"color:#=
008">private</span><span style=3D"color:#660">:</span><span style=3D"color:=
#000"><br><br>=C2=A0 =C2=A0 E data</span><span style=3D"color:#660">[</span=
><span style=3D"color:#000">N</span><span style=3D"color:#660">];</span><sp=
an style=3D"color:#000"><br><br></span><span style=3D"color:#660">};</span>=
</div></code></div><br>Now we could write
<div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,18=
7);border-style:solid;border-width:1px"><code><div><span style=3D"color:#60=
6">Container</span><span style=3D"color:#660"><</span><span style=3D"col=
or:#606">Element</span><span style=3D"color:#660">,</span><span style=3D"co=
lor:#000"> </span><span style=3D"color:#066">5</span><span style=3D"color:#=
660">></span><span style=3D"color:#000"> c</span><span style=3D"color:#6=
60">{</span><span style=3D"color:#000"> </span><span style=3D"color:#660">{=
</span><span style=3D"color:#000"> </span><span style=3D"color:#066">1</spa=
n><span style=3D"color:#660">,</span><span style=3D"color:#000"> </span><sp=
an style=3D"color:#080">"1"</span><span style=3D"color:#000"> </s=
pan><span style=3D"color:#660">},</span><span style=3D"color:#000"> </span>=
<span style=3D"color:#660">{</span><span style=3D"color:#000"> </span><span=
style=3D"color:#066">2</span><span style=3D"color:#660">,</span><span styl=
e=3D"color:#000"> </span><span style=3D"color:#080">"2"</span><sp=
an style=3D"color:#000"> </span><span style=3D"color:#660">},</span><span s=
tyle=3D"color:#000"> </span><span style=3D"color:#660">{</span><span style=
=3D"color:#000"> </span><span style=3D"color:#066">3</span><span style=3D"c=
olor:#660">,</span><span style=3D"color:#000"> </span><span style=3D"color:=
#080">"3"</span><span style=3D"color:#000"> </span><span style=3D=
"color:#660">},</span><span style=3D"color:#000"> </span><span style=3D"col=
or:#660">{</span><span style=3D"color:#000"> </span><span style=3D"color:#0=
66">4</span><span style=3D"color:#660">,</span><span style=3D"color:#000"> =
</span><span style=3D"color:#080">"4"</span><span style=3D"color:=
#000"> </span><span style=3D"color:#660">},</span><span style=3D"color:#000=
"> </span><span style=3D"color:#660">{</span><span style=3D"color:#000"> </=
span><span style=3D"color:#066">5</span><span style=3D"color:#660">,</span>=
<span style=3D"color:#000"> </span><span style=3D"color:#080">"5"=
</span><span style=3D"color:#000"> </span><span style=3D"color:#660">}</spa=
n><span style=3D"color:#000"> </span><span style=3D"color:#660">};</span></=
div></code></div><br>If the number of elements differ the compiler can dete=
ct the error:
<div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,18=
7);border-style:solid;border-width:1px"><code><div><span style=3D"color:#60=
6">Container</span><span style=3D"color:#660"><</span><span style=3D"col=
or:#606">Element</span><span style=3D"color:#660">,</span><span style=3D"co=
lor:#000"> </span><span style=3D"color:#066">5</span><span style=3D"color:#=
660">></span><span style=3D"color:#000"> c</span><span style=3D"color:#6=
60">{</span><span style=3D"color:#000"> </span><span style=3D"color:#660">{=
</span><span style=3D"color:#000"> </span><span style=3D"color:#066">1</spa=
n><span style=3D"color:#660">,</span><span style=3D"color:#000"> </span><sp=
an style=3D"color:#080">"1"</span><span style=3D"color:#000"> </s=
pan><span style=3D"color:#660">},</span><span style=3D"color:#000"> </span>=
<span style=3D"color:#660">{</span><span style=3D"color:#000"> </span><span=
style=3D"color:#066">2</span><span style=3D"color:#660">,</span><span styl=
e=3D"color:#000"> </span><span style=3D"color:#080">"2"</span><sp=
an style=3D"color:#000"> </span><span style=3D"color:#660">},</span><span s=
tyle=3D"color:#000"> </span><span style=3D"color:#660">{</span><span style=
=3D"color:#000"> </span><span style=3D"color:#066">3</span><span style=3D"c=
olor:#660">,</span><span style=3D"color:#000"> </span><span style=3D"color:=
#080">"3"</span><span style=3D"color:#000"> </span><span style=3D=
"color:#660">},</span><span style=3D"color:#000"> </span><span style=3D"col=
or:#660">{</span><span style=3D"color:#000"> </span><span style=3D"color:#0=
66">4</span><span style=3D"color:#660">,</span><span style=3D"color:#000"> =
</span><span style=3D"color:#080">"4"</span><span style=3D"color:=
#000"> </span><span style=3D"color:#660">},</span><span style=3D"color:#000=
"> </span><span style=3D"color:#660">{</span><span style=3D"color:#000"> </=
span><span style=3D"color:#066">5</span><span style=3D"color:#660">,</span>=
<span style=3D"color:#000"> </span><span style=3D"color:#080">"5"=
</span><span style=3D"color:#000"> </span><span style=3D"color:#660">},</sp=
an><span style=3D"color:#000"> </span><span style=3D"color:#660">{</span><s=
pan style=3D"color:#000"> </span><span style=3D"color:#066">6</span><span s=
tyle=3D"color:#660">,</span><span style=3D"color:#000"> </span><span style=
=3D"color:#080">"6"</span><span style=3D"color:#660">}</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#660">};</span><span st=
yle=3D"color:#000"> </span><span style=3D"color:#800">// error: too much el=
ements</span></div></code></div>
In combination with deduction guides, allowing a partial deduction, it woul=
d be possible to write
<div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,18=
7);border-style:solid;border-width:1px"><code><div><span style=3D"color:#60=
6">Container</span><span style=3D"color:#660"><</span><span style=3D"col=
or:#606">Element</span><span style=3D"color:#660">></span><span style=3D=
"color:#000"> c</span><span style=3D"color:#660">{</span><span style=3D"col=
or:#000"> </span><span style=3D"color:#660">{</span><span style=3D"color:#0=
00"> </span><span style=3D"color:#066">1</span><span style=3D"color:#660">,=
</span><span style=3D"color:#000"> </span><span style=3D"color:#080">"=
1"</span><span style=3D"color:#000"> </span><span style=3D"color:#660"=
>},</span><span style=3D"color:#000"> </span><span style=3D"color:#660">{</=
span><span style=3D"color:#000"> </span><span style=3D"color:#066">2</span>=
<span style=3D"color:#660">,</span><span style=3D"color:#000"> </span><span=
style=3D"color:#080">"2"</span><span style=3D"color:#000"> </spa=
n><span style=3D"color:#660">},</span><span style=3D"color:#000"> </span><s=
pan style=3D"color:#660">{</span><span style=3D"color:#000"> </span><span s=
tyle=3D"color:#066">3</span><span style=3D"color:#660">,</span><span style=
=3D"color:#000"> </span><span style=3D"color:#080">"3"</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#660">},</span><span st=
yle=3D"color:#000"> </span><span style=3D"color:#660">{</span><span style=
=3D"color:#000"> </span><span style=3D"color:#066">4</span><span style=3D"c=
olor:#660">,</span><span style=3D"color:#000"> </span><span style=3D"color:=
#080">"4"</span><span style=3D"color:#000"> </span><span style=3D=
"color:#660">},</span><span style=3D"color:#000"> </span><span style=3D"col=
or:#660">{</span><span style=3D"color:#000"> </span><span style=3D"color:#0=
66">5</span><span style=3D"color:#660">,</span><span style=3D"color:#000"> =
</span><span style=3D"color:#080">"5"</span><span style=3D"color:=
#000"> </span><span style=3D"color:#660">}</span><span style=3D"color:#000"=
> </span><span style=3D"color:#660">};</span></div></code></div>
Kind Regards,
Martin Kalbfu=C3=9F
</pre></div></div></div></div> </div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/0649c0ae-0e27-4fd5-8c31-3f418989e581%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/0649c0ae-0e27-4fd5-8c31-3f418989e581=
%40isocpp.org</a>.<br />
------=_Part_8872_510712270.1509473129519--
------=_Part_8871_134052216.1509473129517--
.
Author: Richard Smith <richard@metafoo.co.uk>
Date: Tue, 31 Oct 2017 11:55:40 -0700
Raw View
--001a113535945c4a2f055cdc4e86
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
On 31 October 2017 at 11:05, ma.kalbfuss via ISO C++ Standard - Future
Proposals <std-proposals@isocpp.org> wrote:
> Hi Guys,
>
> If we have a container type like...
>
> template <typename E, size_t S>
> class Container
> {
>
> public:
>
> template <typename... Args>
> Container(Args&&... args)
> : data(std::forward<Args>(args)...)
> { }
>
> private:
>
> E data[S];
>
> };
>
> We can initialize the container with
>
> Container<int, 5> c{ 0, 1, 2, 3, 4, 5 };
>
> But if we have a more complex element type like a class or struct we cann=
ot write
>
> Container<Element, 5> c{ { 1, "1" }, { 2, "2" }, { 3, "3" }, { 4, "4" }, =
{ 5, "5" } };
>
> The compiler cannot deduce the type. We would have to write
>
> Container<Element, 5> c{ Element{ 1, "1" }, Element{ 2, "2" }, Element{ 3=
, "3" }, Element{ 4, "4" }, Element{ 5, "5" } };
>
> That is not what we want. We could use std::initializer_list, but the ini=
tializer list could be of different size. We would have to add a runtime ch=
eck.
> If initializer_list would allow an optional size parameter. The container=
code could look like the following
>
> template <typename E, size_t N>
> class Container
> {
>
> public:
>
> Container(std::initializer_list<E, N> il)
>
>
Use "E (&&il)[N]".
This is strictly better than the initializer_list form for this use case,
since it also permits you to move from the initializer.
>
> {
> std::copy_n(il.begin(), N, data);
> }
>
> private:
>
> E data[N];
>
> };
>
> Now we could write
>
> Container<Element, 5> c{ { 1, "1" }, { 2, "2" }, { 3, "3" }, { 4, "4" }, =
{ 5, "5" } };
>
> If the number of elements differ the compiler can detect the error:
>
> Container<Element, 5> c{ { 1, "1" }, { 2, "2" }, { 3, "3" }, { 4, "4" }, =
{ 5, "5" }, { 6, "6"} }; // error: too much elements
>
> In combination with deduction guides, allowing a partial deduction, it wo=
uld be possible to write
>
> Container<Element> c{ { 1, "1" }, { 2, "2" }, { 3, "3" }, { 4, "4" }, { 5=
, "5" } };
>
> Kind Regards,
> Martin Kalbfu=C3=9F
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to std-proposals+unsubscribe@isocpp.org.
> To post to this group, send email to std-proposals@isocpp.org.
> To view this discussion on the web visit https://groups.google.com/a/
> isocpp.org/d/msgid/std-proposals/0649c0ae-0e27-4fd5-
> 8c31-3f418989e581%40isocpp.org
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/0649c0ae-0e=
27-4fd5-8c31-3f418989e581%40isocpp.org?utm_medium=3Demail&utm_source=3Dfoot=
er>
> .
>
--=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/CAOfiQqkC%3D8EtYLGyB4rzZNU0fbM_rD60iW3f%2B%2BOTe=
Mn%3D4-gT3w%40mail.gmail.com.
--001a113535945c4a2f055cdc4e86
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On 3=
1 October 2017 at 11:05, ma.kalbfuss via ISO C++ Standard - Future Proposal=
s <span dir=3D"ltr"><<a href=3D"mailto:std-proposals@isocpp.org" target=
=3D"_blank">std-proposals@isocpp.org</a>></span> wrote:<br><blockquote c=
lass=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;=
padding-left:1ex"><div dir=3D"ltr"><div><div style=3D"overflow:auto"><div s=
tyle=3D"max-height:10000px"><div dir=3D"ltr"><pre>Hi Guys,
If we have a container type like...<br>=C2=A0<div style=3D"background-color=
:rgb(250,250,250);border-color:rgb(187,187,187);border-style:solid;border-w=
idth:1px"><code><div><span style=3D"color:#008">template</span><span style=
=3D"color:#000"> </span><span style=3D"color:#660"><</span><span style=
=3D"color:#008">typename</span><span style=3D"color:#000"> E</span><span st=
yle=3D"color:#660">,</span><span style=3D"color:#000"> size_t S</span><span=
style=3D"color:#660">></span><span style=3D"color:#000"><br></span><spa=
n style=3D"color:#008">class</span><span style=3D"color:#000"> </span><span=
style=3D"color:#606">Container</span><span style=3D"color:#000"><br></span=
><span style=3D"color:#660">{</span><span style=3D"color:#000"><br><br>=C2=
=A0 </span><span style=3D"color:#008">public</span><span style=3D"color:#66=
0">:</span><span style=3D"color:#000"><br><br>=C2=A0 =C2=A0 </span><span st=
yle=3D"color:#008">template</span><span style=3D"color:#000"> </span><span =
style=3D"color:#660"><</span><span style=3D"color:#008">typename</span><=
span style=3D"color:#660">...</span><span style=3D"color:#000"> </span><spa=
n style=3D"color:#606">Args</span><span style=3D"color:#660">></span><sp=
an style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#606"=
>Container</span><span style=3D"color:#660">(</span><span style=3D"color:#6=
06">Args</span><span style=3D"color:#660">&&...</span><span style=
=3D"color:#000"> args</span><span style=3D"color:#660">)</span><span style=
=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color=
:#660">:</span><span style=3D"color:#000"> data</span><span style=3D"color:=
#660">(</span><span style=3D"color:#000">std</span><span style=3D"color:#66=
0">::</span><span style=3D"color:#000">forward</span><span style=3D"color:#=
660"><</span><span style=3D"color:#606">Args</span><span style=3D"color:=
#660">>(</span><span style=3D"color:#000">args</span><span style=3D"colo=
r:#660">).<wbr>..)</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </spa=
n><span style=3D"color:#660">{</span><span style=3D"color:#000"> </span><sp=
an style=3D"color:#660">}</span><span style=3D"color:#000"><br><br>=C2=A0 <=
/span><span style=3D"color:#008">private</span><span style=3D"color:#660">:=
</span><span style=3D"color:#000"><br><br>=C2=A0 =C2=A0 E data</span><span =
style=3D"color:#660">[</span><span style=3D"color:#000">S</span><span style=
=3D"color:#660">];</span><span style=3D"color:#000"><br><br></span><span st=
yle=3D"color:#660">};</span></div></code></div>
We can initialize the container with
<div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,18=
7);border-style:solid;border-width:1px"><code><div><span style=3D"color:#60=
6">Container</span><span style=3D"color:#660"><</span><span style=3D"col=
or:#008">int</span><span style=3D"color:#660">,</span><span style=3D"color:=
#000"> </span><span style=3D"color:#066">5</span><span style=3D"color:#660"=
>></span><span style=3D"color:#000"> c</span><span style=3D"color:#660">=
{</span><span style=3D"color:#000"> </span><span style=3D"color:#066">0</sp=
an><span style=3D"color:#660">,</span><span style=3D"color:#000"> </span><s=
pan style=3D"color:#066">1</span><span style=3D"color:#660">,</span><span s=
tyle=3D"color:#000"> </span><span style=3D"color:#066">2</span><span style=
=3D"color:#660">,</span><span style=3D"color:#000"> </span><span style=3D"c=
olor:#066">3</span><span style=3D"color:#660">,</span><span style=3D"color:=
#000"> </span><span style=3D"color:#066">4</span><span style=3D"color:#660"=
>,</span><span style=3D"color:#000"> </span><span style=3D"color:#066">5</s=
pan><span style=3D"color:#000"> </span><span style=3D"color:#660">};</span>=
</div></code></div>
But if we have a more complex element type like a class or struct we cannot=
write
<div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,18=
7);border-style:solid;border-width:1px"><code><div><span style=3D"color:#60=
6">Container</span><span style=3D"color:#660"><</span><span style=3D"col=
or:#606">Element</span><span style=3D"color:#660">,</span><span style=3D"co=
lor:#000"> </span><span style=3D"color:#066">5</span><span style=3D"color:#=
660">></span><span style=3D"color:#000"> c</span><span style=3D"color:#6=
60">{</span><span style=3D"color:#000"> </span><span style=3D"color:#660">{=
</span><span style=3D"color:#000"> </span><span style=3D"color:#066">1</spa=
n><span style=3D"color:#660">,</span><span style=3D"color:#000"> </span><sp=
an style=3D"color:#080">"1"</span><span style=3D"color:#000"> </s=
pan><span style=3D"color:#660">},</span><span style=3D"color:#000"> </span>=
<span style=3D"color:#660">{</span><span style=3D"color:#000"> </span><span=
style=3D"color:#066">2</span><span style=3D"color:#660">,</span><span styl=
e=3D"color:#000"> </span><span style=3D"color:#080">"2"</span><sp=
an style=3D"color:#000"> </span><span style=3D"color:#660">},</span><span s=
tyle=3D"color:#000"> </span><span style=3D"color:#660">{</span><span style=
=3D"color:#000"> </span><span style=3D"color:#066">3</span><span style=3D"c=
olor:#660">,</span><span style=3D"color:#000"> </span><span style=3D"color:=
#080">"3"</span><span style=3D"color:#000"> </span><span style=3D=
"color:#660">},</span><span style=3D"color:#000"> </span><span style=3D"col=
or:#660">{</span><span style=3D"color:#000"> </span><span style=3D"color:#0=
66">4</span><span style=3D"color:#660">,</span><span style=3D"color:#000"> =
</span><span style=3D"color:#080">"4"</span><span style=3D"color:=
#000"> </span><span style=3D"color:#660">},</span><span style=3D"color:#000=
"> </span><span style=3D"color:#660">{</span><span style=3D"color:#000"> </=
span><span style=3D"color:#066">5</span><span style=3D"color:#660">,</span>=
<span style=3D"color:#000"> </span><span style=3D"color:#080">"5"=
</span><span style=3D"color:#000"> </span><span style=3D"color:#660">}</spa=
n><span style=3D"color:#000"> </span><span style=3D"color:#660">};</span></=
div></code></div>
The compiler cannot deduce the type. We would have to write
<div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,18=
7);border-style:solid;border-width:1px"><code><div><span style=3D"color:#60=
6">Container</span><span style=3D"color:#660"><</span><span style=3D"col=
or:#606">Element</span><span style=3D"color:#660">,</span><span style=3D"co=
lor:#000"> </span><span style=3D"color:#066">5</span><span style=3D"color:#=
660">></span><span style=3D"color:#000"> c</span><span style=3D"color:#6=
60">{</span><span style=3D"color:#000"> </span><span style=3D"color:#606">E=
lement</span><span style=3D"color:#660">{</span><span style=3D"color:#000">=
</span><span style=3D"color:#066">1</span><span style=3D"color:#660">,</sp=
an><span style=3D"color:#000"> </span><span style=3D"color:#080">"1&qu=
ot;</span><span style=3D"color:#000"> </span><span style=3D"color:#660">},<=
/span><span style=3D"color:#000"> </span><span style=3D"color:#606">Element=
</span><span style=3D"color:#660">{</span><span style=3D"color:#000"> </spa=
n><span style=3D"color:#066">2</span><span style=3D"color:#660">,</span><sp=
an style=3D"color:#000"> </span><span style=3D"color:#080">"2"</s=
pan><span style=3D"color:#000"> </span><span style=3D"color:#660">},</span>=
<span style=3D"color:#000"> </span><span style=3D"color:#606">Element</span=
><span style=3D"color:#660">{</span><span style=3D"color:#000"> </span><spa=
n style=3D"color:#066">3</span><span style=3D"color:#660">,</span><span sty=
le=3D"color:#000"> </span><span style=3D"color:#080">"3"</span><s=
pan style=3D"color:#000"> </span><span style=3D"color:#660">},</span><span =
style=3D"color:#000"> </span><span style=3D"color:#606">Element</span><span=
style=3D"color:#660">{</span><span style=3D"color:#000"> </span><span styl=
e=3D"color:#066">4</span><span style=3D"color:#660">,</span><span style=3D"=
color:#000"> </span><span style=3D"color:#080">"4"</span><span st=
yle=3D"color:#000"> </span><span style=3D"color:#660">},</span><span style=
=3D"color:#000"> </span><span style=3D"color:#606">Element</span><span styl=
e=3D"color:#660">{</span><span style=3D"color:#000"> </span><span style=3D"=
color:#066">5</span><span style=3D"color:#660">,</span><span style=3D"color=
:#000"> </span><span style=3D"color:#080">"5"</span><span style=
=3D"color:#000"> </span><span style=3D"color:#660">}</span><span style=3D"c=
olor:#000"> </span><span style=3D"color:#660">};</span></div></code></div>
That is not what we want. We could use std::initializer_list, but the initi=
alizer list could be of different size. We would have to add a runtime chec=
k.
If initializer_list would allow an optional size parameter. The container c=
ode could look like the following
<div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,18=
7);border-style:solid;border-width:1px"><code><div><span style=3D"color:#00=
8">template</span><span style=3D"color:#000"> </span><span style=3D"color:#=
660"><</span><span style=3D"color:#008">typename</span><span style=3D"co=
lor:#000"> E</span><span style=3D"color:#660">,</span><span style=3D"color:=
#000"> size_t N</span><span style=3D"color:#660">></span><span style=3D"=
color:#000"><br></span><span style=3D"color:#008">class</span><span style=
=3D"color:#000"> </span><span style=3D"color:#606">Container</span><span st=
yle=3D"color:#000"><br></span><span style=3D"color:#660">{</span><span styl=
e=3D"color:#000"><br><br>=C2=A0 </span><span style=3D"color:#008">public</s=
pan><span style=3D"color:#660">:</span><span style=3D"color:#000"><br><br>=
=C2=A0 =C2=A0 </span><span style=3D"color:#606">Container</span><span style=
=3D"color:#660">(</span><span style=3D"color:#000">std</span><span style=3D=
"color:#660">::</span><span style=3D"color:#000">initializer_lis<wbr>t</spa=
n><span style=3D"color:#660"><</span><span style=3D"color:#000">E</span>=
<span style=3D"color:#660">,</span><span style=3D"color:#000"> N</span><spa=
n style=3D"color:#660">></span><span style=3D"color:#000"> il</span><spa=
n style=3D"color:#660">)</span></div></code></div></pre></div></div></div><=
/div></div></blockquote><div><br></div><div>Use "E (&&il)[N]&q=
uot;.</div><div><br></div><div>This is strictly better than the initializer=
_list form for this use case, since it also permits you to move from the in=
itializer.</div><div>=C2=A0</div><blockquote class=3D"gmail_quote" style=3D=
"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D=
"ltr"><div><div style=3D"overflow:auto"><div style=3D"max-height:10000px"><=
div dir=3D"ltr"><pre><div style=3D"background-color:rgb(250,250,250);border=
-color:rgb(187,187,187);border-style:solid;border-width:1px"><code><div><sp=
an style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#660"=
>{</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 std</sp=
an><span style=3D"color:#660">::</span><span style=3D"color:#000">copy_n</s=
pan><span style=3D"color:#660">(</span><span style=3D"color:#000">il</span>=
<span style=3D"color:#660">.</span><span style=3D"color:#008">begin</span><=
span style=3D"color:#660">(),</span><span style=3D"color:#000"> N</span><sp=
an style=3D"color:#660">,</span><span style=3D"color:#000"> data</span><spa=
n style=3D"color:#660">);</span><span style=3D"color:#000"><br>=C2=A0 =C2=
=A0 </span><span style=3D"color:#660">}</span><span style=3D"color:#000"><b=
r><br>=C2=A0 </span><span style=3D"color:#008">private</span><span style=3D=
"color:#660">:</span><span style=3D"color:#000"><br><br>=C2=A0 =C2=A0 E dat=
a</span><span style=3D"color:#660">[</span><span style=3D"color:#000">N</sp=
an><span style=3D"color:#660">];</span><span style=3D"color:#000"><br><br><=
/span><span style=3D"color:#660">};</span></div></code></div><br>Now we cou=
ld write
<div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,18=
7);border-style:solid;border-width:1px"><code><div><span style=3D"color:#60=
6">Container</span><span style=3D"color:#660"><</span><span style=3D"col=
or:#606">Element</span><span style=3D"color:#660">,</span><span style=3D"co=
lor:#000"> </span><span style=3D"color:#066">5</span><span style=3D"color:#=
660">></span><span style=3D"color:#000"> c</span><span style=3D"color:#6=
60">{</span><span style=3D"color:#000"> </span><span style=3D"color:#660">{=
</span><span style=3D"color:#000"> </span><span style=3D"color:#066">1</spa=
n><span style=3D"color:#660">,</span><span style=3D"color:#000"> </span><sp=
an style=3D"color:#080">"1"</span><span style=3D"color:#000"> </s=
pan><span style=3D"color:#660">},</span><span style=3D"color:#000"> </span>=
<span style=3D"color:#660">{</span><span style=3D"color:#000"> </span><span=
style=3D"color:#066">2</span><span style=3D"color:#660">,</span><span styl=
e=3D"color:#000"> </span><span style=3D"color:#080">"2"</span><sp=
an style=3D"color:#000"> </span><span style=3D"color:#660">},</span><span s=
tyle=3D"color:#000"> </span><span style=3D"color:#660">{</span><span style=
=3D"color:#000"> </span><span style=3D"color:#066">3</span><span style=3D"c=
olor:#660">,</span><span style=3D"color:#000"> </span><span style=3D"color:=
#080">"3"</span><span style=3D"color:#000"> </span><span style=3D=
"color:#660">},</span><span style=3D"color:#000"> </span><span style=3D"col=
or:#660">{</span><span style=3D"color:#000"> </span><span style=3D"color:#0=
66">4</span><span style=3D"color:#660">,</span><span style=3D"color:#000"> =
</span><span style=3D"color:#080">"4"</span><span style=3D"color:=
#000"> </span><span style=3D"color:#660">},</span><span style=3D"color:#000=
"> </span><span style=3D"color:#660">{</span><span style=3D"color:#000"> </=
span><span style=3D"color:#066">5</span><span style=3D"color:#660">,</span>=
<span style=3D"color:#000"> </span><span style=3D"color:#080">"5"=
</span><span style=3D"color:#000"> </span><span style=3D"color:#660">}</spa=
n><span style=3D"color:#000"> </span><span style=3D"color:#660">};</span></=
div></code></div><br>If the number of elements differ the compiler can dete=
ct the error:
<div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,18=
7);border-style:solid;border-width:1px"><code><div><span style=3D"color:#60=
6">Container</span><span style=3D"color:#660"><</span><span style=3D"col=
or:#606">Element</span><span style=3D"color:#660">,</span><span style=3D"co=
lor:#000"> </span><span style=3D"color:#066">5</span><span style=3D"color:#=
660">></span><span style=3D"color:#000"> c</span><span style=3D"color:#6=
60">{</span><span style=3D"color:#000"> </span><span style=3D"color:#660">{=
</span><span style=3D"color:#000"> </span><span style=3D"color:#066">1</spa=
n><span style=3D"color:#660">,</span><span style=3D"color:#000"> </span><sp=
an style=3D"color:#080">"1"</span><span style=3D"color:#000"> </s=
pan><span style=3D"color:#660">},</span><span style=3D"color:#000"> </span>=
<span style=3D"color:#660">{</span><span style=3D"color:#000"> </span><span=
style=3D"color:#066">2</span><span style=3D"color:#660">,</span><span styl=
e=3D"color:#000"> </span><span style=3D"color:#080">"2"</span><sp=
an style=3D"color:#000"> </span><span style=3D"color:#660">},</span><span s=
tyle=3D"color:#000"> </span><span style=3D"color:#660">{</span><span style=
=3D"color:#000"> </span><span style=3D"color:#066">3</span><span style=3D"c=
olor:#660">,</span><span style=3D"color:#000"> </span><span style=3D"color:=
#080">"3"</span><span style=3D"color:#000"> </span><span style=3D=
"color:#660">},</span><span style=3D"color:#000"> </span><span style=3D"col=
or:#660">{</span><span style=3D"color:#000"> </span><span style=3D"color:#0=
66">4</span><span style=3D"color:#660">,</span><span style=3D"color:#000"> =
</span><span style=3D"color:#080">"4"</span><span style=3D"color:=
#000"> </span><span style=3D"color:#660">},</span><span style=3D"color:#000=
"> </span><span style=3D"color:#660">{</span><span style=3D"color:#000"> </=
span><span style=3D"color:#066">5</span><span style=3D"color:#660">,</span>=
<span style=3D"color:#000"> </span><span style=3D"color:#080">"5"=
</span><span style=3D"color:#000"> </span><span style=3D"color:#660">},</sp=
an><span style=3D"color:#000"> </span><span style=3D"color:#660">{</span><s=
pan style=3D"color:#000"> </span><span style=3D"color:#066">6</span><span s=
tyle=3D"color:#660">,</span><span style=3D"color:#000"> </span><span style=
=3D"color:#080">"6"</span><span style=3D"color:#660">}</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#660">};</span><span st=
yle=3D"color:#000"> </span><span style=3D"color:#800">// error: too much el=
ements</span></div></code></div>
In combination with deduction guides, allowing a partial deduction, it woul=
d be possible to write
<div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,18=
7);border-style:solid;border-width:1px"><code><div><span style=3D"color:#60=
6">Container</span><span style=3D"color:#660"><</span><span style=3D"col=
or:#606">Element</span><span style=3D"color:#660">></span><span style=3D=
"color:#000"> c</span><span style=3D"color:#660">{</span><span style=3D"col=
or:#000"> </span><span style=3D"color:#660">{</span><span style=3D"color:#0=
00"> </span><span style=3D"color:#066">1</span><span style=3D"color:#660">,=
</span><span style=3D"color:#000"> </span><span style=3D"color:#080">"=
1"</span><span style=3D"color:#000"> </span><span style=3D"color:#660"=
>},</span><span style=3D"color:#000"> </span><span style=3D"color:#660">{</=
span><span style=3D"color:#000"> </span><span style=3D"color:#066">2</span>=
<span style=3D"color:#660">,</span><span style=3D"color:#000"> </span><span=
style=3D"color:#080">"2"</span><span style=3D"color:#000"> </spa=
n><span style=3D"color:#660">},</span><span style=3D"color:#000"> </span><s=
pan style=3D"color:#660">{</span><span style=3D"color:#000"> </span><span s=
tyle=3D"color:#066">3</span><span style=3D"color:#660">,</span><span style=
=3D"color:#000"> </span><span style=3D"color:#080">"3"</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#660">},</span><span st=
yle=3D"color:#000"> </span><span style=3D"color:#660">{</span><span style=
=3D"color:#000"> </span><span style=3D"color:#066">4</span><span style=3D"c=
olor:#660">,</span><span style=3D"color:#000"> </span><span style=3D"color:=
#080">"4"</span><span style=3D"color:#000"> </span><span style=3D=
"color:#660">},</span><span style=3D"color:#000"> </span><span style=3D"col=
or:#660">{</span><span style=3D"color:#000"> </span><span style=3D"color:#0=
66">5</span><span style=3D"color:#660">,</span><span style=3D"color:#000"> =
</span><span style=3D"color:#080">"5"</span><span style=3D"color:=
#000"> </span><span style=3D"color:#660">}</span><span style=3D"color:#000"=
> </span><span style=3D"color:#660">};</span></div></code></div>
Kind Regards,
Martin Kalbfu=C3=9F
</pre></div></div></div></div><span class=3D"HOEnZb"><font color=3D"#888888=
"> </font></span></div><span class=3D"HOEnZb"><font color=3D"#8=
88888">
<p></p>
-- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org" target=3D"_=
blank">std-proposals+unsubscribe@<wbr>isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/0649c0ae-0e27-4fd5-8c31-3f418989e581%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" target=3D"_blank">=
https://groups.google.com/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/0649=
c0ae-0e27-4fd5-<wbr>8c31-3f418989e581%40isocpp.org</a><wbr>.<br>
</font></span></blockquote></div><br></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAOfiQqkC%3D8EtYLGyB4rzZNU0fbM_rD60iW=
3f%2B%2BOTeMn%3D4-gT3w%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfoo=
ter">https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAOfiQqkC=
%3D8EtYLGyB4rzZNU0fbM_rD60iW3f%2B%2BOTeMn%3D4-gT3w%40mail.gmail.com</a>.<br=
/>
--001a113535945c4a2f055cdc4e86--
.
Author: Richard Smith <richard@metafoo.co.uk>
Date: Tue, 31 Oct 2017 11:57:51 -0700
Raw View
--94eb2c11ed783ce1d1055cdc564c
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
On 31 October 2017 at 11:55, Richard Smith <richard@metafoo.co.uk> wrote:
> On 31 October 2017 at 11:05, ma.kalbfuss via ISO C++ Standard - Future
> Proposals <std-proposals@isocpp.org> wrote:
>
>> Hi Guys,
>>
>> If we have a container type like...
>>
>> template <typename E, size_t S>
>> class Container
>> {
>>
>> public:
>>
>> template <typename... Args>
>> Container(Args&&... args)
>> : data(std::forward<Args>(args)...)
>> { }
>>
>> private:
>>
>> E data[S];
>>
>> };
>>
>> We can initialize the container with
>>
>> Container<int, 5> c{ 0, 1, 2, 3, 4, 5 };
>>
>> But if we have a more complex element type like a class or struct we can=
not write
>>
>> Container<Element, 5> c{ { 1, "1" }, { 2, "2" }, { 3, "3" }, { 4, "4" },=
{ 5, "5" } };
>>
>> The compiler cannot deduce the type. We would have to write
>>
>> Container<Element, 5> c{ Element{ 1, "1" }, Element{ 2, "2" }, Element{ =
3, "3" }, Element{ 4, "4" }, Element{ 5, "5" } };
>>
>> That is not what we want. We could use std::initializer_list, but the in=
itializer list could be of different size. We would have to add a runtime c=
heck.
>> If initializer_list would allow an optional size parameter. The containe=
r code could look like the following
>>
>> template <typename E, size_t N>
>> class Container
>> {
>>
>> public:
>>
>> Container(std::initializer_list<E, N> il)
>>
>>
> Use "E (&&il)[N]".
>
> This is strictly better than the initializer_list form for this use case,
> since it also permits you to move from the initializer.
>
I should probably also mention the downside, which is that you have to add
an extra set of parens or braces around your initializer. I think it's a
shame that we don't treat the reference-to-array case as an
initializer-list constructor. It would be interesting to see how much
existing code would be broken by changing that.
>
>
>>
>> {
>> std::copy_n(il.begin(), N, data);
>> }
>>
>> private:
>>
>> E data[N];
>>
>> };
>>
>> Now we could write
>>
>> Container<Element, 5> c{ { 1, "1" }, { 2, "2" }, { 3, "3" }, { 4, "4" },=
{ 5, "5" } };
>>
>> If the number of elements differ the compiler can detect the error:
>>
>> Container<Element, 5> c{ { 1, "1" }, { 2, "2" }, { 3, "3" }, { 4, "4" },=
{ 5, "5" }, { 6, "6"} }; // error: too much elements
>>
>> In combination with deduction guides, allowing a partial deduction, it w=
ould be possible to write
>>
>> Container<Element> c{ { 1, "1" }, { 2, "2" }, { 3, "3" }, { 4, "4" }, { =
5, "5" } };
>>
>> Kind Regards,
>> Martin Kalbfu=C3=9F
>>
>>
>> --
>> You received this message because you are subscribed to the Google Group=
s
>> "ISO C++ Standard - Future Proposals" group.
>> To unsubscribe from this group and stop receiving emails from it, send a=
n
>> email to std-proposals+unsubscribe@isocpp.org.
>> To post to this group, send email to std-proposals@isocpp.org.
>> To view this discussion on the web visit https://groups.google.com/a/is
>> ocpp.org/d/msgid/std-proposals/0649c0ae-0e27-4fd5-8c31-
>> 3f418989e581%40isocpp.org
>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/0649c0ae-0=
e27-4fd5-8c31-3f418989e581%40isocpp.org?utm_medium=3Demail&utm_source=3Dfoo=
ter>
>> .
>>
>
>
--=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/CAOfiQq%3DfkxgPs0gK%3DpBKOMdON1%3D%3DF_KrvQrtg8F=
Vu5xd%3DfXt4A%40mail.gmail.com.
--94eb2c11ed783ce1d1055cdc564c
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On 3=
1 October 2017 at 11:55, Richard Smith <span dir=3D"ltr"><<a href=3D"mai=
lto:richard@metafoo.co.uk" target=3D"_blank">richard@metafoo.co.uk</a>><=
/span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8=
ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div class=
=3D"gmail_extra"><div class=3D"gmail_quote"><span class=3D"">On 31 October =
2017 at 11:05, ma.kalbfuss via ISO C++ Standard - Future Proposals <span di=
r=3D"ltr"><<a href=3D"mailto:std-proposals@isocpp.org" target=3D"_blank"=
>std-proposals@isocpp.org</a>></span> wrote:<br><blockquote class=3D"gma=
il_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-lef=
t:1ex"><div dir=3D"ltr"><div><div style=3D"overflow:auto"><div style=3D"max=
-height:10000px"><div dir=3D"ltr"><pre>Hi Guys,
If we have a container type like...<br>=C2=A0<div style=3D"background-color=
:rgb(250,250,250);border-color:rgb(187,187,187);border-style:solid;border-w=
idth:1px"><code><div><span style=3D"color:#008">template</span><span style=
=3D"color:#000"> </span><span style=3D"color:#660"><</span><span style=
=3D"color:#008">typename</span><span style=3D"color:#000"> E</span><span st=
yle=3D"color:#660">,</span><span style=3D"color:#000"> size_t S</span><span=
style=3D"color:#660">></span><span style=3D"color:#000"><br></span><spa=
n style=3D"color:#008">class</span><span style=3D"color:#000"> </span><span=
style=3D"color:#606">Container</span><span style=3D"color:#000"><br></span=
><span style=3D"color:#660">{</span><span style=3D"color:#000"><br><br>=C2=
=A0 </span><span style=3D"color:#008">public</span><span style=3D"color:#66=
0">:</span><span style=3D"color:#000"><br><br>=C2=A0 =C2=A0 </span><span st=
yle=3D"color:#008">template</span><span style=3D"color:#000"> </span><span =
style=3D"color:#660"><</span><span style=3D"color:#008">typename</span><=
span style=3D"color:#660">...</span><span style=3D"color:#000"> </span><spa=
n style=3D"color:#606">Args</span><span style=3D"color:#660">></span><sp=
an style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#606"=
>Container</span><span style=3D"color:#660">(</span><span style=3D"color:#6=
06">Args</span><span style=3D"color:#660">&&...</span><span style=
=3D"color:#000"> args</span><span style=3D"color:#660">)</span><span style=
=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color=
:#660">:</span><span style=3D"color:#000"> data</span><span style=3D"color:=
#660">(</span><span style=3D"color:#000">std</span><span style=3D"color:#66=
0">::</span><span style=3D"color:#000">forward</span><span style=3D"color:#=
660"><</span><span style=3D"color:#606">Args</span><span style=3D"color:=
#660">>(</span><span style=3D"color:#000">args</span><span style=3D"colo=
r:#660">).<wbr>..)</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </spa=
n><span style=3D"color:#660">{</span><span style=3D"color:#000"> </span><sp=
an style=3D"color:#660">}</span><span style=3D"color:#000"><br><br>=C2=A0 <=
/span><span style=3D"color:#008">private</span><span style=3D"color:#660">:=
</span><span style=3D"color:#000"><br><br>=C2=A0 =C2=A0 E data</span><span =
style=3D"color:#660">[</span><span style=3D"color:#000">S</span><span style=
=3D"color:#660">];</span><span style=3D"color:#000"><br><br></span><span st=
yle=3D"color:#660">};</span></div></code></div>
We can initialize the container with
<div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,18=
7);border-style:solid;border-width:1px"><code><div><span style=3D"color:#60=
6">Container</span><span style=3D"color:#660"><</span><span style=3D"col=
or:#008">int</span><span style=3D"color:#660">,</span><span style=3D"color:=
#000"> </span><span style=3D"color:#066">5</span><span style=3D"color:#660"=
>></span><span style=3D"color:#000"> c</span><span style=3D"color:#660">=
{</span><span style=3D"color:#000"> </span><span style=3D"color:#066">0</sp=
an><span style=3D"color:#660">,</span><span style=3D"color:#000"> </span><s=
pan style=3D"color:#066">1</span><span style=3D"color:#660">,</span><span s=
tyle=3D"color:#000"> </span><span style=3D"color:#066">2</span><span style=
=3D"color:#660">,</span><span style=3D"color:#000"> </span><span style=3D"c=
olor:#066">3</span><span style=3D"color:#660">,</span><span style=3D"color:=
#000"> </span><span style=3D"color:#066">4</span><span style=3D"color:#660"=
>,</span><span style=3D"color:#000"> </span><span style=3D"color:#066">5</s=
pan><span style=3D"color:#000"> </span><span style=3D"color:#660">};</span>=
</div></code></div>
But if we have a more complex element type like a class or struct we cannot=
write
<div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,18=
7);border-style:solid;border-width:1px"><code><div><span style=3D"color:#60=
6">Container</span><span style=3D"color:#660"><</span><span style=3D"col=
or:#606">Element</span><span style=3D"color:#660">,</span><span style=3D"co=
lor:#000"> </span><span style=3D"color:#066">5</span><span style=3D"color:#=
660">></span><span style=3D"color:#000"> c</span><span style=3D"color:#6=
60">{</span><span style=3D"color:#000"> </span><span style=3D"color:#660">{=
</span><span style=3D"color:#000"> </span><span style=3D"color:#066">1</spa=
n><span style=3D"color:#660">,</span><span style=3D"color:#000"> </span><sp=
an style=3D"color:#080">"1"</span><span style=3D"color:#000"> </s=
pan><span style=3D"color:#660">},</span><span style=3D"color:#000"> </span>=
<span style=3D"color:#660">{</span><span style=3D"color:#000"> </span><span=
style=3D"color:#066">2</span><span style=3D"color:#660">,</span><span styl=
e=3D"color:#000"> </span><span style=3D"color:#080">"2"</span><sp=
an style=3D"color:#000"> </span><span style=3D"color:#660">},</span><span s=
tyle=3D"color:#000"> </span><span style=3D"color:#660">{</span><span style=
=3D"color:#000"> </span><span style=3D"color:#066">3</span><span style=3D"c=
olor:#660">,</span><span style=3D"color:#000"> </span><span style=3D"color:=
#080">"3"</span><span style=3D"color:#000"> </span><span style=3D=
"color:#660">},</span><span style=3D"color:#000"> </span><span style=3D"col=
or:#660">{</span><span style=3D"color:#000"> </span><span style=3D"color:#0=
66">4</span><span style=3D"color:#660">,</span><span style=3D"color:#000"> =
</span><span style=3D"color:#080">"4"</span><span style=3D"color:=
#000"> </span><span style=3D"color:#660">},</span><span style=3D"color:#000=
"> </span><span style=3D"color:#660">{</span><span style=3D"color:#000"> </=
span><span style=3D"color:#066">5</span><span style=3D"color:#660">,</span>=
<span style=3D"color:#000"> </span><span style=3D"color:#080">"5"=
</span><span style=3D"color:#000"> </span><span style=3D"color:#660">}</spa=
n><span style=3D"color:#000"> </span><span style=3D"color:#660">};</span></=
div></code></div>
The compiler cannot deduce the type. We would have to write
<div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,18=
7);border-style:solid;border-width:1px"><code><div><span style=3D"color:#60=
6">Container</span><span style=3D"color:#660"><</span><span style=3D"col=
or:#606">Element</span><span style=3D"color:#660">,</span><span style=3D"co=
lor:#000"> </span><span style=3D"color:#066">5</span><span style=3D"color:#=
660">></span><span style=3D"color:#000"> c</span><span style=3D"color:#6=
60">{</span><span style=3D"color:#000"> </span><span style=3D"color:#606">E=
lement</span><span style=3D"color:#660">{</span><span style=3D"color:#000">=
</span><span style=3D"color:#066">1</span><span style=3D"color:#660">,</sp=
an><span style=3D"color:#000"> </span><span style=3D"color:#080">"1&qu=
ot;</span><span style=3D"color:#000"> </span><span style=3D"color:#660">},<=
/span><span style=3D"color:#000"> </span><span style=3D"color:#606">Element=
</span><span style=3D"color:#660">{</span><span style=3D"color:#000"> </spa=
n><span style=3D"color:#066">2</span><span style=3D"color:#660">,</span><sp=
an style=3D"color:#000"> </span><span style=3D"color:#080">"2"</s=
pan><span style=3D"color:#000"> </span><span style=3D"color:#660">},</span>=
<span style=3D"color:#000"> </span><span style=3D"color:#606">Element</span=
><span style=3D"color:#660">{</span><span style=3D"color:#000"> </span><spa=
n style=3D"color:#066">3</span><span style=3D"color:#660">,</span><span sty=
le=3D"color:#000"> </span><span style=3D"color:#080">"3"</span><s=
pan style=3D"color:#000"> </span><span style=3D"color:#660">},</span><span =
style=3D"color:#000"> </span><span style=3D"color:#606">Element</span><span=
style=3D"color:#660">{</span><span style=3D"color:#000"> </span><span styl=
e=3D"color:#066">4</span><span style=3D"color:#660">,</span><span style=3D"=
color:#000"> </span><span style=3D"color:#080">"4"</span><span st=
yle=3D"color:#000"> </span><span style=3D"color:#660">},</span><span style=
=3D"color:#000"> </span><span style=3D"color:#606">Element</span><span styl=
e=3D"color:#660">{</span><span style=3D"color:#000"> </span><span style=3D"=
color:#066">5</span><span style=3D"color:#660">,</span><span style=3D"color=
:#000"> </span><span style=3D"color:#080">"5"</span><span style=
=3D"color:#000"> </span><span style=3D"color:#660">}</span><span style=3D"c=
olor:#000"> </span><span style=3D"color:#660">};</span></div></code></div>
That is not what we want. We could use std::initializer_list, but the initi=
alizer list could be of different size. We would have to add a runtime chec=
k.
If initializer_list would allow an optional size parameter. The container c=
ode could look like the following
<div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,18=
7);border-style:solid;border-width:1px"><code><div><span style=3D"color:#00=
8">template</span><span style=3D"color:#000"> </span><span style=3D"color:#=
660"><</span><span style=3D"color:#008">typename</span><span style=3D"co=
lor:#000"> E</span><span style=3D"color:#660">,</span><span style=3D"color:=
#000"> size_t N</span><span style=3D"color:#660">></span><span style=3D"=
color:#000"><br></span><span style=3D"color:#008">class</span><span style=
=3D"color:#000"> </span><span style=3D"color:#606">Container</span><span st=
yle=3D"color:#000"><br></span><span style=3D"color:#660">{</span><span styl=
e=3D"color:#000"><br><br>=C2=A0 </span><span style=3D"color:#008">public</s=
pan><span style=3D"color:#660">:</span><span style=3D"color:#000"><br><br>=
=C2=A0 =C2=A0 </span><span style=3D"color:#606">Container</span><span style=
=3D"color:#660">(</span><span style=3D"color:#000">std</span><span style=3D=
"color:#660">::</span><span style=3D"color:#000">initializer_lis<wbr>t</spa=
n><span style=3D"color:#660"><</span><span style=3D"color:#000">E</span>=
<span style=3D"color:#660">,</span><span style=3D"color:#000"> N</span><spa=
n style=3D"color:#660">></span><span style=3D"color:#000"> il</span><spa=
n style=3D"color:#660">)</span></div></code></div></pre></div></div></div><=
/div></div></blockquote><div><br></div></span><div>Use "E (&&i=
l)[N]".</div><div><br></div><div>This is strictly better than the init=
ializer_list form for this use case, since it also permits you to move from=
the initializer.</div></div></div></div></blockquote><div><br></div><div>I=
should probably also mention the downside, which is that you have to add a=
n extra set of parens or braces around your initializer. I think it's a=
shame that we don't treat the reference-to-array case as an initialize=
r-list constructor. It would be interesting to see how much existing code w=
ould be broken by changing that.</div><div>=C2=A0</div><blockquote class=3D=
"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding=
-left:1ex"><div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_=
quote"><div>=C2=A0</div><span class=3D""><blockquote class=3D"gmail_quote" =
style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><di=
v dir=3D"ltr"><div><div style=3D"overflow:auto"><div style=3D"max-height:10=
000px"><div dir=3D"ltr"><pre><div style=3D"background-color:rgb(250,250,250=
);border-color:rgb(187,187,187);border-style:solid;border-width:1px"><code>=
<div><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"col=
or:#660">{</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0=
std</span><span style=3D"color:#660">::</span><span style=3D"color:#000">c=
opy_n</span><span style=3D"color:#660">(</span><span style=3D"color:#000">i=
l</span><span style=3D"color:#660">.</span><span style=3D"color:#008">begin=
</span><span style=3D"color:#660">(),</span><span style=3D"color:#000"> N</=
span><span style=3D"color:#660">,</span><span style=3D"color:#000"> data</s=
pan><span style=3D"color:#660">);</span><span style=3D"color:#000"><br>=C2=
=A0 =C2=A0 </span><span style=3D"color:#660">}</span><span style=3D"color:#=
000"><br><br>=C2=A0 </span><span style=3D"color:#008">private</span><span s=
tyle=3D"color:#660">:</span><span style=3D"color:#000"><br><br>=C2=A0 =C2=
=A0 E data</span><span style=3D"color:#660">[</span><span style=3D"color:#0=
00">N</span><span style=3D"color:#660">];</span><span style=3D"color:#000">=
<br><br></span><span style=3D"color:#660">};</span></div></code></div><br>N=
ow we could write
<div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,18=
7);border-style:solid;border-width:1px"><code><div><span style=3D"color:#60=
6">Container</span><span style=3D"color:#660"><</span><span style=3D"col=
or:#606">Element</span><span style=3D"color:#660">,</span><span style=3D"co=
lor:#000"> </span><span style=3D"color:#066">5</span><span style=3D"color:#=
660">></span><span style=3D"color:#000"> c</span><span style=3D"color:#6=
60">{</span><span style=3D"color:#000"> </span><span style=3D"color:#660">{=
</span><span style=3D"color:#000"> </span><span style=3D"color:#066">1</spa=
n><span style=3D"color:#660">,</span><span style=3D"color:#000"> </span><sp=
an style=3D"color:#080">"1"</span><span style=3D"color:#000"> </s=
pan><span style=3D"color:#660">},</span><span style=3D"color:#000"> </span>=
<span style=3D"color:#660">{</span><span style=3D"color:#000"> </span><span=
style=3D"color:#066">2</span><span style=3D"color:#660">,</span><span styl=
e=3D"color:#000"> </span><span style=3D"color:#080">"2"</span><sp=
an style=3D"color:#000"> </span><span style=3D"color:#660">},</span><span s=
tyle=3D"color:#000"> </span><span style=3D"color:#660">{</span><span style=
=3D"color:#000"> </span><span style=3D"color:#066">3</span><span style=3D"c=
olor:#660">,</span><span style=3D"color:#000"> </span><span style=3D"color:=
#080">"3"</span><span style=3D"color:#000"> </span><span style=3D=
"color:#660">},</span><span style=3D"color:#000"> </span><span style=3D"col=
or:#660">{</span><span style=3D"color:#000"> </span><span style=3D"color:#0=
66">4</span><span style=3D"color:#660">,</span><span style=3D"color:#000"> =
</span><span style=3D"color:#080">"4"</span><span style=3D"color:=
#000"> </span><span style=3D"color:#660">},</span><span style=3D"color:#000=
"> </span><span style=3D"color:#660">{</span><span style=3D"color:#000"> </=
span><span style=3D"color:#066">5</span><span style=3D"color:#660">,</span>=
<span style=3D"color:#000"> </span><span style=3D"color:#080">"5"=
</span><span style=3D"color:#000"> </span><span style=3D"color:#660">}</spa=
n><span style=3D"color:#000"> </span><span style=3D"color:#660">};</span></=
div></code></div><br>If the number of elements differ the compiler can dete=
ct the error:
<div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,18=
7);border-style:solid;border-width:1px"><code><div><span style=3D"color:#60=
6">Container</span><span style=3D"color:#660"><</span><span style=3D"col=
or:#606">Element</span><span style=3D"color:#660">,</span><span style=3D"co=
lor:#000"> </span><span style=3D"color:#066">5</span><span style=3D"color:#=
660">></span><span style=3D"color:#000"> c</span><span style=3D"color:#6=
60">{</span><span style=3D"color:#000"> </span><span style=3D"color:#660">{=
</span><span style=3D"color:#000"> </span><span style=3D"color:#066">1</spa=
n><span style=3D"color:#660">,</span><span style=3D"color:#000"> </span><sp=
an style=3D"color:#080">"1"</span><span style=3D"color:#000"> </s=
pan><span style=3D"color:#660">},</span><span style=3D"color:#000"> </span>=
<span style=3D"color:#660">{</span><span style=3D"color:#000"> </span><span=
style=3D"color:#066">2</span><span style=3D"color:#660">,</span><span styl=
e=3D"color:#000"> </span><span style=3D"color:#080">"2"</span><sp=
an style=3D"color:#000"> </span><span style=3D"color:#660">},</span><span s=
tyle=3D"color:#000"> </span><span style=3D"color:#660">{</span><span style=
=3D"color:#000"> </span><span style=3D"color:#066">3</span><span style=3D"c=
olor:#660">,</span><span style=3D"color:#000"> </span><span style=3D"color:=
#080">"3"</span><span style=3D"color:#000"> </span><span style=3D=
"color:#660">},</span><span style=3D"color:#000"> </span><span style=3D"col=
or:#660">{</span><span style=3D"color:#000"> </span><span style=3D"color:#0=
66">4</span><span style=3D"color:#660">,</span><span style=3D"color:#000"> =
</span><span style=3D"color:#080">"4"</span><span style=3D"color:=
#000"> </span><span style=3D"color:#660">},</span><span style=3D"color:#000=
"> </span><span style=3D"color:#660">{</span><span style=3D"color:#000"> </=
span><span style=3D"color:#066">5</span><span style=3D"color:#660">,</span>=
<span style=3D"color:#000"> </span><span style=3D"color:#080">"5"=
</span><span style=3D"color:#000"> </span><span style=3D"color:#660">},</sp=
an><span style=3D"color:#000"> </span><span style=3D"color:#660">{</span><s=
pan style=3D"color:#000"> </span><span style=3D"color:#066">6</span><span s=
tyle=3D"color:#660">,</span><span style=3D"color:#000"> </span><span style=
=3D"color:#080">"6"</span><span style=3D"color:#660">}</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#660">};</span><span st=
yle=3D"color:#000"> </span><span style=3D"color:#800">// error: too much el=
ements</span></div></code></div>
In combination with deduction guides, allowing a partial deduction, it woul=
d be possible to write
<div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,18=
7);border-style:solid;border-width:1px"><code><div><span style=3D"color:#60=
6">Container</span><span style=3D"color:#660"><</span><span style=3D"col=
or:#606">Element</span><span style=3D"color:#660">></span><span style=3D=
"color:#000"> c</span><span style=3D"color:#660">{</span><span style=3D"col=
or:#000"> </span><span style=3D"color:#660">{</span><span style=3D"color:#0=
00"> </span><span style=3D"color:#066">1</span><span style=3D"color:#660">,=
</span><span style=3D"color:#000"> </span><span style=3D"color:#080">"=
1"</span><span style=3D"color:#000"> </span><span style=3D"color:#660"=
>},</span><span style=3D"color:#000"> </span><span style=3D"color:#660">{</=
span><span style=3D"color:#000"> </span><span style=3D"color:#066">2</span>=
<span style=3D"color:#660">,</span><span style=3D"color:#000"> </span><span=
style=3D"color:#080">"2"</span><span style=3D"color:#000"> </spa=
n><span style=3D"color:#660">},</span><span style=3D"color:#000"> </span><s=
pan style=3D"color:#660">{</span><span style=3D"color:#000"> </span><span s=
tyle=3D"color:#066">3</span><span style=3D"color:#660">,</span><span style=
=3D"color:#000"> </span><span style=3D"color:#080">"3"</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#660">},</span><span st=
yle=3D"color:#000"> </span><span style=3D"color:#660">{</span><span style=
=3D"color:#000"> </span><span style=3D"color:#066">4</span><span style=3D"c=
olor:#660">,</span><span style=3D"color:#000"> </span><span style=3D"color:=
#080">"4"</span><span style=3D"color:#000"> </span><span style=3D=
"color:#660">},</span><span style=3D"color:#000"> </span><span style=3D"col=
or:#660">{</span><span style=3D"color:#000"> </span><span style=3D"color:#0=
66">5</span><span style=3D"color:#660">,</span><span style=3D"color:#000"> =
</span><span style=3D"color:#080">"5"</span><span style=3D"color:=
#000"> </span><span style=3D"color:#660">}</span><span style=3D"color:#000"=
> </span><span style=3D"color:#660">};</span></div></code></div>
Kind Regards,
Martin Kalbfu=C3=9F
</pre></div></div></div></div><span class=3D"m_4272782005339551766HOEnZb"><=
font color=3D"#888888"> </font></span></div><span class=3D"m_42=
72782005339551766HOEnZb"><font color=3D"#888888">
<p></p>
-- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org" target=3D"_=
blank">std-proposals+unsubscribe@isoc<wbr>pp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/0649c0ae-0e27-4fd5-8c31-3f418989e581%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" target=3D"_blank">=
https://groups.google.com/a/is<wbr>ocpp.org/d/msgid/std-proposals<wbr>/0649=
c0ae-0e27-4fd5-8c31-<wbr>3f418989e581%40isocpp.org</a>.<br>
</font></span></blockquote></span></div><br></div></div>
</blockquote></div><br></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAOfiQq%3DfkxgPs0gK%3DpBKOMdON1%3D%3D=
F_KrvQrtg8FVu5xd%3DfXt4A%40mail.gmail.com?utm_medium=3Demail&utm_source=3Df=
ooter">https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAOfiQq=
%3DfkxgPs0gK%3DpBKOMdON1%3D%3DF_KrvQrtg8FVu5xd%3DfXt4A%40mail.gmail.com</a>=
..<br />
--94eb2c11ed783ce1d1055cdc564c--
.
Author: Zhihao Yuan <zy@miator.net>
Date: Tue, 31 Oct 2017 14:13:46 -0500
Raw View
--001a114c906ef02dd2055cdc8d19
Content-Type: text/plain; charset="UTF-8"
On Tue, Oct 31, 2017 at 1:57 PM, Richard Smith <richard@metafoo.co.uk>
wrote:
> I should probably also mention the downside, which is that you have to add
> an extra set of parens or braces around your initializer. I think it's a
> shame that we don't treat the reference-to-array case as an
> initializer-list constructor. It would be interesting to see how much
> existing code would be broken by changing that.
>
Here is a use case for changing that
https://cplusplus.github.io/LWG/issue2814
Probably also make_shared<T[]>.
--
Zhihao Yuan, ID lichray
The best way to predict the future is to invent it.
_______________________________________________
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAGsORuCeBFS%2B6e4R86RQF%3DrxVyVmPqJ4eZHKd6uuqzfJwt7Owg%40mail.gmail.com.
--001a114c906ef02dd2055cdc8d19
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Tue, Oct 31, 2017 at 1:57 PM, Richard Smith <span dir=
=3D"ltr"><<a target=3D"_blank" href=3D"mailto:richard@metafoo.co.uk">ric=
hard@metafoo.co.uk</a>></span> wrote:<div class=3D"gmail_extra"><div cla=
ss=3D"gmail_quote"><blockquote style=3D"margin:0px 0px 0px 0.8ex;border-lef=
t:1px solid rgb(204,204,204);padding-left:1ex" class=3D"gmail_quote"><div d=
ir=3D"ltr"><div class=3D"gmail_extra">I should probably also mention the do=
wnside, which is that you have to add an extra set of parens or braces arou=
nd your initializer. I think it's a shame that we don't treat the r=
eference-to-array case as an initializer-list constructor. It would be inte=
resting to see how much existing code would be broken by changing that.<div=
class=3D"gmail_quote"><span class=3D"gmail-"></span></div></div></div></bl=
ockquote></div><br></div><div class=3D"gmail_extra">Here is a use case for =
changing that<br><br>=C2=A0 <a href=3D"https://cplusplus.github.io/LWG/issu=
e2814">https://cplusplus.github.io/LWG/issue2814</a><br><br></div><div clas=
s=3D"gmail_extra">Probably also make_shared<T[]>.<br clear=3D"all"></=
div><div class=3D"gmail_extra"><br>-- <br><div class=3D"gmail_signature"><d=
iv dir=3D"ltr"><div><div dir=3D"ltr"><div><div dir=3D"ltr"><div>Zhihao Yuan=
, ID lichray<br>The best way to predict the future is to invent it.<br>____=
___________________________________________<br></div></div></div></div></di=
v></div></div>
</div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAGsORuCeBFS%2B6e4R86RQF%3DrxVyVmPqJ4=
eZHKd6uuqzfJwt7Owg%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAGsORuCeBFS%=
2B6e4R86RQF%3DrxVyVmPqJ4eZHKd6uuqzfJwt7Owg%40mail.gmail.com</a>.<br />
--001a114c906ef02dd2055cdc8d19--
.