Topic: Protecting a function parameter pack from further deduction


Author: "'Johannes Schaub' via ISO C++ Standard - Future Proposals" <std-proposals@isocpp.org>
Date: Mon, 22 Aug 2016 22:21:23 +0200
Raw View
Sometimes I would like to say "this function parameter pack must
either be all-explicitly-specified or all deduced", to forbid the
following and other (similar to how "nondeduced<..>::type" can disable
deduction for non-packs)

    template<typename ...T>
    void f(T ...);

    f<int>(1, 2); // oops

This would come handy in class template arg deduction for std::tuple,
because "std::tuple<int> a(1, 2)" could be rejected. I would propose
"protected ..." to be a "non-extensible pack expansion":

    template<typename ...T>
    void f(T protected ...);

    f<int>(1, 2); // error!

Similar, tuple's constructor can be defined as

    tuple(Types && protected ... values);

Do you like the idea?

--
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/CANu6V4XXfE5y3-opxMDSYhvH-vf%2BGCj8BDXhoeFVMS2uj9hDwg%40mail.gmail.com.

.


Author: TONGARI J <tongari95@gmail.com>
Date: Mon, 22 Aug 2016 18:16:09 -0700 (PDT)
Raw View
------=_Part_4233_1746912849.1471914969645
Content-Type: multipart/alternative;
 boundary="----=_Part_4234_608634040.1471914969645"

------=_Part_4234_608634040.1471914969645
Content-Type: text/plain; charset=UTF-8

On Tuesday, August 23, 2016 at 4:21:25 AM UTC+8, Johannes Schaub wrote:
>
> Sometimes I would like to say "this function parameter pack must
> either be all-explicitly-specified or all deduced", to forbid the
> following and other (similar to how "nondeduced<..>::type" can disable
> deduction for non-packs)
>
>     template<typename ...T>
>     void f(T ...);
>
>     f<int>(1, 2); // oops
>
> This would come handy in class template arg deduction for std::tuple,
> because "std::tuple<int> a(1, 2)" could be rejected. I would propose
> "protected ..." to be a "non-extensible pack expansion":
>
>     template<typename ...T>
>     void f(T protected ...);
>
>     f<int>(1, 2); // error!
>
> Similar, tuple's constructor can be defined as
>
>     tuple(Types && protected ... values);
>
> Do you like the idea?
>

You have it already:
template<class T>
struct nodeduced
{
    using type = T;
};

template<class T>
using nodeduced_t = typename nodeduced<T>::type;

template<typename ...T, class...Z>
void f(T ..., nodeduced_t<Z>...) {}

And "std::tuple<int> a(1, 2)" is already rejected, I don't see your point.

--
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/6dda12e3-acbd-40ab-ae5d-afe538fbf308%40isocpp.org.

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

<div dir=3D"ltr">On Tuesday, August 23, 2016 at 4:21:25 AM UTC+8, Johannes =
Schaub wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-le=
ft: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">Sometimes I would=
 like to say &quot;this function parameter pack must
<br>either be all-explicitly-specified or all deduced&quot;, to forbid the
<br>following and other (similar to how &quot;nondeduced&lt;..&gt;::type&qu=
ot; can disable
<br>deduction for non-packs)
<br>
<br>=C2=A0 =C2=A0 template&lt;typename ...T&gt;
<br>=C2=A0 =C2=A0 void f(T ...);
<br>
<br>=C2=A0 =C2=A0 f&lt;int&gt;(1, 2); // oops
<br>
<br>This would come handy in class template arg deduction for std::tuple,
<br>because &quot;std::tuple&lt;int&gt; a(1, 2)&quot; could be rejected. I =
would propose
<br>&quot;protected ...&quot; to be a &quot;non-extensible pack expansion&q=
uot;:
<br>
<br>=C2=A0 =C2=A0 template&lt;typename ...T&gt;
<br>=C2=A0 =C2=A0 void f(T protected ...);
<br>
<br>=C2=A0 =C2=A0 f&lt;int&gt;(1, 2); // error!
<br>
<br>Similar, tuple&#39;s constructor can be defined as
<br>
<br>=C2=A0 =C2=A0 tuple(Types &amp;&amp; protected ... values);
<br>
<br>Do you like the idea?
<br></blockquote><div><br></div><div>You have it already:</div><div class=
=3D"prettyprint" style=3D"border: 1px solid rgb(187, 187, 187); word-wrap: =
break-word; background-color: rgb(250, 250, 250);"><code class=3D"prettypri=
nt"><div class=3D"subprettyprint"><span style=3D"color: #008;" class=3D"sty=
led-by-prettify">template</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">&lt;</span><span style=3D"color: #008;" class=3D"styled-by-p=
rettify">class</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> T</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">struct</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> nodeduced<br></span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span>=
<span style=3D"color: #008;" class=3D"styled-by-prettify">using</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"> type </span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> T</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">};</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"><br><br></span><span style=3D"color: #008;" class=3D"styled-by-p=
rettify">template</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">&lt;</span><span style=3D"color: #008;" class=3D"styled-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-prettify">&gt;</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">using</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> nodeduced_t </span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #0=
08;" class=3D"styled-by-prettify">typename</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> nodeduced</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify">T</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">&gt;::</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify">type</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><b=
r><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">temp=
late</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</=
span><span style=3D"color: #008;" class=3D"styled-by-prettify">typename</sp=
an><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"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"> </span><span style=3D"color: #008;" class=3D"=
styled-by-prettify">class</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">...</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify">Z</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&=
gt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></s=
pan><span style=3D"color: #008;" class=3D"styled-by-prettify">void</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> f</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify">T </span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">...,</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> nodeduced_t</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">&lt;</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify">Z</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">&gt;...)</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"color: #000;" class=3D"styled-by-prettify"> </span=
></div></code></div><div><br></div><div>And &quot;std::tuple&lt;int&gt; a(1=
, 2)&quot; is already rejected, I don&#39;t see your point.</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/6dda12e3-acbd-40ab-ae5d-afe538fbf308%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/6dda12e3-acbd-40ab-ae5d-afe538fbf308=
%40isocpp.org</a>.<br />

------=_Part_4234_608634040.1471914969645--

------=_Part_4233_1746912849.1471914969645--

.