Topic: Does template deduction for constructors


Author: Faisal Vali <faisalv@gmail.com>
Date: Tue, 26 Jul 2016 20:07:36 -0500
Raw View
On Tue, Jul 26, 2016 at 7:59 PM, Edward Catmur <ed@catmur.co.uk> 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. (I'm pretty sure reopening namespace std
> is allowed; it'd be odd if it wasn't.)
>


You can add specializations to namespace std - and you should be able
to add deduction guides too (I hope the wording reflects that).


> 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.

--
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/CABsSTho5JMUuQwODRLWhEk4DJnJaVUwMjCoLxyGyshSZd7FDBw%40mail.gmail.com.

.


Author: =?UTF-8?Q?Daniel_Kr=C3=BCgler?= <daniel.kruegler@gmail.com>
Date: Wed, 27 Jul 2016 16:27:58 +0200
Raw View
2016-07-27 2:59 GMT+02:00 Edward Catmur <ed@catmur.co.uk>:
> On Wednesday, 27 July 2016 00:59:08 UTC+1, Nicol Bolas wrote:
>>
> 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.

make_array is currently only part of the fundamentals TS v2, not yet
part of the working draft for Standard C++. The most recent proposal
requesting it's upgrade is

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0325r1.html

- Daniel

--
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/CAGNvRgD7x-t%2BHjW5Rg2qpmMYqFqT0W6NTcc9iv-Qg7fD2B38Fg%40mail.gmail.com.

.


Author: "'Edward Catmur' via ISO C++ Standard - Future Proposals" <std-proposals@isocpp.org>
Date: Wed, 27 Jul 2016 15:38:44 +0100
Raw View
--001a114cad4c81ede505389ef999
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

On Wed, Jul 27, 2016 at 3:27 PM, Daniel Kr=C3=BCgler <daniel.kruegler@gmail=
..com>
wrote:

> 2016-07-27 2:59 GMT+02:00 Edward Catmur <ed@catmur.co.uk>:
> > On Wednesday, 27 July 2016 00:59:08 UTC+1, Nicol Bolas wrote:
> >>
> > 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 matte=
r
> of
> > course.
>
> make_array is currently only part of the fundamentals TS v2, not yet
> part of the working draft for Standard C++. The most recent proposal
> requesting it's upgrade is
>
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0325r1.html


Sorry, you're right. Thanks for the correction; I'm still getting used to
the status of the TSs.

--=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/CAJnLdOapgPy4WC7%3D0eZVM05bCFrf6j8dVWyi3VLitRYr8=
Tdf_A%40mail.gmail.com.

--001a114cad4c81ede505389ef999
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 W=
ed, Jul 27, 2016 at 3:27 PM, Daniel Kr=C3=BCgler <span dir=3D"ltr">&lt;<a h=
ref=3D"mailto:daniel.kruegler@gmail.com" target=3D"_blank">daniel.kruegler@=
gmail.com</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" style=
=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span cl=
ass=3D"">2016-07-27 2:59 GMT+02:00 Edward Catmur &lt;<a href=3D"mailto:ed@c=
atmur.co.uk">ed@catmur.co.uk</a>&gt;:<br>
&gt; On Wednesday, 27 July 2016 00:59:08 UTC+1, Nicol Bolas wrote:<br>
&gt;&gt;<br>
</span>&gt; Again, think of deduction guides as shorthand make_XXX function=
s: the<br>
&gt; function template template&lt;class... Ts&gt; make_array(Ts...) -&gt;<=
br>
&gt; array&lt;common_type_t&lt;Ts...&gt;, sizeof...(Ts)&gt; is already a me=
mber of the<br>
&gt; standard, so adding the corresponding deduction guide should be a matt=
er of<br>
&gt; course.<br>
<br>
make_array is currently only part of the fundamentals TS v2, not yet<br>
part of the working draft for Standard C++. The most recent proposal<br>
requesting it&#39;s upgrade is<br>
<br>
<a href=3D"http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0325r1.=
html" rel=3D"noreferrer" target=3D"_blank">http://www.open-std.org/jtc1/sc2=
2/wg21/docs/papers/2016/p0325r1.html</a></blockquote><div>=C2=A0</div><div>=
Sorry, you&#39;re right. Thanks for the correction; I&#39;m still getting u=
sed to the status of the TSs.</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&quot; 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/CAJnLdOapgPy4WC7%3D0eZVM05bCFrf6j8dVW=
yi3VLitRYr8Tdf_A%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">h=
ttps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAJnLdOapgPy4WC=
7%3D0eZVM05bCFrf6j8dVWyi3VLitRYr8Tdf_A%40mail.gmail.com</a>.<br />

--001a114cad4c81ede505389ef999--

.


Author: "'Edward Catmur' via ISO C++ Standard - Future Proposals" <std-proposals@isocpp.org>
Date: Wed, 27 Jul 2016 15:43:26 +0100
Raw View
--001a1147578641c73d05389f0aad
Content-Type: text/plain; charset=UTF-8

On Wed, Jul 27, 2016 at 3:21 PM, Nicol Bolas <jmckesson@gmail.com> wrote:

> On Wednesday, July 27, 2016 at 7:29:40 AM UTC-4, Edward Catmur wrote:
>>
>> 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*/},
> };
>
>
That was removed from the proposal between P0091r2 and P0091r3, following
feedback at Oulu (IIRC) that it could lead to unexpected behavior e.g. for
tuple<int, char>{42, 'a', 3.141} the user is most likely expecting an
error, not a 3-element tuple<int, char, double>.

Perhaps a metafunction might work here; otherwise you could probably cope
using to_array and mandatory RVO.

--
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/CAJnLdOaRkUnkqLs1vMi9xVnmiTn4aYtJeQUNQh4mQhqTPvCUEA%40mail.gmail.com.

--001a1147578641c73d05389f0aad
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 W=
ed, Jul 27, 2016 at 3:21 PM, Nicol Bolas <span dir=3D"ltr">&lt;<a href=3D"m=
ailto:jmckesson@gmail.com" target=3D"_blank">jmckesson@gmail.com</a>&gt;</s=
pan> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex=
;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">On Wednesday=
, July 27, 2016 at 7:29:40 AM 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"><div>A const array reference argume=
nt (of form T const (&amp;)[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&#39;t say=
):</div><div><br></div><div style=3D"border:1px solid 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">&lt;</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:#000"> </span><span style=
=3D"color:#008">unsigned</span><span style=3D"color:#000"> N</span><span st=
yle=3D"color:#660">&gt;</span><span style=3D"color:#000"> </span><span styl=
e=3D"color:#008">auto</span><span style=3D"color:#000"> array</span><span s=
tyle=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">(&amp;)[</span><span style=3D"color:#000">N</span><span sty=
le=3D"color:#660">])</span><span style=3D"color:#000"> </span><span style=
=3D"color:#660">-&gt;</span><span style=3D"color:#000"> array</span><span s=
tyle=3D"color:#660">&lt;</span><span style=3D"color:#000">T</span><span sty=
le=3D"color:#660">,</span><span style=3D"color:#000"> N</span><span style=
=3D"color:#660">&gt;;</span><span style=3D"color:#000"><br></span></div></c=
ode></div><div><br></div><div>Annoyingly, this is almost to_array[1] (in th=
e library fundamentals TS v2) but not quite, since to_array 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 heterog=
eneous guide above.</div></div></blockquote><div><br>One more question. Wou=
ld it be possible to do:<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">auto</span><span st=
yle=3D"color:#000"> variable </span><span style=3D"color:#660">=3D</span><s=
pan style=3D"color:#000"> array</span><span style=3D"color:#660">&lt;</span=
><span style=3D"color:#606">Typename</span><span style=3D"color:#660">&gt;{=
</span><span style=3D"color:#000"><br>=C2=A0 </span><span style=3D"color:#6=
60">{</span><span style=3D"color:#800">/*stuff*/</span><span style=3D"color=
:#660">},</span><span style=3D"color:#000"><br>=C2=A0 </span><span style=3D=
"color:#660">{</span><span style=3D"color:#800">/*stuff*/</span><span style=
=3D"color:#660">},</span><span style=3D"color:#000"><br>=C2=A0 </span><span=
 style=3D"color:#660">{</span><span style=3D"color:#800">/*stuff*/</span><s=
pan style=3D"color:#660">},</span><span style=3D"color:#000"><br></span><sp=
an style=3D"color:#660">};</span><span style=3D"color:#000"><br></span></di=
v></code></div><br>As opposed to:<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">auto</span=
><span style=3D"color:#000"> variable </span><span style=3D"color:#660">=3D=
</span><span style=3D"color:#000"> array</span><span style=3D"color:#660">{=
</span><span style=3D"color:#000"><br>=C2=A0 </span><span style=3D"color:#6=
06">Typename</span><span style=3D"color:#660">{</span><span style=3D"color:=
#800">/*stuff*/</span><span style=3D"color:#660">},</span><span style=3D"co=
lor:#000"><br>=C2=A0 </span><span style=3D"color:#606">Typename</span><span=
 style=3D"color:#660">{</span><span style=3D"color:#800">/*stuff*/</span><s=
pan style=3D"color:#660">},</span><span style=3D"color:#000"><br>=C2=A0 </s=
pan><span style=3D"color:#606">Typename</span><span style=3D"color:#660">{<=
/span><span style=3D"color:#800">/*stuff*/</span><span style=3D"color:#660"=
>},</span><span style=3D"color:#000"><br></span><span style=3D"color:#660">=
};</span><span class=3D"HOEnZb"><font color=3D"#888888"><span style=3D"colo=
r:#000"><br></span></font></span></div></code></div></div><span class=3D"HO=
EnZb"><font color=3D"#888888"><br></font></span></div></blockquote><div><br=
></div><div>That was removed from the proposal between P0091r2 and P0091r3,=
 following feedback at Oulu (IIRC) that it could lead to unexpected behavio=
r e.g. for tuple&lt;int, char&gt;{42, &#39;a&#39;, 3.141} the user is most =
likely expecting an error, not a 3-element tuple&lt;int, char, double&gt;.<=
/div></div><br></div><div class=3D"gmail_extra">Perhaps a metafunction migh=
t work here; otherwise you could probably cope using to_array and mandatory=
 RVO.</div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; 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/CAJnLdOaRkUnkqLs1vMi9xVnmiTn4aYtJeQUN=
Qh4mQhqTPvCUEA%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">htt=
ps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAJnLdOaRkUnkqLs1=
vMi9xVnmiTn4aYtJeQUNQh4mQhqTPvCUEA%40mail.gmail.com</a>.<br />

--001a1147578641c73d05389f0aad--

.


Author: "'Edward Catmur' via ISO C++ Standard - Future Proposals" <std-proposals@isocpp.org>
Date: Wed, 27 Jul 2016 16:32:22 +0100
Raw View
--001a1147578646671905389fb944
Content-Type: text/plain; charset=UTF-8

On Wed, Jul 27, 2016 at 4:18 PM, Nicol Bolas <jmckesson@gmail.com> wrote:

> On Wednesday, July 27, 2016 at 10:43:28 AM UTC-4, Edward Catmur wrote:
>>
>> On Wed, Jul 27, 2016 at 3:21 PM, Nicol Bolas <jmck...@gmail.com> wrote:
>>
>>> 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*/},
>>> };
>>>
>>>
>> That was removed from the proposal between P0091r2 and P0091r3, following
>> feedback at Oulu (IIRC) that it could lead to unexpected behavior e.g. for
>> tuple<int, char>{42, 'a', 3.141} the user is most likely expecting an
>> error, not a 3-element tuple<int, char, double>.
>>
>> Perhaps a metafunction might work here; otherwise you could probably cope
>> using to_array and mandatory RVO.
>>
>
> `to_array` takes an array as a parameter. You cannot elide the copy from a
> parameter to an output value.
>

Guh, sorry. Not thinking straight today. And a metafunction won't work
either, since the guide has to operate on a class template directly. All I
can think of that would work is inheritance, but it's pretty ugly:

template<class T> struct array_of {
>     template<size_t N> struct type : array<T, N> {};
>     template<size_t N> auto type(T const (&)[N]) -> type<N>;
> }
> auto variable = array_of<Typename>::type{...};

--
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/CAJnLdOZOVfiF8dZ1goNhZePVPRqKbCKQ7H%3DJSsGtUHetf9YjnA%40mail.gmail.com.

--001a1147578646671905389fb944
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 W=
ed, Jul 27, 2016 at 4:18 PM, Nicol Bolas <span dir=3D"ltr">&lt;<a href=3D"m=
ailto:jmckesson@gmail.com" target=3D"_blank">jmckesson@gmail.com</a>&gt;</s=
pan> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0p=
x 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-lef=
t-style:solid;padding-left:1ex"><div dir=3D"ltr">On Wednesday, July 27, 201=
6 at 10:43:28 AM UTC-4, Edward Catmur wrote:<blockquote class=3D"gmail_quot=
e" style=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-colo=
r:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir=3D"lt=
r"><div><div class=3D"gmail_quote">On Wed, Jul 27, 2016 at 3:21 PM, Nicol B=
olas <span dir=3D"ltr">&lt;<a rel=3D"nofollow">jmck...@gmail.com</a>&gt;</s=
pan> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0p=
x 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-lef=
t-style:solid;padding-left:1ex"><div dir=3D"ltr"><div>One more question. Wo=
uld it be possible to do:<br><br><div style=3D"border:1px solid rgb(187,187=
,187);word-wrap:break-word;background-color:rgb(250,250,250)"><code><div><s=
pan style=3D"color:rgb(0,0,136)">auto</span><span style=3D"color:rgb(0,0,0)=
"> variable </span><span style=3D"color:rgb(102,102,0)">=3D</span><span sty=
le=3D"color:rgb(0,0,0)"> array</span><span style=3D"color:rgb(102,102,0)">&=
lt;</span><span style=3D"color:rgb(102,0,102)">Typename</span><span style=
=3D"color:rgb(102,102,0)">&gt;{</span><span style=3D"color:rgb(0,0,0)"><br>=
=C2=A0 </span><span style=3D"color:rgb(102,102,0)">{</span><span style=3D"c=
olor:rgb(136,0,0)">/*stuff*/</span><span style=3D"color:rgb(102,102,0)">},<=
/span><span style=3D"color:rgb(0,0,0)"><br>=C2=A0 </span><span style=3D"col=
or:rgb(102,102,0)">{</span><span style=3D"color:rgb(136,0,0)">/*stuff*/</sp=
an><span style=3D"color:rgb(102,102,0)">},</span><span style=3D"color:rgb(0=
,0,0)"><br>=C2=A0 </span><span style=3D"color:rgb(102,102,0)">{</span><span=
 style=3D"color:rgb(136,0,0)">/*stuff*/</span><span style=3D"color:rgb(102,=
102,0)">},</span><span style=3D"color:rgb(0,0,0)"><br></span><span style=3D=
"color:rgb(102,102,0)">};</span><span style=3D"color:rgb(0,0,0)"><br></span=
></div></code></div><br>As opposed to:<br><br><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:rgb(0,0,136)">auto</span><span style=3D"col=
or:rgb(0,0,0)"> variable </span><span style=3D"color:rgb(102,102,0)">=3D</s=
pan><span style=3D"color:rgb(0,0,0)"> array</span><span style=3D"color:rgb(=
102,102,0)">{</span><span style=3D"color:rgb(0,0,0)"><br>=C2=A0 </span><spa=
n style=3D"color:rgb(102,0,102)">Typename</span><span style=3D"color:rgb(10=
2,102,0)">{</span><span style=3D"color:rgb(136,0,0)">/*stuff*/</span><span =
style=3D"color:rgb(102,102,0)">},</span><span style=3D"color:rgb(0,0,0)"><b=
r>=C2=A0 </span><span style=3D"color:rgb(102,0,102)">Typename</span><span s=
tyle=3D"color:rgb(102,102,0)">{</span><span style=3D"color:rgb(136,0,0)">/*=
stuff*/</span><span style=3D"color:rgb(102,102,0)">},</span><span style=3D"=
color:rgb(0,0,0)"><br>=C2=A0 </span><span style=3D"color:rgb(102,0,102)">Ty=
pename</span><span style=3D"color:rgb(102,102,0)">{</span><span style=3D"co=
lor:rgb(136,0,0)">/*stuff*/</span><span style=3D"color:rgb(102,102,0)">},</=
span><span style=3D"color:rgb(0,0,0)"><br></span><span style=3D"color:rgb(1=
02,102,0)">};</span><span><font color=3D"#888888"><span style=3D"color:rgb(=
0,0,0)"><br></span></font></span></div></code></div></div><span><font color=
=3D"#888888"><br></font></span></div></blockquote><div><br></div><div>That =
was removed from the proposal between P0091r2 and P0091r3, following feedba=
ck at Oulu (IIRC) that it could lead to unexpected behavior e.g. for tuple&=
lt;int, char&gt;{42, &#39;a&#39;, 3.141} the user is most likely expecting =
an error, not a 3-element tuple&lt;int, char, double&gt;.</div></div><br></=
div><div>Perhaps a metafunction might work here; otherwise you could probab=
ly cope using to_array and mandatory RVO.</div></div></blockquote><div><br>=
`to_array` takes an array as a parameter. You cannot elide the copy from a =
parameter to an output value.=C2=A0</div></div></blockquote><div><br></div>=
<div>Guh, sorry. Not thinking straight today. And a metafunction won&#39;t =
work either, since the guide has to operate on a class template directly. A=
ll I can think of that would work is inheritance, but it&#39;s pretty ugly:=
=C2=A0</div><div><br></div><blockquote class=3D"gmail_quote" style=3D"margi=
n:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204=
);border-left-style:solid;padding-left:1ex"><font face=3D"monospace, monosp=
ace">template&lt;class T&gt; struct array_of {<br></font><font face=3D"mono=
space, monospace">=C2=A0 =C2=A0 template&lt;size_t N&gt; struct type : arra=
y&lt;T, N&gt; {};<br></font><font face=3D"monospace, monospace">=C2=A0 =C2=
=A0 template&lt;size_t N&gt; auto type(T const (&amp;)[N]) -&gt; type&lt;N&=
gt;;<br></font><font face=3D"monospace, monospace">}<br></font><font face=
=3D"monospace, monospace">auto variable =3D=C2=A0array_of&lt;Typename&gt;::=
type{...};</font></blockquote><div><br></div><div><br></div></div></div></d=
iv>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; 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/CAJnLdOZOVfiF8dZ1goNhZePVPRqKbCKQ7H%3=
DJSsGtUHetf9YjnA%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">h=
ttps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAJnLdOZOVfiF8d=
Z1goNhZePVPRqKbCKQ7H%3DJSsGtUHetf9YjnA%40mail.gmail.com</a>.<br />

--001a1147578646671905389fb944--

.


Author: Nicol Bolas <jmckesson@gmail.com>
Date: Wed, 27 Jul 2016 08:18:05 -0700 (PDT)
Raw View
------=_Part_283_743757723.1469632686070
Content-Type: multipart/alternative;
 boundary="----=_Part_284_257687713.1469632686076"

------=_Part_284_257687713.1469632686076
Content-Type: text/plain; charset=UTF-8

On Wednesday, July 27, 2016 at 10:43:28 AM UTC-4, Edward Catmur wrote:
>
> On Wed, Jul 27, 2016 at 3:21 PM, Nicol Bolas <jmck...@gmail.com
> <javascript:>> wrote:
>
>> On Wednesday, July 27, 2016 at 7:29:40 AM UTC-4, Edward Catmur wrote:
>>>
>>> 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*/},
>> };
>>
>>
> That was removed from the proposal between P0091r2 and P0091r3, following
> feedback at Oulu (IIRC) that it could lead to unexpected behavior e.g. for
> tuple<int, char>{42, 'a', 3.141} the user is most likely expecting an
> error, not a 3-element tuple<int, char, double>.
>
> Perhaps a metafunction might work here; otherwise you could probably cope
> using to_array and mandatory RVO.
>

`to_array` takes an array as a parameter. You cannot elide the copy from a
parameter to an output value.

--
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/49527529-c732-4482-b37c-3f2ba01a38b1%40isocpp.org.

------=_Part_284_257687713.1469632686076
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Wednesday, July 27, 2016 at 10:43:28 AM UTC-4, Edward C=
atmur wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-lef=
t: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><=
div><div class=3D"gmail_quote">On Wed, Jul 27, 2016 at 3:21 PM, Nicol Bolas=
 <span dir=3D"ltr">&lt;<a href=3D"javascript:" target=3D"_blank" gdf-obfusc=
ated-mailto=3D"YyAPBnbxBAAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D&#=
39;javascript:&#39;;return true;" onclick=3D"this.href=3D&#39;javascript:&#=
39;;return true;">jmck...@gmail.com</a>&gt;</span> wrote:<br><blockquote cl=
ass=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;p=
adding-left:1ex"><div dir=3D"ltr">On Wednesday, July 27, 2016 at 7:29:40 AM=
 UTC-4, Edward Catmur wrote:<blockquote class=3D"gmail_quote" style=3D"marg=
in:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div di=
r=3D"ltr"><div>A const array reference argument (of form T const (&amp;)[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&#39;t say):</div><div><br></div><div st=
yle=3D"border:1px solid rgb(187,187,187);word-wrap:break-word;background-co=
lor:rgb(250,250,250)"><code><div><span style=3D"color:#008">template</span>=
<span style=3D"color:#660">&lt;</span><span style=3D"color:#008">class</spa=
n><span style=3D"color:#000"> T</span><span style=3D"color:#660">,</span><s=
pan style=3D"color:#000"> </span><span style=3D"color:#008">unsigned</span>=
<span style=3D"color:#000"> N</span><span style=3D"color:#660">&gt;</span><=
span style=3D"color:#000"> </span><span style=3D"color:#008">auto</span><sp=
an style=3D"color:#000"> array</span><span style=3D"color:#660">(</span><sp=
an style=3D"color:#000">T </span><span style=3D"color:#008">const</span><sp=
an style=3D"color:#000"> </span><span style=3D"color:#660">(&amp;)[</span><=
span style=3D"color:#000">N</span><span style=3D"color:#660">])</span><span=
 style=3D"color:#000"> </span><span style=3D"color:#660">-&gt;</span><span =
style=3D"color:#000"> array</span><span style=3D"color:#660">&lt;</span><sp=
an style=3D"color:#000">T</span><span style=3D"color:#660">,</span><span st=
yle=3D"color:#000"> N</span><span style=3D"color:#660">&gt;;</span><span st=
yle=3D"color:#000"><br></span></div></code></div><div><br></div><div>Annoyi=
ngly, this is almost to_array[1] (in the library fundamentals TS v2) but no=
t quite, since to_array lacks the const qualifier so cannot be called with =
a braced-init-list.<br></div><div><br></div><div>I believe it should be fin=
e for this to overload with the heterogeneous guide above.</div></div></blo=
ckquote><div><br>One more question. Would it be possible to do:<br><br><div=
 style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,187);b=
order-style:solid;border-width:1px;word-wrap:break-word"><code><div><span s=
tyle=3D"color:#008">auto</span><span style=3D"color:#000"> variable </span>=
<span style=3D"color:#660">=3D</span><span style=3D"color:#000"> array</spa=
n><span style=3D"color:#660">&lt;</span><span style=3D"color:#606">Typename=
</span><span style=3D"color:#660">&gt;{</span><span style=3D"color:#000"><b=
r>=C2=A0 </span><span style=3D"color:#660">{</span><span style=3D"color:#80=
0">/*stuff*/</span><span style=3D"color:#660">},</span><span style=3D"color=
:#000"><br>=C2=A0 </span><span style=3D"color:#660">{</span><span style=3D"=
color:#800">/*stuff*/</span><span style=3D"color:#660">},</span><span style=
=3D"color:#000"><br>=C2=A0 </span><span style=3D"color:#660">{</span><span =
style=3D"color:#800">/*stuff*/</span><span style=3D"color:#660">},</span><s=
pan style=3D"color:#000"><br></span><span style=3D"color:#660">};</span><sp=
an style=3D"color:#000"><br></span></div></code></div><br>As opposed to:<br=
><br><div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,1=
87,187);border-style:solid;border-width:1px;word-wrap:break-word"><code><di=
v><span style=3D"color:#008">auto</span><span style=3D"color:#000"> variabl=
e </span><span style=3D"color:#660">=3D</span><span style=3D"color:#000"> a=
rray</span><span style=3D"color:#660">{</span><span style=3D"color:#000"><b=
r>=C2=A0 </span><span style=3D"color:#606">Typename</span><span style=3D"co=
lor:#660">{</span><span style=3D"color:#800">/*stuff*/</span><span style=3D=
"color:#660">},</span><span style=3D"color:#000"><br>=C2=A0 </span><span st=
yle=3D"color:#606">Typename</span><span style=3D"color:#660">{</span><span =
style=3D"color:#800">/*stuff*/</span><span style=3D"color:#660">},</span><s=
pan style=3D"color:#000"><br>=C2=A0 </span><span style=3D"color:#606">Typen=
ame</span><span style=3D"color:#660">{</span><span style=3D"color:#800">/*s=
tuff*/</span><span style=3D"color:#660">},</span><span style=3D"color:#000"=
><br></span><span style=3D"color:#660">};</span><span><font color=3D"#88888=
8"><span style=3D"color:#000"><br></span></font></span></div></code></div><=
/div><span><font color=3D"#888888"><br></font></span></div></blockquote><di=
v><br></div><div>That was removed from the proposal between P0091r2 and P00=
91r3, following feedback at Oulu (IIRC) that it could lead to unexpected be=
havior e.g. for tuple&lt;int, char&gt;{42, &#39;a&#39;, 3.141} the user is =
most likely expecting an error, not a 3-element tuple&lt;int, char, double&=
gt;.</div></div><br></div><div>Perhaps a metafunction might work here; othe=
rwise you could probably cope using to_array and mandatory RVO.</div></div>=
</blockquote><div><br>`to_array` takes an array as a parameter. You cannot =
elide the copy from a parameter to an output value. <br></div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; 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/49527529-c732-4482-b37c-3f2ba01a38b1%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/49527529-c732-4482-b37c-3f2ba01a38b1=
%40isocpp.org</a>.<br />

------=_Part_284_257687713.1469632686076--

------=_Part_283_743757723.1469632686070--

.