Topic: Does template deduction for constructors solve
Author: Faisal Vali <faisalv@gmail.com>
Date: Tue, 26 Jul 2016 19:55:28 -0500
Raw View
On Tue, Jul 26, 2016 at 6:59 PM, Nicol Bolas <jmckesson@gmail.com> wrote:
> Template deduction for constructors allows us to declare a deduction guide
> that maps from potential usage to the actual template type. These deduction
> guides do not prevent a type from being an aggregate. So with a guide, this
> will work:
>
>
> template<typename T1, typename T2>
> struct new_pair
> {
> T1 t1;
> T2 t2;
> };
>
> template<typename T1, typename T2>
> new_pair(T1, T2) -> new_pair<T1, T2>;
>
> new_pair{12.3f, 90}; //T1 = float, T2 = int.
>
Yes.
> Does that mean that it is possible to make this work with `std::array`:
>
Yes.
> auto arr = std::array{2, 3, 1, 4, 44, 23}; //type is deduced as int, size is
> deduced as 6.
>
> I'm thinking of a guide like this:
>
> template<typename T>
> std::array(T ...ts) -> std::array<T, sizeof...(ts);
>
> Or if not that, what about:
>
> template<typename Ts...>
> std::array(Ts ...ts) -> std::array<std::common_type_t<T...>, sizeof...(ts)>;
>
Yes, that should work (modulo syntax bug regarding ellipsis placement
in your template parameter pack).
> If the current syntax doesn't allow a way to deduce the number of
> parameters... is there a way to make it work with some small change to the
> functionality?
>
> --
> 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/7db3740d-f9cf-45ad-a8c6-c61c3b1f9e8f%40isocpp.org.
--
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/CABsSThovKyahDQTMy0xbUMs2EJ4mup4PQ_hMTp5JNZSXcXrgVw%40mail.gmail.com.
.
Author: Edward Catmur <ed@catmur.co.uk>
Date: Tue, 26 Jul 2016 17:59:32 -0700 (PDT)
Raw View
------=_Part_3406_248365636.1469581172663
Content-Type: multipart/alternative;
boundary="----=_Part_3407_510021657.1469581172663"
------=_Part_3407_510021657.1469581172663
Content-Type: text/plain; charset=UTF-8
On Wednesday, 27 July 2016 00:59:08 UTC+1, Nicol Bolas wrote:
>
> Template deduction for constructors allows us to declare a deduction guide
> that maps from potential usage to the actual template type. These deduction
> guides do not prevent a type from being an aggregate. [...]
>
For reference, the proposal series is denoted P0091 and the most recent
paper is Template argument deduction for class templates (Rev. 6)[1].
> Does that mean that it is possible to make this work with `std::array`:
>
> auto arr = std::array{2, 3, 1, 4, 44, 23}; //type is deduced as int, size
> is deduced as 6.
>
Yes.
I'm thinking of a guide like this:
>
> template<typename T>
> std::array(T ...ts) -> std::array<T, sizeof...(ts);
>
The parameter-declaration-clause in a deduction guide is subject to the
same restrictions as a function declaration. You couldn't declare a
function as template<typename T> make_array(T... ts) -> std::array<T,
sizeof...(ts)>, so likewise you can't declare a deduction guide with that
parameter-declaration-clause.
> Or if not that, what about:
>
> template<typename Ts...>
> std::array(Ts ...ts) -> std::array<std::common_type_t<T...>, sizeof...(ts
> )>;
>
Now we're talking. This is nearly correct; aside from one or two typos, the
only issue is that the guide must be declared in the same scope as the
template i.e. within namespace std. (I'm pretty sure reopening namespace
std is allowed; it'd be odd if it wasn't.)
Again, think of deduction guides as shorthand make_XXX functions: the
function template template<class... Ts> make_array(Ts...) ->
array<common_type_t<Ts...>, sizeof...(Ts)> is already a member of the
standard, so adding the corresponding deduction guide should be a matter of
course.
1. http://open-std.org/JTC1/SC22/WG21/docs/papers/2016/p0091r3.html
--
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/09b1e9a6-afb0-4463-83b6-d349b000f516%40isocpp.org.
------=_Part_3407_510021657.1469581172663
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Wednesday, 27 July 2016 00:59:08 UTC+1, Nicol Bolas wr=
ote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex=
;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">Template =
deduction for constructors allows us to declare a deduction guide that maps=
from potential usage to the actual template type. These deduction guides d=
o not prevent a type from being an aggregate. [...]<br></div></blockquote><=
div><br></div><div>For reference, the proposal series is denoted P0091 and =
the most recent paper is Template argument deduction for class templates (R=
ev. 6)[1].</div><div>=C2=A0</div><blockquote class=3D"gmail_quote" style=3D=
"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex=
;"><div dir=3D"ltr">Does that mean that it is possible to make this work wi=
th `std::array`:<br><br><div style=3D"background-color:rgb(250,250,250);bor=
der-color:rgb(187,187,187);border-style:solid;border-width:1px;word-wrap:br=
eak-word"><code><div><span style=3D"color:#008">auto</span><span style=3D"c=
olor:#000"> arr </span><span style=3D"color:#660">=3D</span><span style=3D"=
color:#000"> std</span><span style=3D"color:#660">::</span><span style=3D"c=
olor:#000">array</span><span style=3D"color:#660">{</span><span style=3D"co=
lor:#066">2</span><span style=3D"color:#660">,</span><span style=3D"color:#=
000"> </span><span style=3D"color:#066">3</span><span style=3D"color:#660">=
,</span><span style=3D"color:#000"> </span><span style=3D"color:#066">1</sp=
an><span style=3D"color:#660">,</span><span style=3D"color:#000"> </span><s=
pan style=3D"color:#066">4</span><span style=3D"color:#660">,</span><span s=
tyle=3D"color:#000"> </span><span style=3D"color:#066">44</span><span style=
=3D"color:#660">,</span><span style=3D"color:#000"> </span><span style=3D"c=
olor:#066">23</span><span style=3D"color:#660">};</span><span style=3D"colo=
r:#000"> </span><span style=3D"color:#800">//type is deduced as int, size i=
s deduced as 6.</span></div></code></div></div></blockquote><div><br></div>=
<div>Yes.</div><div><br></div><blockquote class=3D"gmail_quote" style=3D"ma=
rgin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">=
<div dir=3D"ltr">I'm thinking of a guide like this:<br><br><div style=
=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,187);border-=
style:solid;border-width:1px;word-wrap:break-word"><code><div><span style=
=3D"color:#008">template</span><span style=3D"color:#660"><</span><span =
style=3D"color:#008">typename</span><span style=3D"color:#000"> T</span><sp=
an style=3D"color:#660">></span><span style=3D"color:#000"><br>std</span=
><span style=3D"color:#660">::</span><span style=3D"color:#000">array</span=
><span style=3D"color:#660">(</span><span style=3D"color:#000">T </span><sp=
an style=3D"color:#660">...</span><span style=3D"color:#000">ts</span><span=
style=3D"color:#660">)</span><span style=3D"color:#000"> </span><span styl=
e=3D"color:#660">-></span><span style=3D"color:#000"> std</span><span st=
yle=3D"color:#660">::</span><span style=3D"color:#000">array</span><span st=
yle=3D"color:#660"><</span><span style=3D"color:#000">T</span><span styl=
e=3D"color:#660">,</span><span style=3D"color:#000"> </span><span style=3D"=
color:#008">sizeof</span><span style=3D"color:#660">...(</span><span style=
=3D"color:#000">ts</span><span style=3D"color:#660">);</span></div></code><=
/div></div></blockquote><div>=C2=A0</div><div>The parameter-declaration-cla=
use in a deduction guide is subject to the same restrictions as a function =
declaration. You couldn't declare a function as template<typename T&=
gt; make_array(T... ts) -> std::array<T, sizeof...(ts)>, so likewi=
se you can't declare a deduction guide with that parameter-declaration-=
clause.</div><div>=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"ma=
rgin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">=
<div dir=3D"ltr">Or if not that, what about:<br><br><div style=3D"backgroun=
d-color:rgb(250,250,250);border-color:rgb(187,187,187);border-style:solid;b=
order-width:1px;word-wrap:break-word"><code><div><span style=3D"color:#008"=
>template</span><span style=3D"color:#660"><</span><span style=3D"color:=
#008">typename</span><span style=3D"color:#000"> </span><span style=3D"colo=
r:#606">Ts</span><span style=3D"color:#660">...></span><span style=3D"co=
lor:#000"><br>std</span><span style=3D"color:#660">::</span><span style=3D"=
color:#000">array</span><span style=3D"color:#660">(</span><span style=3D"c=
olor:#606">Ts</span><span style=3D"color:#000"> </span><span style=3D"color=
:#660">...</span><span style=3D"color:#000">ts</span><span style=3D"color:#=
660">)</span><span style=3D"color:#000"> </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">array</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">common_type_t</span><span style=3D"co=
lor:#660"><</span><span style=3D"color:#000"><wbr>T</span><span style=3D=
"color:#660">...>,</span><span style=3D"color:#000"> </span><span style=
=3D"color:#008">sizeof</span><span style=3D"color:#660">...(</span><span st=
yle=3D"color:#000">ts</span><span style=3D"color:#660">)>;</span></div><=
/code></div></div></blockquote><div><br></div><div>Now we're talking. T=
his is nearly correct; aside from one or two typos, the only issue is that =
the guide must be declared in the same scope as the template i.e. within na=
mespace std. (I'm pretty sure reopening namespace std is allowed; it=
9;d be odd if it wasn't.)</div><div><br></div><div>Again, think of dedu=
ction guides as shorthand make_XXX functions: the function template templat=
e<class... Ts> make_array(Ts...) -> array<common_type_t<Ts..=
..>, sizeof...(Ts)> is already a member of the standard, so adding the=
corresponding deduction guide should be a matter of course.</div><div><br>=
</div><div>1. http://open-std.org/JTC1/SC22/WG21/docs/papers/2016/p0091r3.h=
tml=C2=A0</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/09b1e9a6-afb0-4463-83b6-d349b000f516%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/09b1e9a6-afb0-4463-83b6-d349b000f516=
%40isocpp.org</a>.<br />
------=_Part_3407_510021657.1469581172663--
------=_Part_3406_248365636.1469581172663--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Tue, 26 Jul 2016 19:34:06 -0700 (PDT)
Raw View
------=_Part_1050_2062164165.1469586846623
Content-Type: multipart/alternative;
boundary="----=_Part_1051_1030962427.1469586846624"
------=_Part_1051_1030962427.1469586846624
Content-Type: text/plain; charset=UTF-8
On Tuesday, July 26, 2016 at 8:59:32 PM UTC-4, Edward Catmur wrote:
>
> On Wednesday, 27 July 2016 00:59:08 UTC+1, Nicol Bolas wrote:
>>
>> Template deduction for constructors allows us to declare a deduction
>> guide that maps from potential usage to the actual template type. These
>> deduction guides do not prevent a type from being an aggregate. [...]
>>
>
> For reference, the proposal series is denoted P0091 and the most recent
> paper is Template argument deduction for class templates (Rev. 6)[1].
>
>
>> Does that mean that it is possible to make this work with `std::array`:
>>
>> auto arr = std::array{2, 3, 1, 4, 44, 23}; //type is deduced as int,
>> size is deduced as 6.
>>
>
> Yes.
>
> I'm thinking of a guide like this:
>>
>> template<typename T>
>> std::array(T ...ts) -> std::array<T, sizeof...(ts);
>>
>
> The parameter-declaration-clause in a deduction guide is subject to the
> same restrictions as a function declaration. You couldn't declare a
> function as template<typename T> make_array(T... ts) -> std::array<T,
> sizeof...(ts)>, so likewise you can't declare a deduction guide with that
> parameter-declaration-clause.
>
>
>> Or if not that, what about:
>>
>> template<typename Ts...>
>> std::array(Ts ...ts) -> std::array<std::common_type_t<T...>, sizeof...(ts
>> )>;
>>
>
> Now we're talking. This is nearly correct; aside from one or two typos,
> the only issue is that the guide must be declared in the same scope as the
> template i.e. within namespace std.
>
So... is that guide going to be part of the standard library? Perhaps a
national body comment could get it in?
However, it does raise an interesting limitation. Namely that this would be
subject to the limits that compilers have on parameter packs. It's not
uncommon to do something like this:
SomeType varname[] =
{
//Table of several thousand entries
};
It seems that such a table would easily blow past the compiler's limits on
the number of elements in a pack. It would be so wonderful if there were a
way to avoid having to rely on template packs to count the elements in a
braced-init-list and feed it to a template parameter.
--
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/3baca11b-fbe6-41f6-842d-16e7448a8f6c%40isocpp.org.
------=_Part_1051_1030962427.1469586846624
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Tuesday, July 26, 2016 at 8:59:32 PM UTC-4, Edward Catm=
ur wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: =
0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">On W=
ednesday, 27 July 2016 00:59:08 UTC+1, Nicol Bolas wrote:<blockquote class=
=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc s=
olid;padding-left:1ex"><div dir=3D"ltr">Template deduction for constructors=
allows us to declare a deduction guide that maps from potential usage to t=
he actual template type. These deduction guides do not prevent a type from =
being an aggregate. [...]<br></div></blockquote><div><br></div><div>For ref=
erence, the proposal series is denoted P0091 and the most recent paper is T=
emplate argument deduction for class templates (Rev. 6)[1].</div><div>=C2=
=A0</div><blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.=
8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">Does that=
mean that it is possible to make this work with `std::array`:<br><br><div =
style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,187);bo=
rder-style:solid;border-width:1px;word-wrap:break-word"><code><div><span st=
yle=3D"color:#008">auto</span><span style=3D"color:#000"> arr </span><span =
style=3D"color:#660">=3D</span><span style=3D"color:#000"> std</span><span =
style=3D"color:#660">::</span><span style=3D"color:#000">array</span><span =
style=3D"color:#660">{</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">1</span><span style=3D"color:#660"=
>,</span><span style=3D"color:#000"> </span><span style=3D"color:#066">4</s=
pan><span style=3D"color:#660">,</span><span style=3D"color:#000"> </span><=
span style=3D"color:#066">44</span><span style=3D"color:#660">,</span><span=
style=3D"color:#000"> </span><span style=3D"color:#066">23</span><span sty=
le=3D"color:#660">};</span><span style=3D"color:#000"> </span><span style=
=3D"color:#800">//type is deduced as int, size is deduced as 6.</span></div=
></code></div></div></blockquote><div><br></div><div>Yes.</div><div><br></d=
iv><blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;bo=
rder-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">I'm thinkin=
g of a guide like this:<br><br><div style=3D"background-color:rgb(250,250,2=
50);border-color:rgb(187,187,187);border-style:solid;border-width:1px;word-=
wrap:break-word"><code><div><span style=3D"color:#008">template</span><span=
style=3D"color:#660"><</span><span style=3D"color:#008">typename</span>=
<span style=3D"color:#000"> T</span><span style=3D"color:#660">></span><=
span style=3D"color:#000"><br>std</span><span style=3D"color:#660">::</span=
><span style=3D"color:#000">array</span><span style=3D"color:#660">(</span>=
<span style=3D"color:#000">T </span><span style=3D"color:#660">...</span><s=
pan style=3D"color:#000">ts</span><span style=3D"color:#660">)</span><span =
style=3D"color:#000"> </span><span style=3D"color:#660">-></span><span s=
tyle=3D"color:#000"> std</span><span style=3D"color:#660">::</span><span st=
yle=3D"color:#000">array</span><span style=3D"color:#660"><</span><span =
style=3D"color:#000">T</span><span style=3D"color:#660">,</span><span style=
=3D"color:#000"> </span><span style=3D"color:#008">sizeof</span><span style=
=3D"color:#660">...(</span><span style=3D"color:#000">ts</span><span style=
=3D"color:#660">);</span></div></code></div></div></blockquote><div>=C2=A0<=
/div><div>The parameter-declaration-clause in a deduction guide is subject =
to the same restrictions as a function declaration. You couldn't declar=
e a function as template<typename T> make_array(T... ts) -> std::a=
rray<T, sizeof...(ts)>, so likewise you can't declare a deduction=
guide with that parameter-declaration-clause.</div><div>=C2=A0</div><block=
quote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left=
:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">Or if not that, what abo=
ut:<br><br><div style=3D"background-color:rgb(250,250,250);border-color:rgb=
(187,187,187);border-style:solid;border-width:1px;word-wrap:break-word"><co=
de><div><span style=3D"color:#008">template</span><span style=3D"color:#660=
"><</span><span style=3D"color:#008">typename</span><span style=3D"color=
:#000"> </span><span style=3D"color:#606">Ts</span><span style=3D"color:#66=
0">...></span><span style=3D"color:#000"><br>std</span><span style=3D"co=
lor:#660">::</span><span style=3D"color:#000">array</span><span style=3D"co=
lor:#660">(</span><span style=3D"color:#606">Ts</span><span style=3D"color:=
#000"> </span><span style=3D"color:#660">...</span><span style=3D"color:#00=
0">ts</span><span style=3D"color:#660">)</span><span style=3D"color:#000"> =
</span><span style=3D"color:#660">-></span><span style=3D"color:#000"> s=
td</span><span style=3D"color:#660">::</span><span style=3D"color:#000">arr=
ay</span><span style=3D"color:#660"><</span><span style=3D"color:#000">s=
td</span><span style=3D"color:#660">::</span><span style=3D"color:#000">com=
mon_type_t</span><span style=3D"color:#660"><</span><span style=3D"color=
:#000"><wbr>T</span><span style=3D"color:#660">...>,</span><span style=
=3D"color:#000"> </span><span style=3D"color:#008">sizeof</span><span style=
=3D"color:#660">...(</span><span style=3D"color:#000">ts</span><span style=
=3D"color:#660">)>;</span></div></code></div></div></blockquote><div><br=
></div><div>Now we're talking. This is nearly correct; aside from one o=
r two typos, the only issue is that the guide must be declared in the same =
scope as the template i.e. within namespace std.</div></div></blockquote><d=
iv><br>So... is that guide going to be part of the standard library? Perhap=
s a national body comment could get it in?<br><br>However, it does raise an=
interesting limitation. Namely that this would be subject to the limits th=
at compilers have on parameter packs. It's not uncommon to do something=
like this:<br><br><div class=3D"prettyprint" style=3D"background-color: rg=
b(250, 250, 250); border-color: rgb(187, 187, 187); border-style: solid; bo=
rder-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><div c=
lass=3D"subprettyprint"><span style=3D"color: #606;" class=3D"styled-by-pre=
ttify">SomeType</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> varname</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">[]</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> <br></span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #8=
00;" class=3D"styled-by-prettify">//Table of several thousand entries</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span=
style=3D"color: #660;" class=3D"styled-by-prettify">};</span></div></code>=
</div><br>It seems that such a table would easily blow past the compiler=
9;s limits on the number of elements in a pack. It would be so wonderful if=
there were a way to avoid having to rely on template packs to count the el=
ements in a braced-init-list and feed it to a template parameter.<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/3baca11b-fbe6-41f6-842d-16e7448a8f6c%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/3baca11b-fbe6-41f6-842d-16e7448a8f6c=
%40isocpp.org</a>.<br />
------=_Part_1051_1030962427.1469586846624--
------=_Part_1050_2062164165.1469586846623--
.
Author: Edward Catmur <ed@catmur.co.uk>
Date: Wed, 27 Jul 2016 04:29:40 -0700 (PDT)
Raw View
------=_Part_1097_217341384.1469618980221
Content-Type: multipart/alternative;
boundary="----=_Part_1098_1590454127.1469618980221"
------=_Part_1098_1590454127.1469618980221
Content-Type: text/plain; charset=UTF-8
On Wednesday, 27 July 2016 03:34:06 UTC+1, Nicol Bolas wrote:
>
> On Tuesday, July 26, 2016 at 8:59:32 PM UTC-4, Edward Catmur wrote:
>>
>> On Wednesday, 27 July 2016 00:59:08 UTC+1, Nicol Bolas wrote:
>>>
>>> Or if not that, what about:
>>>
>>
>>> template<typename Ts...>
>>> std::array(Ts ...ts) -> std::array<std::common_type_t<T...>, sizeof...(
>>> ts)>;
>>>
>>
>> Now we're talking. This is nearly correct; aside from one or two typos,
>> the only issue is that the guide must be declared in the same scope as the
>> template i.e. within namespace std.
>>
>
> So... is that guide going to be part of the standard library? Perhaps a
> national body comment could get it in?
>
> However, it does raise an interesting limitation. Namely that this would
> be subject to the limits that compilers have on parameter packs. It's not
> uncommon to do something like this:
>
> SomeType varname[] =
> {
> //Table of several thousand entries
> };
>
> It seems that such a table would easily blow past the compiler's limits on
> the number of elements in a pack. It would be so wonderful if there were a
> way to avoid having to rely on template packs to count the elements in a
> braced-init-list and feed it to a template parameter.
>
A const array reference argument (of form T const (&)[N]) can be deduced
from a braced-init-list, so hopefully the following guide should work,
possibly with an extra level of braces (although brace elision is so
magical that I really couldn't say):
template<class T, unsigned N> auto array(T const (&)[N]) -> array<T, N>;
Annoyingly, this is almost to_array[1] (in the library fundamentals TS v2)
but not quite, since to_array lacks the const qualifier so cannot be called
with a braced-init-list.
I believe it should be fine for this to overload with the heterogeneous
guide above.
1. http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/n4600.html#header.array.synop
--
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/1616ba0d-65d2-4318-afb0-0e333c16dc5b%40isocpp.org.
------=_Part_1098_1590454127.1469618980221
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Wednesday, 27 July 2016 03:34:06 UTC+1, Nicol Bolas wr=
ote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex=
;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">On Tuesda=
y, July 26, 2016 at 8:59:32 PM UTC-4, Edward Catmur wrote:<blockquote class=
=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc s=
olid;padding-left:1ex"><div dir=3D"ltr">On Wednesday, 27 July 2016 00:59:08=
UTC+1, Nicol Bolas wrote:<blockquote class=3D"gmail_quote" style=3D"margi=
n:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=
=3D"ltr">Or if not that, what about:<br></div></blockquote><blockquote clas=
s=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc =
solid;padding-left:1ex"><div dir=3D"ltr"><br><div style=3D"background-color=
:rgb(250,250,250);border-color:rgb(187,187,187);border-style:solid;border-w=
idth:1px;word-wrap:break-word"><code><div><span style=3D"color:#008">templa=
te</span><span style=3D"color:#660"><</span><span style=3D"color:#008">t=
ypename</span><span style=3D"color:#000"> </span><span style=3D"color:#606"=
>Ts</span><span style=3D"color:#660">...></span><span style=3D"color:#00=
0"><br>std</span><span style=3D"color:#660">::</span><span style=3D"color:#=
000">array</span><span style=3D"color:#660">(</span><span style=3D"color:#6=
06">Ts</span><span style=3D"color:#000"> </span><span style=3D"color:#660">=
....</span><span style=3D"color:#000">ts</span><span style=3D"color:#660">)<=
/span><span style=3D"color:#000"> </span><span style=3D"color:#660">-></=
span><span style=3D"color:#000"> std</span><span style=3D"color:#660">::</s=
pan><span style=3D"color:#000">array</span><span style=3D"color:#660"><<=
/span><span style=3D"color:#000">std</span><span style=3D"color:#660">::</s=
pan><span style=3D"color:#000">common_type_t</span><span style=3D"color:#66=
0"><</span><span style=3D"color:#000"><wbr>T</span><span style=3D"color:=
#660">...>,</span><span style=3D"color:#000"> </span><span style=3D"colo=
r:#008">sizeof</span><span style=3D"color:#660">...(</span><span style=3D"c=
olor:#000">ts</span><span style=3D"color:#660">)>;</span></div></code></=
div></div></blockquote><div><br></div><div>Now we're talking. This is n=
early correct; aside from one or two typos, the only issue is that the guid=
e must be declared in the same scope as the template i.e. within namespace =
std.</div></div></blockquote><div><br>So... is that guide going to be part =
of the standard library? Perhaps a national body comment could get it in?<b=
r><br>However, it does raise an interesting limitation. Namely that this wo=
uld be subject to the limits that compilers have on parameter packs. It'=
;s not uncommon to do something like this:<br><br><div style=3D"background-=
color:rgb(250,250,250);border-color:rgb(187,187,187);border-style:solid;bor=
der-width:1px;word-wrap:break-word"><code><div><span style=3D"color:#606">S=
omeType</span><span style=3D"color:#000"> varname</span><span style=3D"colo=
r:#660">[]</span><span style=3D"color:#000"> </span><span style=3D"color:#6=
60">=3D</span><span style=3D"color:#000"> <br></span><span style=3D"color:#=
660">{</span><span style=3D"color:#000"><br></span><span style=3D"color:#80=
0">//Table of several thousand entries</span><span style=3D"color:#000"><br=
></span><span style=3D"color:#660">};</span></div></code></div><br>It seems=
that such a table would easily blow past the compiler's limits on the =
number of elements in a pack. It would be so wonderful if there were a way =
to avoid having to rely on template packs to count the elements in a braced=
-init-list and feed it to a template parameter.<br></div></div></blockquote=
><div><br></div><div>A const array reference argument (of form T const (&am=
p;)[N]) can be deduced from a braced-init-list, so hopefully the following =
guide should work, possibly with an extra level of braces (although brace e=
lision is so magical that I really couldn't say):</div><div><br></div><=
div class=3D"prettyprint" style=3D"border: 1px solid rgb(187, 187, 187); wo=
rd-wrap: break-word; background-color: rgb(250, 250, 250);"><code class=3D"=
prettyprint"><div class=3D"subprettyprint"><span style=3D"color: #008;" cla=
ss=3D"styled-by-prettify">template</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify"><</span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">class</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> T</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </s=
pan><span style=3D"color: #008;" class=3D"styled-by-prettify">unsigned</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> N</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">></span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #008;" class=3D"styled-by-prettify">auto</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> array</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify">T </span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">const</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">(&a=
mp;)[</span><span style=3D"color: #000;" class=3D"styled-by-prettify">N</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">])</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">-></span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> array</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify"><</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify">T</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> N</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">>;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><b=
r></span></div></code></div><div><br></div><div>Annoyingly, this is almost =
to_array[1] (in the library fundamentals TS v2) but not quite, since to_arr=
ay lacks the const qualifier so cannot be called with a braced-init-list.<b=
r></div><div><br></div><div>I believe it should be fine for this to overloa=
d with the heterogeneous guide above.</div><div><br></div><div>1.=C2=A0http=
://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/n4600.html#header.array=
..synop</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/1616ba0d-65d2-4318-afb0-0e333c16dc5b%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/1616ba0d-65d2-4318-afb0-0e333c16dc5b=
%40isocpp.org</a>.<br />
------=_Part_1098_1590454127.1469618980221--
------=_Part_1097_217341384.1469618980221--
.
Author: Edward Catmur <ed@catmur.co.uk>
Date: Wed, 27 Jul 2016 04:39:13 -0700 (PDT)
Raw View
------=_Part_4888_1278229410.1469619554011
Content-Type: multipart/alternative;
boundary="----=_Part_4889_208108385.1469619554012"
------=_Part_4889_208108385.1469619554012
Content-Type: text/plain; charset=UTF-8
On Wednesday, 27 July 2016 12:29:40 UTC+1, Edward Catmur wrote:
>
> On Wednesday, 27 July 2016 03:34:06 UTC+1, Nicol Bolas wrote:
>>
>> On Tuesday, July 26, 2016 at 8:59:32 PM UTC-4, Edward Catmur wrote:
>>>
>>> On Wednesday, 27 July 2016 00:59:08 UTC+1, Nicol Bolas wrote:
>>>>
>>>> Or if not that, what about:
>>>>
>>>
>>>> template<typename Ts...>
>>>> std::array(Ts ...ts) -> std::array<std::common_type_t<T...>, sizeof...(
>>>> ts)>;
>>>>
>>>
>>> Now we're talking. This is nearly correct; aside from one or two typos,
>>> the only issue is that the guide must be declared in the same scope as the
>>> template i.e. within namespace std.
>>>
>>
>> So... is that guide going to be part of the standard library? Perhaps a
>> national body comment could get it in?
>>
>> However, it does raise an interesting limitation. Namely that this would
>> be subject to the limits that compilers have on parameter packs. It's not
>> uncommon to do something like this:
>>
>> SomeType varname[] =
>> {
>> //Table of several thousand entries
>> };
>>
>> It seems that such a table would easily blow past the compiler's limits
>> on the number of elements in a pack. It would be so wonderful if there were
>> a way to avoid having to rely on template packs to count the elements in a
>> braced-init-list and feed it to a template parameter.
>>
>
> A const array reference argument (of form T const (&)[N]) can be deduced
> from a braced-init-list, so hopefully the following guide should work,
> possibly with an extra level of braces (although brace elision is so
> magical that I really couldn't say):
>
> template<class T, unsigned N> auto array(T const (&)[N]) -> array<T, N>;
>
> Annoyingly, this is almost to_array[1] (in the library fundamentals TS v2)
> but not quite, since to_array lacks the const qualifier so cannot be called
> with a braced-init-list.
>
> I believe it should be fine for this to overload with the heterogeneous
> guide above.
>
> 1.
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/n4600.html#header.array.synop
>
I've opened a thread in std-discussion on the to_array
deficiency: https://groups.google.com/a/isocpp.org/forum/?fromgroups#!topic/std-discussion/GS3j9tcXnI0
--
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/b28fd4e1-3f27-4bd0-a59b-0069329bf556%40isocpp.org.
------=_Part_4889_208108385.1469619554012
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Wednesday, 27 July 2016 12:29:40 UTC+1, Edward Catmur =
wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8=
ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">On Wedn=
esday, 27 July 2016 03:34:06 UTC+1, Nicol Bolas wrote:<blockquote class=3D=
"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc soli=
d;padding-left:1ex"><div dir=3D"ltr">On Tuesday, July 26, 2016 at 8:59:32 P=
M UTC-4, Edward Catmur wrote:<blockquote class=3D"gmail_quote" style=3D"mar=
gin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div d=
ir=3D"ltr">On Wednesday, 27 July 2016 00:59:08 UTC+1, Nicol Bolas wrote:<b=
lockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-=
left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">Or if not that, what=
about:<br></div></blockquote><blockquote class=3D"gmail_quote" style=3D"ma=
rgin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div =
dir=3D"ltr"><br><div style=3D"background-color:rgb(250,250,250);border-colo=
r:rgb(187,187,187);border-style:solid;border-width:1px;word-wrap:break-word=
"><code><div><span style=3D"color:#008">template</span><span style=3D"color=
:#660"><</span><span style=3D"color:#008">typename</span><span style=3D"=
color:#000"> </span><span style=3D"color:#606">Ts</span><span style=3D"colo=
r:#660">...></span><span style=3D"color:#000"><br>std</span><span style=
=3D"color:#660">::</span><span style=3D"color:#000">array</span><span style=
=3D"color:#660">(</span><span style=3D"color:#606">Ts</span><span style=3D"=
color:#000"> </span><span style=3D"color:#660">...</span><span style=3D"col=
or:#000">ts</span><span style=3D"color:#660">)</span><span style=3D"color:#=
000"> </span><span style=3D"color:#660">-></span><span style=3D"color:#0=
00"> std</span><span style=3D"color:#660">::</span><span style=3D"color:#00=
0">array</span><span style=3D"color:#660"><</span><span style=3D"color:#=
000">std</span><span style=3D"color:#660">::</span><span style=3D"color:#00=
0">common_type_t</span><span style=3D"color:#660"><</span><span style=3D=
"color:#000"><wbr>T</span><span style=3D"color:#660">...>,</span><span s=
tyle=3D"color:#000"> </span><span style=3D"color:#008">sizeof</span><span s=
tyle=3D"color:#660">...(</span><span style=3D"color:#000">ts</span><span st=
yle=3D"color:#660">)>;</span></div></code></div></div></blockquote><div>=
<br></div><div>Now we're talking. This is nearly correct; aside from on=
e or two typos, the only issue is that the guide must be declared in the sa=
me scope as the template i.e. within namespace std.</div></div></blockquote=
><div><br>So... is that guide going to be part of the standard library? Per=
haps a national body comment could get it in?<br><br>However, it does raise=
an interesting limitation. Namely that this would be subject to the limits=
that compilers have on parameter packs. It's not uncommon to do someth=
ing like this:<br><br><div style=3D"background-color:rgb(250,250,250);borde=
r-color:rgb(187,187,187);border-style:solid;border-width:1px;word-wrap:brea=
k-word"><code><div><span style=3D"color:#606">SomeType</span><span style=3D=
"color:#000"> varname</span><span style=3D"color:#660">[]</span><span style=
=3D"color:#000"> </span><span style=3D"color:#660">=3D</span><span style=3D=
"color:#000"> <br></span><span style=3D"color:#660">{</span><span style=3D"=
color:#000"><br></span><span style=3D"color:#800">//Table of several thousa=
nd entries</span><span style=3D"color:#000"><br></span><span style=3D"color=
:#660">};</span></div></code></div><br>It seems that such a table would eas=
ily blow past the compiler's limits on the number of elements in a pack=
.. It would be so wonderful if there were a way to avoid having to rely on t=
emplate packs to count the elements in a braced-init-list and feed it to a =
template parameter.<br></div></div></blockquote><div><br></div><div>A const=
array reference argument (of form T const (&)[N]) can be deduced from =
a braced-init-list, so hopefully the following guide should work, possibly =
with an extra level of braces (although brace elision is so magical that I =
really couldn't say):</div><div><br></div><div style=3D"border:1px soli=
d rgb(187,187,187);word-wrap:break-word;background-color:rgb(250,250,250)">=
<code><div><span style=3D"color:#008">template</span><span style=3D"color:#=
660"><</span><span style=3D"color:#008">class</span><span style=3D"color=
:#000"> T</span><span style=3D"color:#660">,</span><span style=3D"color:#00=
0"> </span><span style=3D"color:#008">unsigned</span><span style=3D"color:#=
000"> N</span><span style=3D"color:#660">></span><span style=3D"color:#0=
00"> </span><span style=3D"color:#008">auto</span><span style=3D"color:#000=
"> array</span><span style=3D"color:#660">(</span><span style=3D"color:#000=
">T </span><span style=3D"color:#008">const</span><span style=3D"color:#000=
"> </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">=
</span><span style=3D"color:#660">-></span><span style=3D"color:#000"> =
array</span><span style=3D"color:#660"><</span><span style=3D"color:#000=
">T</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"><br=
></span></div></code></div><div><br></div><div>Annoyingly, this is almost t=
o_array[1] (in the library fundamentals TS v2) but not quite, since to_arra=
y lacks the const qualifier so cannot be called with a braced-init-list.<br=
></div><div><br></div><div>I believe it should be fine for this to overload=
with the heterogeneous guide above.</div><div><br></div><div>1.=C2=A0<a hr=
ef=3D"http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/n4600.html#he=
ader.array.synop" target=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.hr=
ef=3D'http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.open-std.org%2Fjt=
c1%2Fsc22%2Fwg21%2Fdocs%2Fpapers%2F2016%2Fn4600.html%23header.array.synop\x=
26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEQbrebgDlsgEqfVJW-gMKkuKRarw';re=
turn true;" onclick=3D"this.href=3D'http://www.google.com/url?q\x3dhttp=
%3A%2F%2Fwww.open-std.org%2Fjtc1%2Fsc22%2Fwg21%2Fdocs%2Fpapers%2F2016%2Fn46=
00.html%23header.array.synop\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEQbreb=
gDlsgEqfVJW-gMKkuKRarw';return true;">http://www.open-std.org/<wbr>jtc1=
/sc22/wg21/docs/papers/<wbr>2016/n4600.html#header.array.<wbr>synop</a></di=
v></div></blockquote><div><br></div><div>I've opened a thread in std-di=
scussion on the to_array deficiency:=C2=A0https://groups.google.com/a/isocp=
p.org/forum/?fromgroups#!topic/std-discussion/GS3j9tcXnI0</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/b28fd4e1-3f27-4bd0-a59b-0069329bf556%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/b28fd4e1-3f27-4bd0-a59b-0069329bf556=
%40isocpp.org</a>.<br />
------=_Part_4889_208108385.1469619554012--
------=_Part_4888_1278229410.1469619554011--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Wed, 27 Jul 2016 07:21:46 -0700 (PDT)
Raw View
------=_Part_196_1645326514.1469629306365
Content-Type: multipart/alternative;
boundary="----=_Part_197_253498945.1469629306365"
------=_Part_197_253498945.1469629306365
Content-Type: text/plain; charset=UTF-8
On Wednesday, July 27, 2016 at 7:29:40 AM UTC-4, Edward Catmur wrote:
>
> On Wednesday, 27 July 2016 03:34:06 UTC+1, Nicol Bolas wrote:
>>
>> On Tuesday, July 26, 2016 at 8:59:32 PM UTC-4, Edward Catmur wrote:
>>>
>>> On Wednesday, 27 July 2016 00:59:08 UTC+1, Nicol Bolas wrote:
>>>>
>>>> Or if not that, what about:
>>>>
>>>
>>>> template<typename Ts...>
>>>> std::array(Ts ...ts) -> std::array<std::common_type_t<T...>, sizeof...(
>>>> ts)>;
>>>>
>>>
>>> Now we're talking. This is nearly correct; aside from one or two typos,
>>> the only issue is that the guide must be declared in the same scope as the
>>> template i.e. within namespace std.
>>>
>>
>> So... is that guide going to be part of the standard library? Perhaps a
>> national body comment could get it in?
>>
>> However, it does raise an interesting limitation. Namely that this would
>> be subject to the limits that compilers have on parameter packs. It's not
>> uncommon to do something like this:
>>
>> SomeType varname[] =
>> {
>> //Table of several thousand entries
>> };
>>
>> It seems that such a table would easily blow past the compiler's limits
>> on the number of elements in a pack. It would be so wonderful if there were
>> a way to avoid having to rely on template packs to count the elements in a
>> braced-init-list and feed it to a template parameter.
>>
>
> A const array reference argument (of form T const (&)[N]) can be deduced
> from a braced-init-list, so hopefully the following guide should work,
> possibly with an extra level of braces (although brace elision is so
> magical that I really couldn't say):
>
> template<class T, unsigned N> auto array(T const (&)[N]) -> array<T, N>;
>
> Annoyingly, this is almost to_array[1] (in the library fundamentals TS v2)
> but not quite, since to_array lacks the const qualifier so cannot be called
> with a braced-init-list.
>
> I believe it should be fine for this to overload with the heterogeneous
> guide above.
>
One more question. Would it be possible to do:
auto variable = array<Typename>{
{/*stuff*/},
{/*stuff*/},
{/*stuff*/},
};
As opposed to:
auto variable = array{
Typename{/*stuff*/},
Typename{/*stuff*/},
Typename{/*stuff*/},
};
--
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/f10bbace-e6c5-4a00-831a-56bfd8b860e4%40isocpp.org.
------=_Part_197_253498945.1469629306365
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Wednesday, July 27, 2016 at 7:29:40 AM UTC-4, E=
dward Catmur wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;mar=
gin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D=
"ltr">On Wednesday, 27 July 2016 03:34:06 UTC+1, Nicol Bolas wrote:<blockq=
uote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:=
1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">On Tuesday, July 26, 2016=
at 8:59:32 PM UTC-4, Edward Catmur wrote:<blockquote class=3D"gmail_quote"=
style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-lef=
t:1ex"><div dir=3D"ltr">On Wednesday, 27 July 2016 00:59:08 UTC+1, Nicol Bo=
las wrote:<blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:=
0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">Or if n=
ot that, what about:<br></div></blockquote><blockquote class=3D"gmail_quote=
" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-le=
ft:1ex"><div dir=3D"ltr"><br><div style=3D"background-color:rgb(250,250,250=
);border-color:rgb(187,187,187);border-style:solid;border-width:1px;word-wr=
ap:break-word"><code><div><span style=3D"color:#008">template</span><span s=
tyle=3D"color:#660"><</span><span style=3D"color:#008">typename</span><s=
pan style=3D"color:#000"> </span><span style=3D"color:#606">Ts</span><span =
style=3D"color:#660">...></span><span style=3D"color:#000"><br>std</span=
><span style=3D"color:#660">::</span><span style=3D"color:#000">array</span=
><span style=3D"color:#660">(</span><span style=3D"color:#606">Ts</span><sp=
an style=3D"color:#000"> </span><span style=3D"color:#660">...</span><span =
style=3D"color:#000">ts</span><span style=3D"color:#660">)</span><span styl=
e=3D"color:#000"> </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">array</span><span style=3D"color:#660"><</span><span sty=
le=3D"color:#000">std</span><span style=3D"color:#660">::</span><span style=
=3D"color:#000">common_type_t</span><span style=3D"color:#660"><</span><=
span style=3D"color:#000"><wbr>T</span><span style=3D"color:#660">...>,<=
/span><span style=3D"color:#000"> </span><span style=3D"color:#008">sizeof<=
/span><span style=3D"color:#660">...(</span><span style=3D"color:#000">ts</=
span><span style=3D"color:#660">)>;</span></div></code></div></div></blo=
ckquote><div><br></div><div>Now we're talking. This is nearly correct; =
aside from one or two typos, the only issue is that the guide must be decla=
red in the same scope as the template i.e. within namespace std.</div></div=
></blockquote><div><br>So... is that guide going to be part of the standard=
library? Perhaps a national body comment could get it in?<br><br>However, =
it does raise an interesting limitation. Namely that this would be subject =
to the limits that compilers have on parameter packs. It's not uncommon=
to do something like this:<br><br><div style=3D"background-color:rgb(250,2=
50,250);border-color:rgb(187,187,187);border-style:solid;border-width:1px;w=
ord-wrap:break-word"><code><div><span style=3D"color:#606">SomeType</span><=
span style=3D"color:#000"> varname</span><span style=3D"color:#660">[]</spa=
n><span style=3D"color:#000"> </span><span style=3D"color:#660">=3D</span><=
span style=3D"color:#000"> <br></span><span style=3D"color:#660">{</span><s=
pan style=3D"color:#000"><br></span><span style=3D"color:#800">//Table of s=
everal thousand entries</span><span style=3D"color:#000"><br></span><span s=
tyle=3D"color:#660">};</span></div></code></div><br>It seems that such a ta=
ble would easily blow past the compiler's limits on the number of eleme=
nts in a pack. It would be so wonderful if there were a way to avoid having=
to rely on template packs to count the elements in a braced-init-list and =
feed it to a template parameter.<br></div></div></blockquote><div><br></div=
><div>A const array reference argument (of form T const (&)[N]) can be =
deduced from a braced-init-list, so hopefully the following guide should wo=
rk, possibly with an extra level of braces (although brace elision is so ma=
gical that I really couldn't say):</div><div><br></div><div style=3D"bo=
rder:1px solid rgb(187,187,187);word-wrap:break-word;background-color:rgb(2=
50,250,250)"><code><div><span style=3D"color:#008">template</span><span sty=
le=3D"color:#660"><</span><span style=3D"color:#008">class</span><span s=
tyle=3D"color:#000"> T</span><span style=3D"color:#660">,</span><span style=
=3D"color:#000"> </span><span style=3D"color:#008">unsigned</span><span sty=
le=3D"color:#000"> N</span><span style=3D"color:#660">></span><span styl=
e=3D"color:#000"> </span><span style=3D"color:#008">auto</span><span style=
=3D"color:#000"> array</span><span style=3D"color:#660">(</span><span style=
=3D"color:#000">T </span><span style=3D"color:#008">const</span><span style=
=3D"color:#000"> </span><span style=3D"color:#660">(&)[</span><span sty=
le=3D"color:#000">N</span><span style=3D"color:#660">])</span><span style=
=3D"color:#000"> </span><span style=3D"color:#660">-></span><span style=
=3D"color:#000"> array</span><span style=3D"color:#660"><</span><span st=
yle=3D"color:#000">T</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"><br></span></div></code></div><div><br></div><div>Annoyingl=
y, this is almost to_array[1] (in the library fundamentals TS v2) but not q=
uite, since to_array lacks the const qualifier so cannot be called with a b=
raced-init-list.<br></div><div><br></div><div>I believe it should be fine f=
or this to overload with the heterogeneous guide above.</div></div></blockq=
uote><div><br>One more question. Would it be possible to do:<br><br><div cl=
ass=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); border-c=
olor: rgb(187, 187, 187); border-style: solid; border-width: 1px; word-wrap=
: break-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><s=
pan style=3D"color: #008;" class=3D"styled-by-prettify">auto</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> variable </span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> array</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify"><</span><span style=3D"color: #60=
6;" class=3D"styled-by-prettify">Typename</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">>{</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"><br>=C2=A0 </span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">{</span><span style=3D"color: #800;" class=3D"st=
yled-by-prettify">/*stuff*/</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">},</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br>=C2=A0 </span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">{</span><span style=3D"color: #800;" class=3D"styled-by-prettify"=
>/*stuff*/</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
},</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=
=A0 </span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</spa=
n><span style=3D"color: #800;" class=3D"styled-by-prettify">/*stuff*/</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">},</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">};</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"><br></span></div></code></div><br>As=
opposed to:<br><br><div class=3D"prettyprint" style=3D"background-color: r=
gb(250, 250, 250); border-color: rgb(187, 187, 187); border-style: solid; b=
order-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><div =
class=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled-by-pr=
ettify">auto</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> variable </span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> arra=
y</span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 </span>=
<span style=3D"color: #606;" class=3D"styled-by-prettify">Typename</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=
=3D"color: #800;" class=3D"styled-by-prettify">/*stuff*/</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">},</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"><br>=C2=A0 </span><span style=3D"col=
or: #606;" class=3D"styled-by-prettify">Typename</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #800;" =
class=3D"styled-by-prettify">/*stuff*/</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">},</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"><br>=C2=A0 </span><span style=3D"color: #606;" class=3D=
"styled-by-prettify">Typename</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">{</span><span style=3D"color: #800;" class=3D"styled-by-=
prettify">/*stuff*/</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">},</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
><br></span><span style=3D"color: #660;" class=3D"styled-by-prettify">};</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span></=
div></code></div></div><br></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/f10bbace-e6c5-4a00-831a-56bfd8b860e4%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/f10bbace-e6c5-4a00-831a-56bfd8b860e4=
%40isocpp.org</a>.<br />
------=_Part_197_253498945.1469629306365--
------=_Part_196_1645326514.1469629306365--
.