Topic: Zero-length parameter pack expansion of specific type


Author: NDos Dannyu <ndospark320@naver.com>
Date: Sat, 10 Sep 2016 17:39:13 -0700 (PDT)
Raw View
------=_Part_8922_1654272487.1473554353135
Content-Type: multipart/alternative;
 boundary="----=_Part_8923_727349586.1473554353135"

------=_Part_8923_727349586.1473554353135
Content-Type: text/plain; charset=UTF-8

In the former draft of fold expression, zero-length parameter pack
expansion returned the identity element of the operator used.
For example, zero-length parameter pack expansion of operator + returned 0,
or of operator & returned -1 (bitwise all ones), etc.
But this feature was removed from the draft for some reasons. I thought it
was so cool...
But what if the type of the parameter pack is specific?
For example, if the parameter pack were declared like *int ...Args*? if
Args is empty, *(Args + ...)* can return 0, quite logical and no problem.
So if the type of the parameter pack is specific, zero-length parameter
pack expansion can return the identity element with no problem.
So I propose a way to define the result of zero-length parameter pack
expansion. For example,
*std::string operator + (**std::string...**) {*
*    return std::string("");*
*}*
(I think there is a better syntax, though.) std::string("") is the identity
element of operator + for std::string, so this is logical.
If the result of zero-length parameter pack expansion is not the identity
element of the operator, the behavior should be undefined.
If the operator is a template operator, the result of zero-length parameter
pack expansion can be specialized.

--
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/7c828a4d-66cd-4ace-ba48-cca04822a42b%40isocpp.org.

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

<div dir=3D"ltr"><div>In the former draft of fold expression, zero-length p=
arameter pack expansion returned the identity element of the operator used.=
</div><div>For example, zero-length parameter pack expansion of operator + =
returned 0, or of operator &amp; returned -1 (bitwise all ones), etc.</div>=
<div>But this feature was removed from the draft for some reasons. I though=
t it was so cool...</div><div>But what if the type of the parameter pack=C2=
=A0is specific?</div><div>For example, if the parameter pack were declared =
like <b>int ...Args</b>? if Args=C2=A0is empty, <b>(Args + ...)</b> can ret=
urn 0, quite logical and no problem.</div><div>So if the type of the parame=
ter pack=C2=A0is specific, zero-length parameter pack expansion can return =
the identity element with no problem.</div><div>So I propose a way to defin=
e the result of zero-length parameter pack expansion. For example,</div><di=
v><b>std::string operator + (</b><b>std::string...</b><b>) {</b></div><div>=
<b>=C2=A0=C2=A0=C2=A0 return std::string(&quot;&quot;);</b></div><div><b>}<=
/b></div><div>(I think there is a better syntax, though.) std::string(&quot=
;&quot;) is the identity element of operator + for std::string, so this is =
logical.</div><div>If the result of zero-length parameter pack expansion is=
 not the identity element of the operator, the behavior should be undefined=
..</div><div>If the operator is a template operator, the result of zero-leng=
th parameter pack expansion=C2=A0can be specialized.</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/7c828a4d-66cd-4ace-ba48-cca04822a42b%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/7c828a4d-66cd-4ace-ba48-cca04822a42b=
%40isocpp.org</a>.<br />

------=_Part_8923_727349586.1473554353135--

------=_Part_8922_1654272487.1473554353135--

.


Author: Nicol Bolas <jmckesson@gmail.com>
Date: Sat, 10 Sep 2016 21:36:38 -0700 (PDT)
Raw View
------=_Part_1508_845082500.1473568598582
Content-Type: multipart/alternative;
 boundary="----=_Part_1509_859390328.1473568598583"

------=_Part_1509_859390328.1473568598583
Content-Type: text/plain; charset=UTF-8

This all seems like a complex way to do something that, in most cases, is
very simple.

There are essentially two options as C++17 currently stands. You can always
`if constexpr` around them, using `sizeof...` to test if the pack is empty
before doing a unary fold. You can even use a lambda if you want to keep it
in a single expression. The other option is to use a binary fold with a
neutral default value (where applying the value in the non-empty case will
not change anything). In both cases, you make it explicit what the baseline
will be.

We could even possibly have some kind of generic null operand type, which
can be used with any operators, but will always return a copy/move of the
other 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/bf7a9dcb-266c-40ca-95e1-d5d2e08fbc20%40isocpp.org.

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

<div dir=3D"ltr">This all seems like a complex way to do something that, in=
 most cases, is very simple.<br><br>There are essentially two options as C+=
+17 currently stands. You can always `if constexpr` around them, using `siz=
eof...` to test if the pack is empty before doing a unary fold. You can eve=
n use a lambda if you want to keep it in a single expression. The other opt=
ion is to use a binary fold with a neutral default value (where applying th=
e value in the non-empty case will not change anything). In both cases, you=
 make it explicit what the baseline will be.<br><br>We could even possibly =
have some kind of generic null operand type, which can be used with any ope=
rators, but will always return a copy/move of the other value.<br></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/bf7a9dcb-266c-40ca-95e1-d5d2e08fbc20%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/bf7a9dcb-266c-40ca-95e1-d5d2e08fbc20=
%40isocpp.org</a>.<br />

------=_Part_1509_859390328.1473568598583--

------=_Part_1508_845082500.1473568598582--

.