Topic: constexpr ternary (was: relaxing rules for
Author: Marc Mutz <marc.mutz@kdab.com>
Date: Sat, 20 May 2017 22:11:42 +0200
Raw View
On 2017-05-20 21:45, ma.kalbfuss@web.de wrote:
> Thanks for your answer. I see the problem now. The condition is a
> runtime condition. So this isn't going to work. But wouldn't it be
> possible for a constexpr condition?
>
> for Example:
>
> auto x = (std::is_integral_v<T>) ? A{} : B{};
>
> This would be like if constexpr with implicit constexpr determinded by
> the compiler.
I had the same idea the other day :)
constexpr-if is explicit, why should the the ternary be different?
auto x = std::is_integral_v<T> constexpr ? A{} : B{};
Thanks,
Marc
--
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/9dbebffff1732ae5966a93b69a836757%40kdab.com.
.
Author: Zhihao Yuan <zy@miator.net>
Date: Sat, 20 May 2017 16:01:31 -0500
Raw View
--94eb2c0b916c473c5a054ffaf1bc
Content-Type: text/plain; charset="UTF-8"
On Sat, May 20, 2017 at 3:11 PM, Marc Mutz <marc.mutz@kdab.com> wrote:
>
>> auto x = (std::is_integral_v<T>) ? A{} : B{};
>>
>> This would be like if constexpr with implicit constexpr determinded by
>> the compiler.
>>
>
> I had the same idea the other day :)
>
> constexpr-if is explicit, why should the the ternary be different?
>
> auto x = std::is_integral_v<T> constexpr ? A{} : B{};
>
Seems not so hard?
auto x = std::conditional_t<std::is_integral_v<T>, A, B>{};
--
Zhihao Yuan, ID lichray
The best way to predict the future is to invent it.
_______________________________________________
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAGsORuBi-W4ZjOiBbmPCErmkEVsa1zehi6fRfXr1EJ%2B%3Dp6meyg%40mail.gmail.com.
--94eb2c0b916c473c5a054ffaf1bc
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div class=3D"gmail_extra"><br><div class=3D"gmail_quote">=
On Sat, May 20, 2017 at 3:11 PM, Marc Mutz <span dir=3D"ltr"><<a href=3D=
"mailto:marc.mutz@kdab.com" target=3D"_blank">marc.mutz@kdab.com</a>></s=
pan> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0p=
x 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><blockquot=
e class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px s=
olid rgb(204,204,204);padding-left:1ex"><br>
auto x =3D (std::is_integral_v<T>) ? A{} : B{};<br>
<br>
This would be like if constexpr with implicit constexpr determinded by<br>
the compiler.<br>
</blockquote>
<br>
I had the same idea the other day :)<br>
<br>
constexpr-if is explicit, why should the the ternary be different?<br>
<br>
=C2=A0 auto x =3D std::is_integral_v<T> constexpr ? A{} : B{};<br>
</blockquote></div><br></div><div class=3D"gmail_extra">Seems not so hard?<=
br></div><div class=3D"gmail_extra"><br></div><div class=3D"gmail_extra">=
=C2=A0 auto x =3D std::conditional_t<std::is_integral_v<T>, A, B&g=
t;{};</div><div class=3D"gmail_extra"><br>-- <br><div class=3D"gmail_signat=
ure"><div dir=3D"ltr"><div><div dir=3D"ltr"><div><div dir=3D"ltr"><div>Zhih=
ao Yuan, ID lichray<br>The best way to predict the future is to invent it.<=
br>_______________________________________________<br></div></div></div></d=
iv></div></div></div>
</div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAGsORuBi-W4ZjOiBbmPCErmkEVsa1zehi6fR=
fXr1EJ%2B%3Dp6meyg%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAGsORuBi-W4Z=
jOiBbmPCErmkEVsa1zehi6fRfXr1EJ%2B%3Dp6meyg%40mail.gmail.com</a>.<br />
--94eb2c0b916c473c5a054ffaf1bc--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Sat, 20 May 2017 14:49:54 -0700 (PDT)
Raw View
------=_Part_1934_186310657.1495316994566
Content-Type: multipart/alternative;
boundary="----=_Part_1935_1953559408.1495316994566"
------=_Part_1935_1953559408.1495316994566
Content-Type: text/plain; charset="UTF-8"
On Saturday, May 20, 2017 at 5:01:33 PM UTC-4, Zhihao Yuan wrote:
>
>
> On Sat, May 20, 2017 at 3:11 PM, Marc Mutz <marc...@kdab.com <javascript:>
> > wrote:
>
>>
>>> auto x = (std::is_integral_v<T>) ? A{} : B{};
>>>
>>> This would be like if constexpr with implicit constexpr determinded by
>>> the compiler.
>>>
>>
>> I had the same idea the other day :)
>>
>> constexpr-if is explicit, why should the the ternary be different?
>>
>> auto x = std::is_integral_v<T> constexpr ? A{} : B{};
>>
>
> Seems not so hard?
>
> auto x = std::conditional_t<std::is_integral_v<T>, A, B>{};
>
>
If all you want to do is select a type, then it's not hard. If you want to
do what the OP suggested (ignoring the fact that his condition was probably
not `constexpr`), that not something you can do with such a tool.
--
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/72a1eb41-3713-4602-84c0-e3fce2cadbd4%40isocpp.org.
------=_Part_1935_1953559408.1495316994566
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Saturday, May 20, 2017 at 5:01:33 PM UTC-4, Zhihao Yuan=
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"><div><=
br><div class=3D"gmail_quote">On Sat, May 20, 2017 at 3:11 PM, Marc Mutz <s=
pan dir=3D"ltr"><<a href=3D"javascript:" target=3D"_blank" gdf-obfuscate=
d-mailto=3D"xX5HGbc4AwAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D'=
javascript:';return true;" onclick=3D"this.href=3D'javascript:'=
;return true;">marc...@kdab.com</a>></span> wrote:<br><blockquote class=
=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rg=
b(204,204,204);padding-left:1ex"><blockquote class=3D"gmail_quote" style=3D=
"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-le=
ft:1ex"><br>
auto x =3D (std::is_integral_v<T>) ? A{} : B{};<br>
<br>
This would be like if constexpr with implicit constexpr determinded by<br>
the compiler.<br>
</blockquote>
<br>
I had the same idea the other day :)<br>
<br>
constexpr-if is explicit, why should the the ternary be different?<br>
<br>
=C2=A0 auto x =3D std::is_integral_v<T> constexpr ? A{} : B{};<br>
</blockquote></div><br></div><div>Seems not so hard?<br></div><div><br></di=
v><div>=C2=A0 auto x =3D std::conditional_t<std::is_<wbr>integral_v<T=
>, A, B>{};</div><br></div></blockquote><div><br>If all you want to d=
o is select a type, then it's not hard. If you want to do what the OP s=
uggested (ignoring the fact that his condition was probably not `constexpr`=
), that not something you can do with such a tool.<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/72a1eb41-3713-4602-84c0-e3fce2cadbd4%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/72a1eb41-3713-4602-84c0-e3fce2cadbd4=
%40isocpp.org</a>.<br />
------=_Part_1935_1953559408.1495316994566--
------=_Part_1934_186310657.1495316994566--
.
Author: Mingxin Wang <wmx16835vv@163.com>
Date: Sat, 20 May 2017 19:54:38 -0700 (PDT)
Raw View
------=_Part_22_959558533.1495335278587
Content-Type: multipart/alternative;
boundary="----=_Part_23_997195927.1495335278587"
------=_Part_23_997195927.1495335278587
Content-Type: text/plain; charset="UTF-8"
On Sunday, May 21, 2017 at 5:49:54 AM UTC+8, Nicol Bolas wrote:
>
> On Saturday, May 20, 2017 at 5:01:33 PM UTC-4, Zhihao Yuan wrote:
>>
>>
>> On Sat, May 20, 2017 at 3:11 PM, Marc Mutz <marc...@kdab.com> wrote:
>>
>>>
>>>> auto x = (std::is_integral_v<T>) ? A{} : B{};
>>>>
>>>> This would be like if constexpr with implicit constexpr determinded by
>>>> the compiler.
>>>>
>>>
>>> I had the same idea the other day :)
>>>
>>> constexpr-if is explicit, why should the the ternary be different?
>>>
>>> auto x = std::is_integral_v<T> constexpr ? A{} : B{};
>>>
>>
>> Seems not so hard?
>>
>> auto x = std::conditional_t<std::is_integral_v<T>, A, B>{};
>>
>>
> If all you want to do is select a type, then it's not hard. If you want to
> do what the OP suggested (ignoring the fact that his condition was probably
> not `constexpr`), that not something you can do with such a tool.
>
If the condition is not "constexpr", and the types are determined at
runtime, the "proxies" and the "wrappers" can be used to solve this
problem.
(https://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/kvkgsHM6wFQ)
--
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/4752662e-21d2-4498-b236-a5dfb7cb2520%40isocpp.org.
------=_Part_23_997195927.1495335278587
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Sunday, May 21, 2017 at 5:49:54 AM UTC+8, Nicol Bolas w=
rote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8e=
x;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">On Satur=
day, May 20, 2017 at 5:01:33 PM UTC-4, Zhihao Yuan 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><br><div class=3D"gmail_quote"=
>On Sat, May 20, 2017 at 3:11 PM, Marc Mutz <span dir=3D"ltr"><<a rel=3D=
"nofollow">marc...@kdab.com</a>></span> wrote:<br><blockquote class=3D"g=
mail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204=
,204,204);padding-left:1ex"><blockquote class=3D"gmail_quote" style=3D"marg=
in:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1e=
x"><br>
auto x =3D (std::is_integral_v<T>) ? A{} : B{};<br>
<br>
This would be like if constexpr with implicit constexpr determinded by<br>
the compiler.<br>
</blockquote>
<br>
I had the same idea the other day :)<br>
<br>
constexpr-if is explicit, why should the the ternary be different?<br>
<br>
=C2=A0 auto x =3D std::is_integral_v<T> constexpr ? A{} : B{};<br>
</blockquote></div><br></div><div>Seems not so hard?<br></div><div><br></di=
v><div>=C2=A0 auto x =3D std::conditional_t<std::is_<wbr>integral_v<T=
>, A, B>{};</div><br></div></blockquote><div><br>If all you want to d=
o is select a type, then it's not hard. If you want to do what the OP s=
uggested (ignoring the fact that his condition was probably not `constexpr`=
), that not something you can do with such a tool.<br></div></div></blockqu=
ote><div><br></div><div>If the condition is not "constexpr",=C2=
=A0=C2=A0and the types are determined at runtime, the "proxies" a=
nd the "wrappers" can be used to solve this problem. (https://gro=
ups.google.com/a/isocpp.org/forum/#!topic/std-proposals/kvkgsHM6wFQ)</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/4752662e-21d2-4498-b236-a5dfb7cb2520%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/4752662e-21d2-4498-b236-a5dfb7cb2520=
%40isocpp.org</a>.<br />
------=_Part_23_997195927.1495335278587--
------=_Part_22_959558533.1495335278587--
.
Author: ma.kalbfuss@web.de
Date: Sun, 21 May 2017 01:31:31 -0700 (PDT)
Raw View
------=_Part_1954_770801191.1495355491510
Content-Type: multipart/alternative;
boundary="----=_Part_1955_663316352.1495355491510"
------=_Part_1955_663316352.1495355491510
Content-Type: text/plain; charset="UTF-8"
introducing constexpr ternary seems like a natural extension.
Explicitly denoting constexpr is a posibility. But i vote against it.
One point of the ternary operator is its shortness in comparison to if
else. Adding an additional constexpr increases the statemanent size.
They tend to get unreadable fastly, anyway. An additional constexpr makes
things worse.
Another point is the position of the constexpr keyword. Where should it go?
There are at least 3 reasonable positions I can think of.
Am Samstag, 20. Mai 2017 22:14:48 UTC+2 schrieb Marc Mutz:
>
> On 2017-05-20 21:45, ma.ka...@web.de <javascript:> wrote:
> > Thanks for your answer. I see the problem now. The condition is a
> > runtime condition. So this isn't going to work. But wouldn't it be
> > possible for a constexpr condition?
> >
> > for Example:
> >
> > auto x = (std::is_integral_v<T>) ? A{} : B{};
> >
> > This would be like if constexpr with implicit constexpr determinded by
> > the compiler.
>
> I had the same idea the other day :)
>
> constexpr-if is explicit, why should the the ternary be different?
>
> auto x = std::is_integral_v<T> constexpr ? A{} : B{};
>
> Thanks,
> Marc
>
>
--
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/38362b79-c21a-4a80-99cd-7bb813b548b3%40isocpp.org.
------=_Part_1955_663316352.1495355491510
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">introducing constexpr ternary seems like a natural extensi=
on.<br><br>Explicitly denoting constexpr is a posibility. But i vote agains=
t it.<br>One point of the ternary operator is its shortness in comparison t=
o if else. Adding an additional constexpr increases the statemanent size.<b=
r>They tend to get unreadable fastly, anyway. An additional constexpr makes=
things worse.<br>Another point is the position of the constexpr keyword. W=
here should it go? There are at least 3 reasonable positions I can think of=
..<br><br><br><br>Am Samstag, 20. Mai 2017 22:14:48 UTC+2 schrieb Marc Mutz:=
<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;bor=
der-left: 1px #ccc solid;padding-left: 1ex;">On 2017-05-20 21:45, <a href=
=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"Jh8A4ik2AwAJ" r=
el=3D"nofollow" onmousedown=3D"this.href=3D'javascript:';return tru=
e;" onclick=3D"this.href=3D'javascript:';return true;">ma.ka...@web=
..de</a> wrote:
<br>> Thanks for your answer. I see the problem now. The condition is a
<br>> runtime condition. So this isn't going to work. But wouldn'=
;t it be
<br>> possible for a constexpr condition?
<br>>=20
<br>> for Example:
<br>>=20
<br>> auto x =3D (std::is_integral_v<T>) ? A{} : B{};
<br>>=20
<br>> This would be like if constexpr with implicit constexpr determinde=
d by
<br>> the compiler.
<br>
<br>I had the same idea the other day :)
<br>
<br>constexpr-if is explicit, why should the the ternary be different?
<br>
<br>=C2=A0 =C2=A0auto x =3D std::is_integral_v<T> constexpr ? A{} : B=
{};
<br>
<br>Thanks,
<br>Marc
<br>
<br></blockquote></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/38362b79-c21a-4a80-99cd-7bb813b548b3%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/38362b79-c21a-4a80-99cd-7bb813b548b3=
%40isocpp.org</a>.<br />
------=_Part_1955_663316352.1495355491510--
------=_Part_1954_770801191.1495355491510--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Sun, 21 May 2017 06:59:43 -0700 (PDT)
Raw View
------=_Part_2262_880569485.1495375183748
Content-Type: multipart/alternative;
boundary="----=_Part_2263_1401191829.1495375183748"
------=_Part_2263_1401191829.1495375183748
Content-Type: text/plain; charset="UTF-8"
On Saturday, May 20, 2017 at 10:54:38 PM UTC-4, Mingxin Wang wrote:
>
> If the condition is not "constexpr", and the types are determined at
> runtime, the "proxies" and the "wrappers" can be used to solve this
> problem. (
> https://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/kvkgsHM6wFQ
> )
>
So long as you're willing to suffer through needless virtual call overhead,
as well as less obvious code, yes.
--
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/f392812b-7d49-4074-9710-93f9fc4262d3%40isocpp.org.
------=_Part_2263_1401191829.1495375183748
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Saturday, May 20, 2017 at 10:54:38 PM UTC-4, Mingxin Wa=
ng 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"><div=
></div><div>If the condition is not "constexpr",=C2=A0=C2=A0and t=
he types are determined at runtime, the "proxies" and the "w=
rappers" can be used to solve this problem. (<a href=3D"https://groups=
..google.com/a/isocpp.org/forum/#!topic/std-proposals/kvkgsHM6wFQ" target=3D=
"_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D'https://groups.go=
ogle.com/a/isocpp.org/forum/#!topic/std-proposals/kvkgsHM6wFQ';return t=
rue;" onclick=3D"this.href=3D'https://groups.google.com/a/isocpp.org/fo=
rum/#!topic/std-proposals/kvkgsHM6wFQ';return true;">https://groups.goo=
gle.com/a/<wbr>isocpp.org/forum/#!topic/std-<wbr>proposals/kvkgsHM6wFQ</a>)=
</div></div></blockquote><div><br>So long as you're willing to suffer t=
hrough needless virtual call overhead, as well as less obvious code, yes.<b=
r></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/f392812b-7d49-4074-9710-93f9fc4262d3%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/f392812b-7d49-4074-9710-93f9fc4262d3=
%40isocpp.org</a>.<br />
------=_Part_2263_1401191829.1495375183748--
------=_Part_2262_880569485.1495375183748--
.
Author: Mingxin Wang <wmx16835vv@163.com>
Date: Sun, 21 May 2017 07:34:08 -0700 (PDT)
Raw View
------=_Part_2200_144066872.1495377248079
Content-Type: multipart/alternative;
boundary="----=_Part_2201_1919695596.1495377248079"
------=_Part_2201_1919695596.1495377248079
Content-Type: text/plain; charset="UTF-8"
If the type cannot be deduced at compile time, then runtime overhead
is inevitable.
On Sunday, May 21, 2017 at 9:59:43 PM UTC+8, Nicol Bolas wrote:
>
> On Saturday, May 20, 2017 at 10:54:38 PM UTC-4, Mingxin Wang wrote:
>>
>> If the condition is not "constexpr", and the types are determined at
>> runtime, the "proxies" and the "wrappers" can be used to solve this
>> problem. (
>> https://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/kvkgsHM6wFQ
>> )
>>
>
> So long as you're willing to suffer through needless virtual call
> overhead, as well as less obvious code, yes.
>
--
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/4df4ee9a-d1e4-40cc-b50b-3109195133fd%40isocpp.org.
------=_Part_2201_1919695596.1495377248079
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><font face=3D"georgia, serif">If the type cannot be deduce=
d at compile time, then runtime overhead is=C2=A0inevitable.</font><br><br>=
On Sunday, May 21, 2017 at 9:59:43 PM UTC+8, Nicol Bolas wrote:<blockquote =
class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1p=
x #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">On Saturday, May 20, 2017=
at 10:54:38 PM UTC-4, Mingxin Wang 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"><div></div><div>If the condition is not "const=
expr",=C2=A0=C2=A0and the types are determined at runtime, the "p=
roxies" and the "wrappers" can be used to solve this problem=
.. (<a href=3D"https://groups.google.com/a/isocpp.org/forum/#!topic/std-prop=
osals/kvkgsHM6wFQ" rel=3D"nofollow" target=3D"_blank" onmousedown=3D"this.h=
ref=3D'https://groups.google.com/a/isocpp.org/forum/#!topic/std-proposa=
ls/kvkgsHM6wFQ';return true;" onclick=3D"this.href=3D'https://group=
s.google.com/a/isocpp.org/forum/#!topic/std-proposals/kvkgsHM6wFQ';retu=
rn true;">https://groups.google.com/a/<wbr>isocpp.org/forum/#!topic/std-<wb=
r>proposals/kvkgsHM6wFQ</a>)</div></div></blockquote><div><br>So long as yo=
u're willing to suffer through needless virtual call overhead, as well =
as less obvious code, yes.<br></div></div></blockquote></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/4df4ee9a-d1e4-40cc-b50b-3109195133fd%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/4df4ee9a-d1e4-40cc-b50b-3109195133fd=
%40isocpp.org</a>.<br />
------=_Part_2201_1919695596.1495377248079--
------=_Part_2200_144066872.1495377248079--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Sun, 21 May 2017 09:40:19 -0700 (PDT)
Raw View
------=_Part_2248_247146924.1495384819170
Content-Type: multipart/alternative;
boundary="----=_Part_2249_1546743412.1495384819170"
------=_Part_2249_1546743412.1495384819170
Content-Type: text/plain; charset="UTF-8"
On Sunday, May 21, 2017 at 10:34:08 AM UTC-4, Mingxin Wang wrote:
>
> If the type cannot be deduced at compile time, then runtime overhead
> is inevitable.
>
And yet, the OP just outlined an implementation that has *zero* runtime
overhead. Or at least trivial overhead: code size and possibly stack
storage. There would be no runtime performance overhead outside of the
initial conditional branch.
Which would be far faster than a virtual function call, or any other form
of type-erasure.
--
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/5eba5825-7ef7-44ad-83ad-6218d874f41e%40isocpp.org.
------=_Part_2249_1546743412.1495384819170
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Sunday, May 21, 2017 at 10:34:08 AM UTC-4, Mingxin Wang=
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"><font =
face=3D"georgia, serif">If the type cannot be deduced at compile time, then=
runtime overhead is=C2=A0inevitable.</font></div></blockquote><div>=C2=A0<=
/div><div>And yet, the OP just outlined an implementation that has <i>zero<=
/i> runtime overhead. Or at least trivial overhead: code size and possibly =
stack storage. There would be no runtime performance overhead outside of th=
e initial conditional branch.<br><br>Which would be far faster than a virtu=
al function call, or any other form of type-erasure.<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/5eba5825-7ef7-44ad-83ad-6218d874f41e%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/5eba5825-7ef7-44ad-83ad-6218d874f41e=
%40isocpp.org</a>.<br />
------=_Part_2249_1546743412.1495384819170--
------=_Part_2248_247146924.1495384819170--
.
Author: Bengt Gustafsson <bengt.gustafsson@beamways.com>
Date: Mon, 22 May 2017 12:57:02 -0700 (PDT)
Raw View
------=_Part_1495_1131943377.1495483022846
Content-Type: multipart/alternative;
boundary="----=_Part_1496_1878082619.1495483022847"
------=_Part_1496_1878082619.1495483022847
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
If we limit ourselves to the constexpr condition case I think this proposal=
=20
has some merit as an if constexpr stateament can't be used to affect the=20
type of a variable that outlives the if statement, which such a constexpr ?=
=20
could.
A general non-constexpr version is in my opinion a far too long step away=
=20
from the C++ type system, and also is very prone to hide type errors where=
=20
you didn't want the compiler to do any trickery to counteract your=20
mistyping, hiding bugs until later in the development cycle.
Den s=C3=B6ndag 21 maj 2017 kl. 04:54:38 UTC+2 skrev Mingxin Wang:
>
> On Sunday, May 21, 2017 at 5:49:54 AM UTC+8, Nicol Bolas wrote:
>>
>> On Saturday, May 20, 2017 at 5:01:33 PM UTC-4, Zhihao Yuan wrote:
>>>
>>>
>>> On Sat, May 20, 2017 at 3:11 PM, Marc Mutz <marc...@kdab.com> wrote:
>>>
>>>>
>>>>> auto x =3D (std::is_integral_v<T>) ? A{} : B{};
>>>>>
>>>>> This would be like if constexpr with implicit constexpr determinded b=
y
>>>>> the compiler.
>>>>>
>>>>
>>>> I had the same idea the other day :)
>>>>
>>>> constexpr-if is explicit, why should the the ternary be different?
>>>>
>>>> auto x =3D std::is_integral_v<T> constexpr ? A{} : B{};
>>>>
>>>
>>> Seems not so hard?
>>>
>>> auto x =3D std::conditional_t<std::is_integral_v<T>, A, B>{};
>>>
>>>
>> If all you want to do is select a type, then it's not hard. If you want=
=20
>> to do what the OP suggested (ignoring the fact that his condition was=20
>> probably not `constexpr`), that not something you can do with such a too=
l.
>>
>
> If the condition is not "constexpr", and the types are determined at=20
> runtime, the "proxies" and the "wrappers" can be used to solve this=20
> problem. (
> https://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/kvkgsH=
M6wFQ
> )
>
--=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/85b404a7-bc13-4737-b71d-c5afc6b4157b%40isocpp.or=
g.
------=_Part_1496_1878082619.1495483022847
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">If we limit ourselves to the constexpr condition case I th=
ink this proposal has some merit as an if constexpr stateament can't be=
used to affect the type of a variable that outlives the if statement, whic=
h such a constexpr ? could.<div><br></div><div>A general non-constexpr vers=
ion is in my opinion a far too long step away from the C++ type system, and=
also is very prone to hide type errors where you didn't want the compi=
ler to do any trickery to counteract your mistyping, hiding bugs until late=
r in the development cycle.<br><div><br><br>Den s=C3=B6ndag 21 maj 2017 kl.=
04:54:38 UTC+2 skrev Mingxin Wang:<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 Sunday, May 21, 2017 at 5:49:54 AM UTC+8, Nicol B=
olas 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 Satu=
rday, May 20, 2017 at 5:01:33 PM UTC-4, Zhihao Yuan 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><br><div class=3D"gmail_quote"=
>On Sat, May 20, 2017 at 3:11 PM, Marc Mutz <span dir=3D"ltr"><<a rel=3D=
"nofollow">marc...@kdab.com</a>></span> wrote:<br><blockquote class=3D"g=
mail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204=
,204,204);padding-left:1ex"><blockquote class=3D"gmail_quote" style=3D"marg=
in:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1e=
x"><br>
auto x =3D (std::is_integral_v<T>) ? A{} : B{};<br>
<br>
This would be like if constexpr with implicit constexpr determinded by<br>
the compiler.<br>
</blockquote>
<br>
I had the same idea the other day :)<br>
<br>
constexpr-if is explicit, why should the the ternary be different?<br>
<br>
=C2=A0 auto x =3D std::is_integral_v<T> constexpr ? A{} : B{};<br>
</blockquote></div><br></div><div>Seems not so hard?<br></div><div><br></di=
v><div>=C2=A0 auto x =3D std::conditional_t<std::is_<wbr>integral_v<T=
>, A, B>{};</div><br></div></blockquote><div><br>If all you want to d=
o is select a type, then it's not hard. If you want to do what the OP s=
uggested (ignoring the fact that his condition was probably not `constexpr`=
), that not something you can do with such a tool.<br></div></div></blockqu=
ote><div><br></div><div>If the condition is not "constexpr",=C2=
=A0=C2=A0and the types are determined at runtime, the "proxies" a=
nd the "wrappers" can be used to solve this problem. (<a href=3D"=
https://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/kvkgsHM6=
wFQ" target=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D'htt=
ps://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/kvkgsHM6wFQ=
';return true;" onclick=3D"this.href=3D'https://groups.google.com/a=
/isocpp.org/forum/#!topic/std-proposals/kvkgsHM6wFQ';return true;">http=
s://groups.google.com/a/<wbr>isocpp.org/forum/#!topic/std-<wbr>proposals/kv=
kgsHM6wFQ</a>)</div></div></blockquote></div></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/85b404a7-bc13-4737-b71d-c5afc6b4157b%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/85b404a7-bc13-4737-b71d-c5afc6b4157b=
%40isocpp.org</a>.<br />
------=_Part_1496_1878082619.1495483022847--
------=_Part_1495_1131943377.1495483022846--
.
Author: "ma.kalbfuss via ISO C++ Standard - Future Proposals" <std-proposals@isocpp.org>
Date: Tue, 23 May 2017 01:07:52 -0700 (PDT)
Raw View
------=_Part_918_1565699535.1495526872701
Content-Type: multipart/alternative;
boundary="----=_Part_919_1961138763.1495526872702"
------=_Part_919_1961138763.1495526872702
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
The hiding of type errors and unwanted exponential growth of the code size=
=20
could be avoided by using an attribute or a different operator symbol.=20
Please ignore the attribute name and the choosen symbol for now. They are=
=20
only placeholers.
auto x =3D runtime_condition [[generic]] ? A{} : B{};=20
or
auto x =3D runtime_condition ?? A{} : B{};
This way, the programmer has to tell the compiler that he want to use the=
=20
generic version. No unexpected exponential growth and no hidden type=20
errors. Maybe this is too much for the upcomming standard. There is no room=
=20
for such an extension. The list of must have features is already too long.=
=20
There is not much room left besides Concepts and Modules, anyway. So this=
=20
will be a proposal for a later standard. I think there are more cases,=20
whrere this technique could be applied. These cases are not explored yet.
Am Montag, 22. Mai 2017 21:57:02 UTC+2 schrieb Bengt Gustafsson:
>
> If we limit ourselves to the constexpr condition case I think this=20
> proposal has some merit as an if constexpr stateament can't be used to=20
> affect the type of a variable that outlives the if statement, which such =
a=20
> constexpr ? could.
>
> A general non-constexpr version is in my opinion a far too long step away=
=20
> from the C++ type system, and also is very prone to hide type errors wher=
e=20
> you didn't want the compiler to do any trickery to counteract your=20
> mistyping, hiding bugs until later in the development cycle.
>
>
> Den s=C3=B6ndag 21 maj 2017 kl. 04:54:38 UTC+2 skrev Mingxin Wang:
>>
>> On Sunday, May 21, 2017 at 5:49:54 AM UTC+8, Nicol Bolas wrote:
>>>
>>> On Saturday, May 20, 2017 at 5:01:33 PM UTC-4, Zhihao Yuan wrote:
>>>>
>>>>
>>>> On Sat, May 20, 2017 at 3:11 PM, Marc Mutz <marc...@kdab.com> wrote:
>>>>
>>>>>
>>>>>> auto x =3D (std::is_integral_v<T>) ? A{} : B{};
>>>>>>
>>>>>> This would be like if constexpr with implicit constexpr determinded =
by
>>>>>> the compiler.
>>>>>>
>>>>>
>>>>> I had the same idea the other day :)
>>>>>
>>>>> constexpr-if is explicit, why should the the ternary be different?
>>>>>
>>>>> auto x =3D std::is_integral_v<T> constexpr ? A{} : B{};
>>>>>
>>>>
>>>> Seems not so hard?
>>>>
>>>> auto x =3D std::conditional_t<std::is_integral_v<T>, A, B>{};
>>>>
>>>>
>>> If all you want to do is select a type, then it's not hard. If you want=
=20
>>> to do what the OP suggested (ignoring the fact that his condition was=
=20
>>> probably not `constexpr`), that not something you can do with such a to=
ol.
>>>
>>
>> If the condition is not "constexpr", and the types are determined at=20
>> runtime, the "proxies" and the "wrappers" can be used to solve this=20
>> problem. (
>> https://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/kvkgs=
HM6wFQ
>> )
>>
>
--=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/aa40be9b-4a58-4f2e-9105-abb5ddf4f73e%40isocpp.or=
g.
------=_Part_919_1961138763.1495526872702
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">The hiding of type errors and unwanted exponential growth =
of the code size could be avoided by using an attribute or a different oper=
ator symbol. Please ignore the attribute name and the choosen symbol for no=
w. They are only placeholers.<br><br><div style=3D"background-color: rgb(25=
0, 250, 250); border-color: rgb(187, 187, 187); border-style: solid; border=
-width: 1px; overflow-wrap: break-word;" class=3D"prettyprint"><code class=
=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color: #008;"=
class=3D"styled-by-prettify">auto</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> x </span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> runtime_condition </span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">[[</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify">generic</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">]]</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"> A</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">{}</span><span style=3D"co=
lor: #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"> B</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">{};</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span></div></code></div><br>or<br><br><code class=3D"prettyprin=
t"><div style=3D"background-color: rgb(250, 250, 250); border-color: rgb(18=
7, 187, 187); border-style: solid; border-width: 1px; overflow-wrap: break-=
word;" class=3D"prettyprint"><code class=3D"prettyprint"><div class=3D"subp=
rettyprint"><span style=3D"color: #008;" class=3D"styled-by-prettify">auto<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> x </span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> runtime_condition </span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">??</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> A</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: #660;" cla=
ss=3D"styled-by-prettify">:</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> B</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">{};</span></div></code></div><span style=3D"color: #660;" class=3D=
"styled-by-prettify"><br></span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"></span></code>This way, the programmer has to tell the compi=
ler that he want to use the generic version. No unexpected exponential grow=
th and no hidden type errors. Maybe this is too much for the upcomming stan=
dard. There is no room for such an extension. The list of must have feature=
s is already too long. There is not much=C2=A0 room left besides Concepts a=
nd Modules, anyway. So this will be a proposal for a later standard. I thin=
k there are more cases, whrere this technique could be applied. These cases=
are not explored yet.<br><br>Am Montag, 22. Mai 2017 21:57:02 UTC+2 schrie=
b Bengt Gustafsson:<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">If we limit ourselves to the constexpr condition case I think this pr=
oposal has some merit as an if constexpr stateament can't be used to af=
fect the type of a variable that outlives the if statement, which such a co=
nstexpr ? could.<div><br></div><div>A general non-constexpr version is in m=
y opinion a far too long step away from the C++ type system, and also is ve=
ry prone to hide type errors where you didn't want the compiler to do a=
ny trickery to counteract your mistyping, hiding bugs until later in the de=
velopment cycle.<br><div><br><br>Den s=C3=B6ndag 21 maj 2017 kl. 04:54:38 U=
TC+2 skrev Mingxin Wang:<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 Sunday, May 21, 2017 at 5:49:54 AM UTC+8, Nicol Bolas wrote:<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">On Saturday, May 20, 201=
7 at 5:01:33 PM UTC-4, Zhihao Yuan 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"><div><br><div class=3D"gmail_quote">On Sat, May 20, =
2017 at 3:11 PM, Marc Mutz <span dir=3D"ltr"><<a rel=3D"nofollow">marc..=
..@kdab.com</a>></span> wrote:<br><blockquote class=3D"gmail_quote" style=
=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding=
-left:1ex"><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.=
8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
auto x =3D (std::is_integral_v<T>) ? A{} : B{};<br>
<br>
This would be like if constexpr with implicit constexpr determinded by<br>
the compiler.<br>
</blockquote>
<br>
I had the same idea the other day :)<br>
<br>
constexpr-if is explicit, why should the the ternary be different?<br>
<br>
=C2=A0 auto x =3D std::is_integral_v<T> constexpr ? A{} : B{};<br>
</blockquote></div><br></div><div>Seems not so hard?<br></div><div><br></di=
v><div>=C2=A0 auto x =3D std::conditional_t<std::is_<wbr>integral_v<T=
>, A, B>{};</div><br></div></blockquote><div><br>If all you want to d=
o is select a type, then it's not hard. If you want to do what the OP s=
uggested (ignoring the fact that his condition was probably not `constexpr`=
), that not something you can do with such a tool.<br></div></div></blockqu=
ote><div><br></div><div>If the condition is not "constexpr",=C2=
=A0=C2=A0and the types are determined at runtime, the "proxies" a=
nd the "wrappers" can be used to solve this problem. (<a href=3D"=
https://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/kvkgsHM6=
wFQ" rel=3D"nofollow" target=3D"_blank" onmousedown=3D"this.href=3D'htt=
ps://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/kvkgsHM6wFQ=
';return true;" onclick=3D"this.href=3D'https://groups.google.com/a=
/isocpp.org/forum/#!topic/std-proposals/kvkgsHM6wFQ';return true;">http=
s://groups.google.com/a/<wbr>isocpp.org/forum/#!topic/std-<wbr>proposals/kv=
kgsHM6wFQ</a>)</div></div></blockquote></div></div></div></blockquote></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/aa40be9b-4a58-4f2e-9105-abb5ddf4f73e%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/aa40be9b-4a58-4f2e-9105-abb5ddf4f73e=
%40isocpp.org</a>.<br />
------=_Part_919_1961138763.1495526872702--
------=_Part_918_1565699535.1495526872701--
.
Author: "ma.kalbfuss via ISO C++ Standard - Future Proposals" <std-proposals@isocpp.org>
Date: Tue, 23 May 2017 01:22:01 -0700 (PDT)
Raw View
------=_Part_3307_379269697.1495527721271
Content-Type: multipart/alternative;
boundary="----=_Part_3308_1235638019.1495527721272"
------=_Part_3308_1235638019.1495527721272
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
I explored other situations where this could be applied.
//generic lambda
[[generic]] [](bool runtime_condition) {
if(runtime_condition) {
return A{};
} else {
return B{};
}
=20
}
// generic function
[[generic]] auto doit(bool runtime_condition) {
if(runtime_condition) {
return A{};
} else {
return B{};
} =20
}
// generic function with generic ternary operator
[[generic]] auto doit(bool runtime_condition) {
return runtime_condition [[generic]] ? A{} : B{};
}
Am Dienstag, 23. Mai 2017 10:07:52 UTC+2 schrieb ma.ka...@googlemail.com:
>
> The hiding of type errors and unwanted exponential growth of the code siz=
e=20
> could be avoided by using an attribute or a different operator symbol.=20
> Please ignore the attribute name and the choosen symbol for now. They are=
=20
> only placeholers.
>
> auto x =3D runtime_condition [[generic]] ? A{} : B{};=20
>
> or
>
> auto x =3D runtime_condition ?? A{} : B{};
>
> This way, the programmer has to tell the compiler that he want to use the=
=20
> generic version. No unexpected exponential growth and no hidden type=20
> errors. Maybe this is too much for the upcomming standard. There is no ro=
om=20
> for such an extension. The list of must have features is already too long=
..=20
> There is not much room left besides Concepts and Modules, anyway. So thi=
s=20
> will be a proposal for a later standard. I think there are more cases,=20
> whrere this technique could be applied. These cases are not explored yet.
>
> Am Montag, 22. Mai 2017 21:57:02 UTC+2 schrieb Bengt Gustafsson:
>>
>> If we limit ourselves to the constexpr condition case I think this=20
>> proposal has some merit as an if constexpr stateament can't be used to=
=20
>> affect the type of a variable that outlives the if statement, which such=
a=20
>> constexpr ? could.
>>
>> A general non-constexpr version is in my opinion a far too long step awa=
y=20
>> from the C++ type system, and also is very prone to hide type errors whe=
re=20
>> you didn't want the compiler to do any trickery to counteract your=20
>> mistyping, hiding bugs until later in the development cycle.
>>
>>
>> Den s=C3=B6ndag 21 maj 2017 kl. 04:54:38 UTC+2 skrev Mingxin Wang:
>>>
>>> On Sunday, May 21, 2017 at 5:49:54 AM UTC+8, Nicol Bolas wrote:
>>>>
>>>> On Saturday, May 20, 2017 at 5:01:33 PM UTC-4, Zhihao Yuan wrote:
>>>>>
>>>>>
>>>>> On Sat, May 20, 2017 at 3:11 PM, Marc Mutz <marc...@kdab.com> wrote:
>>>>>
>>>>>>
>>>>>>> auto x =3D (std::is_integral_v<T>) ? A{} : B{};
>>>>>>>
>>>>>>> This would be like if constexpr with implicit constexpr determinded=
=20
>>>>>>> by
>>>>>>> the compiler.
>>>>>>>
>>>>>>
>>>>>> I had the same idea the other day :)
>>>>>>
>>>>>> constexpr-if is explicit, why should the the ternary be different?
>>>>>>
>>>>>> auto x =3D std::is_integral_v<T> constexpr ? A{} : B{};
>>>>>>
>>>>>
>>>>> Seems not so hard?
>>>>>
>>>>> auto x =3D std::conditional_t<std::is_integral_v<T>, A, B>{};
>>>>>
>>>>>
>>>> If all you want to do is select a type, then it's not hard. If you wan=
t=20
>>>> to do what the OP suggested (ignoring the fact that his condition was=
=20
>>>> probably not `constexpr`), that not something you can do with such a t=
ool.
>>>>
>>>
>>> If the condition is not "constexpr", and the types are determined at=
=20
>>> runtime, the "proxies" and the "wrappers" can be used to solve this=20
>>> problem. (
>>> https://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/kvkg=
sHM6wFQ
>>> )
>>>
>>
--=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/b45e79e3-aebf-4840-86a7-610a2a4d3696%40isocpp.or=
g.
------=_Part_3308_1235638019.1495527721272
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">I explored other situations where this could be applied.<b=
r><br><div style=3D"background-color: rgb(250, 250, 250); border-color: rgb=
(187, 187, 187); border-style: solid; border-width: 1px; overflow-wrap: bre=
ak-word;" class=3D"prettyprint"><code class=3D"prettyprint"><div class=3D"s=
ubprettyprint"><span style=3D"color: #800;" class=3D"styled-by-prettify">//=
generic lambda</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"><br></span><span style=3D"color: #660;" class=3D"styled-by-prettify">[[=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify">generic</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">]]</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">[](</span><span style=3D"col=
or: #008;" class=3D"styled-by-prettify">bool</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> runtime_condition</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">if</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify">runtime_condition</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">)</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">return</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> A</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 =C2=A0 </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">else</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: #0=
00;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><s=
pan style=3D"color: #008;" class=3D"styled-by-prettify">return</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> B</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 =C2=A0 </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 =C2=A0 <br></span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">}</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"><br><br></span><span style=3D"colo=
r: #800;" class=3D"styled-by-prettify">// generic function</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">[[</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify">generic</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"style=
d-by-prettify">auto</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> doit</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">(</span><span style=3D"color: #008;" class=3D"styled-by-prettify">bool<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> runtime_co=
ndition</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">if</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify">runtime_condition</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: #660;" =
class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">return</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> A</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 =C2=A0 </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"style=
d-by-prettify">else</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </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 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">return</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> B</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">{};</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=
=C2=A0 =C2=A0 </span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">}</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =C2=
=A0 =C2=A0<br></span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">}</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><=
br></span><span style=3D"color: #800;" class=3D"styled-by-prettify">// gene=
ric function with generic ternary operator</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">[[</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify">generic</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">]]</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">au=
to</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> doit</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span=
style=3D"color: #008;" class=3D"styled-by-prettify">bool</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> runtime_condition</span><sp=
an 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"color: #000;" =
class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color:=
#008;" class=3D"styled-by-prettify">return</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> runtime_condition </span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">[[</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify">generic</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: #660;" class=3D"style=
d-by-prettify">?</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> A</span><span style=3D"color: #660;" class=3D"styled-by-prettify">{}=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">:</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> B</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">{};</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">}</span></div></code></div><br><br><br><br>Am Die=
nstag, 23. Mai 2017 10:07:52 UTC+2 schrieb ma.ka...@googlemail.com:<blockqu=
ote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left=
: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">The hiding of type er=
rors and unwanted exponential growth of the code size could be avoided by u=
sing an attribute or a different operator symbol. Please ignore the attribu=
te name and the choosen symbol for now. They are only placeholers.<br><br><=
div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,187=
);border-style:solid;border-width:1px"><code><div><span style=3D"color:#008=
">auto</span><span style=3D"color:#000"> x </span><span style=3D"color:#660=
">=3D</span><span style=3D"color:#000"> runtime_condition </span><span styl=
e=3D"color:#660">[[</span><span style=3D"color:#000">generic</span><span st=
yle=3D"color:#660">]]</span><span style=3D"color:#000"> </span><span style=
=3D"color:#660">?</span><span style=3D"color:#000"> A</span><span style=3D"=
color:#660">{}</span><span style=3D"color:#000"> </span><span style=3D"colo=
r:#660">:</span><span style=3D"color:#000"> B</span><span style=3D"color:#6=
60">{};</span><span style=3D"color:#000"> </span></div></code></div><br>or<=
br><br><code><div style=3D"background-color:rgb(250,250,250);border-color:r=
gb(187,187,187);border-style:solid;border-width:1px"><code><div><span style=
=3D"color:#008">auto</span><span style=3D"color:#000"> x </span><span style=
=3D"color:#660">=3D</span><span style=3D"color:#000"> runtime_condition </s=
pan><span style=3D"color:#660">??</span><span style=3D"color:#000"> A</span=
><span style=3D"color:#660">{}</span><span style=3D"color:#000"> </span><sp=
an style=3D"color:#660">:</span><span style=3D"color:#000"> B</span><span s=
tyle=3D"color:#660">{};</span></div></code></div><span style=3D"color:#660"=
><br></span><span style=3D"color:#000"></span></code>This way, the programm=
er has to tell the compiler that he want to use the generic version. No une=
xpected exponential growth and no hidden type errors. Maybe this is too muc=
h for the upcomming standard. There is no room for such an extension. The l=
ist of must have features is already too long. There is not much=C2=A0 room=
left besides Concepts and Modules, anyway. So this will be a proposal for =
a later standard. I think there are more cases, whrere this technique could=
be applied. These cases are not explored yet.<br><br>Am Montag, 22. Mai 20=
17 21:57:02 UTC+2 schrieb Bengt Gustafsson:<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">If we limit ourselves to the constexpr condition c=
ase I think this proposal has some merit as an if constexpr stateament can&=
#39;t be used to affect the type of a variable that outlives the if stateme=
nt, which such a constexpr ? could.<div><br></div><div>A general non-conste=
xpr version is in my opinion a far too long step away from the C++ type sys=
tem, and also is very prone to hide type errors where you didn't want t=
he compiler to do any trickery to counteract your mistyping, hiding bugs un=
til later in the development cycle.<br><div><br><br>Den s=C3=B6ndag 21 maj =
2017 kl. 04:54:38 UTC+2 skrev Mingxin Wang:<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">On Sunday, May 21, 2017 at 5:49:54 AM UTC+8, Nicol=
Bolas 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">On Sa=
turday, May 20, 2017 at 5:01:33 PM UTC-4, Zhihao Yuan wrote:<blockquote cla=
ss=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc=
solid;padding-left:1ex"><div dir=3D"ltr"><div><br><div class=3D"gmail_quot=
e">On Sat, May 20, 2017 at 3:11 PM, Marc Mutz <span dir=3D"ltr"><<a rel=
=3D"nofollow">marc...@kdab.com</a>></span> wrote:<br><blockquote class=
=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rg=
b(204,204,204);padding-left:1ex"><blockquote class=3D"gmail_quote" style=3D=
"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-le=
ft:1ex"><br>
auto x =3D (std::is_integral_v<T>) ? A{} : B{};<br>
<br>
This would be like if constexpr with implicit constexpr determinded by<br>
the compiler.<br>
</blockquote>
<br>
I had the same idea the other day :)<br>
<br>
constexpr-if is explicit, why should the the ternary be different?<br>
<br>
=C2=A0 auto x =3D std::is_integral_v<T> constexpr ? A{} : B{};<br>
</blockquote></div><br></div><div>Seems not so hard?<br></div><div><br></di=
v><div>=C2=A0 auto x =3D std::conditional_t<std::is_<wbr>integral_v<T=
>, A, B>{};</div><br></div></blockquote><div><br>If all you want to d=
o is select a type, then it's not hard. If you want to do what the OP s=
uggested (ignoring the fact that his condition was probably not `constexpr`=
), that not something you can do with such a tool.<br></div></div></blockqu=
ote><div><br></div><div>If the condition is not "constexpr",=C2=
=A0=C2=A0and the types are determined at runtime, the "proxies" a=
nd the "wrappers" can be used to solve this problem. (<a href=3D"=
https://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/kvkgsHM6=
wFQ" rel=3D"nofollow" target=3D"_blank" onmousedown=3D"this.href=3D'htt=
ps://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/kvkgsHM6wFQ=
';return true;" onclick=3D"this.href=3D'https://groups.google.com/a=
/isocpp.org/forum/#!topic/std-proposals/kvkgsHM6wFQ';return true;">http=
s://groups.google.com/a/<wbr>isocpp.org/forum/#!topic/std-<wbr>proposals/kv=
kgsHM6wFQ</a>)</div></div></blockquote></div></div></div></blockquote></div=
></blockquote></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/b45e79e3-aebf-4840-86a7-610a2a4d3696%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/b45e79e3-aebf-4840-86a7-610a2a4d3696=
%40isocpp.org</a>.<br />
------=_Part_3308_1235638019.1495527721272--
------=_Part_3307_379269697.1495527721271--
.
Author: "ma.kalbfuss via ISO C++ Standard - Future Proposals" <std-proposals@isocpp.org>
Date: Tue, 23 May 2017 02:47:30 -0700 (PDT)
Raw View
------=_Part_3249_1005493849.1495532850249
Content-Type: multipart/alternative;
boundary="----=_Part_3250_1487130865.1495532850250"
------=_Part_3250_1487130865.1495532850250
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Further cases where this could be applied:
// generic variable
void doit(bool runtime_condition) {
[[generic]] auto x;
if(runtime_condition) {
x =3D A{};
} else {
x =3D B{};
} =20
}
// generic variable with concept
void doit(bool runtime_condition) {
[[generic]] Iteratable x;
if(runtime_condition) {
x =3D A{};
} else {
x =3D B{};
} =20
}
Am Dienstag, 23. Mai 2017 10:22:01 UTC+2 schrieb ma.ka...@googlemail.com:
>
> I explored other situations where this could be applied.
>
> //generic lambda
> [[generic]] [](bool runtime_condition) {
> if(runtime_condition) {
> return A{};
> } else {
> return B{};
> }
> =20
> }
>
> // generic function
> [[generic]] auto doit(bool runtime_condition) {
> if(runtime_condition) {
> return A{};
> } else {
> return B{};
> } =20
> }
>
> // generic function with generic ternary operator
> [[generic]] auto doit(bool runtime_condition) {
> return runtime_condition [[generic]] ? A{} : B{};
> }
>
>
>
>
> Am Dienstag, 23. Mai 2017 10:07:52 UTC+2 schrieb ma.ka...@googlemail.com:
>>
>> The hiding of type errors and unwanted exponential growth of the code=20
>> size could be avoided by using an attribute or a different operator symb=
ol.=20
>> Please ignore the attribute name and the choosen symbol for now. They ar=
e=20
>> only placeholers.
>>
>> auto x =3D runtime_condition [[generic]] ? A{} : B{};=20
>>
>> or
>>
>> auto x =3D runtime_condition ?? A{} : B{};
>>
>> This way, the programmer has to tell the compiler that he want to use th=
e=20
>> generic version. No unexpected exponential growth and no hidden type=20
>> errors. Maybe this is too much for the upcomming standard. There is no r=
oom=20
>> for such an extension. The list of must have features is already too lon=
g.=20
>> There is not much room left besides Concepts and Modules, anyway. So th=
is=20
>> will be a proposal for a later standard. I think there are more cases,=
=20
>> whrere this technique could be applied. These cases are not explored yet=
..
>>
>> Am Montag, 22. Mai 2017 21:57:02 UTC+2 schrieb Bengt Gustafsson:
>>>
>>> If we limit ourselves to the constexpr condition case I think this=20
>>> proposal has some merit as an if constexpr stateament can't be used to=
=20
>>> affect the type of a variable that outlives the if statement, which suc=
h a=20
>>> constexpr ? could.
>>>
>>> A general non-constexpr version is in my opinion a far too long step=20
>>> away from the C++ type system, and also is very prone to hide type erro=
rs=20
>>> where you didn't want the compiler to do any trickery to counteract you=
r=20
>>> mistyping, hiding bugs until later in the development cycle.
>>>
>>>
>>> Den s=C3=B6ndag 21 maj 2017 kl. 04:54:38 UTC+2 skrev Mingxin Wang:
>>>>
>>>> On Sunday, May 21, 2017 at 5:49:54 AM UTC+8, Nicol Bolas wrote:
>>>>>
>>>>> On Saturday, May 20, 2017 at 5:01:33 PM UTC-4, Zhihao Yuan wrote:
>>>>>>
>>>>>>
>>>>>> On Sat, May 20, 2017 at 3:11 PM, Marc Mutz <marc...@kdab.com> wrote:
>>>>>>
>>>>>>>
>>>>>>>> auto x =3D (std::is_integral_v<T>) ? A{} : B{};
>>>>>>>>
>>>>>>>> This would be like if constexpr with implicit constexpr determinde=
d=20
>>>>>>>> by
>>>>>>>> the compiler.
>>>>>>>>
>>>>>>>
>>>>>>> I had the same idea the other day :)
>>>>>>>
>>>>>>> constexpr-if is explicit, why should the the ternary be different?
>>>>>>>
>>>>>>> auto x =3D std::is_integral_v<T> constexpr ? A{} : B{};
>>>>>>>
>>>>>>
>>>>>> Seems not so hard?
>>>>>>
>>>>>> auto x =3D std::conditional_t<std::is_integral_v<T>, A, B>{};
>>>>>>
>>>>>>
>>>>> If all you want to do is select a type, then it's not hard. If you=20
>>>>> want to do what the OP suggested (ignoring the fact that his conditio=
n was=20
>>>>> probably not `constexpr`), that not something you can do with such a =
tool.
>>>>>
>>>>
>>>> If the condition is not "constexpr", and the types are determined at=
=20
>>>> runtime, the "proxies" and the "wrappers" can be used to solve this=20
>>>> problem. (
>>>> https://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/kvk=
gsHM6wFQ
>>>> )
>>>>
>>>
--=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/35841344-e829-4e86-bba2-12c5f3b0085c%40isocpp.or=
g.
------=_Part_3250_1487130865.1495532850250
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Further cases where this could be applied:<br><br><div sty=
le=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187=
); border-style: solid; border-width: 1px; overflow-wrap: break-word;" clas=
s=3D"prettyprint"><code class=3D"prettyprint"><div class=3D"subprettyprint"=
><span style=3D"color: #800;" class=3D"styled-by-prettify">// generic varia=
ble</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"> doit</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">bool</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> runtime_condition</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: #660;" cla=
ss=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">[[</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify">generic</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">]]</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">aut=
o</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> x</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"><br><br>=C2=A0 =C2=A0 </sp=
an><span style=3D"color: #008;" class=3D"styled-by-prettify">if</span><span=
style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify">runtime_condition</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">)</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 x </span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> A</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">{};</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">}</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styl=
ed-by-prettify">else</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"><br>=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 x </span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> B</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 =C2=A0 </span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">}</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =C2=
=A0 =C2=A0<br></span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">}</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><=
br></span><span style=3D"color: #800;" class=3D"styled-by-prettify">// gene=
ric variable with concept</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br></span><span style=3D"color: #008;" class=3D"styled-by-p=
rettify">void</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> doit</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(<=
/span><span style=3D"color: #008;" class=3D"styled-by-prettify">bool</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> runtime_conditio=
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 styl=
e=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">[[</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify">generic</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">]]</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=3D"s=
tyled-by-prettify">Iteratable</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> x</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"><br><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled=
-by-prettify">if</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">run=
time_condition</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">)</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 x </span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> A</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">{};</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 <=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">}</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">else</span><span style=3D"co=
lor: #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"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 x </span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> B</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">{};</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">}</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> =C2=A0 =C2=A0<br></span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">}</span></div></code></div><br><br><br>Am =
Dienstag, 23. Mai 2017 10:22:01 UTC+2 schrieb ma.ka...@googlemail.com:<bloc=
kquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-l=
eft: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">I explored other s=
ituations where this could be applied.<br><br><div style=3D"background-colo=
r:rgb(250,250,250);border-color:rgb(187,187,187);border-style:solid;border-=
width:1px"><code><div><span style=3D"color:#800">//generic lambda</span><sp=
an style=3D"color:#000"><br></span><span style=3D"color:#660">[[</span><spa=
n style=3D"color:#000">generic</span><span style=3D"color:#660">]]</span><s=
pan style=3D"color:#000"> </span><span style=3D"color:#660">[](</span><span=
style=3D"color:#008">bool</span><span style=3D"color:#000"> runtime_condit=
ion</span><span style=3D"color:#660">)</span><span style=3D"color:#000"> </=
span><span style=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=
=A0 =C2=A0 </span><span style=3D"color:#008">if</span><span style=3D"color:=
#660">(</span><span style=3D"color:#000">runtime_condition</span><span styl=
e=3D"color:#660">)</span><span style=3D"color:#000"> </span><span style=3D"=
color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=
=A0 </span><span style=3D"color:#008">return</span><span style=3D"color:#00=
0"> A</span><span style=3D"color:#660">{};</span><span style=3D"color:#000"=
><br>=C2=A0 =C2=A0 </span><span style=3D"color:#660">}</span><span style=3D=
"color:#000"> </span><span style=3D"color:#008">else</span><span style=3D"c=
olor:#000"> </span><span style=3D"color:#660">{</span><span style=3D"color:=
#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#008">ret=
urn</span><span style=3D"color:#000"> B</span><span style=3D"color:#660">{}=
;</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"=
color:#660">}</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 <br></span=
><span style=3D"color:#660">}</span><span style=3D"color:#000"><br><br></sp=
an><span style=3D"color:#800">// generic function</span><span style=3D"colo=
r:#000"><br></span><span style=3D"color:#660">[[</span><span style=3D"color=
:#000">generic</span><span style=3D"color:#660">]]</span><span style=3D"col=
or:#000"> </span><span style=3D"color:#008">auto</span><span style=3D"color=
:#000"> doit</span><span style=3D"color:#660">(</span><span style=3D"color:=
#008">bool</span><span style=3D"color:#000"> runtime_condition</span><span =
style=3D"color:#660">)</span><span style=3D"color:#000"> </span><span style=
=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span=
><span style=3D"color:#008">if</span><span style=3D"color:#660">(</span><sp=
an style=3D"color:#000">runtime_condition</span><span style=3D"color:#660">=
)</span><span style=3D"color:#000"> </span><span style=3D"color:#660">{</sp=
an><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span =
style=3D"color:#008">return</span><span style=3D"color:#000"> A</span><span=
style=3D"color:#660">{};</span><span style=3D"color:#000"><br>=C2=A0 =C2=
=A0 </span><span style=3D"color:#660">}</span><span style=3D"color:#000"> <=
/span><span style=3D"color:#008">else</span><span style=3D"color:#000"> </s=
pan><span style=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#008">return</span><sp=
an style=3D"color:#000"> B</span><span style=3D"color:#660">{};</span><span=
style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#660">}=
</span><span style=3D"color:#000"> =C2=A0 =C2=A0<br></span><span style=3D"c=
olor:#660">}</span><span style=3D"color:#000"><br><br></span><span style=3D=
"color:#800">// generic function with generic ternary operator</span><span =
style=3D"color:#000"><br></span><span style=3D"color:#660">[[</span><span s=
tyle=3D"color:#000">generic</span><span style=3D"color:#660">]]</span><span=
style=3D"color:#000"> </span><span style=3D"color:#008">auto</span><span s=
tyle=3D"color:#000"> doit</span><span style=3D"color:#660">(</span><span st=
yle=3D"color:#008">bool</span><span style=3D"color:#000"> runtime_condition=
</span><span style=3D"color:#660">)</span><span style=3D"color:#000"> </spa=
n><span style=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 =
=C2=A0 </span><span style=3D"color:#008">return</span><span style=3D"color:=
#000"> runtime_condition </span><span style=3D"color:#660">[[</span><span s=
tyle=3D"color:#000">generic</span><span style=3D"color:#660">]]</span><span=
style=3D"color:#000"> </span><span style=3D"color:#660">?</span><span styl=
e=3D"color:#000"> A</span><span style=3D"color:#660">{}</span><span style=
=3D"color:#000"> </span><span style=3D"color:#660">:</span><span style=3D"c=
olor:#000"> B</span><span style=3D"color:#660">{};</span><span style=3D"col=
or:#000"><br></span><span style=3D"color:#660">}</span></div></code></div><=
br><br><br><br>Am Dienstag, 23. Mai 2017 10:07:52 UTC+2 schrieb <a>ma.ka...=
@googlemail.com</a>:<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=
">The hiding of type errors and unwanted exponential growth of the code siz=
e could be avoided by using an attribute or a different operator symbol. Pl=
ease ignore the attribute name and the choosen symbol for now. They are onl=
y placeholers.<br><br><div style=3D"background-color:rgb(250,250,250);borde=
r-color:rgb(187,187,187);border-style:solid;border-width:1px"><code><div><s=
pan style=3D"color:#008">auto</span><span style=3D"color:#000"> x </span><s=
pan style=3D"color:#660">=3D</span><span style=3D"color:#000"> runtime_cond=
ition </span><span style=3D"color:#660">[[</span><span style=3D"color:#000"=
>generic</span><span style=3D"color:#660">]]</span><span style=3D"color:#00=
0"> </span><span style=3D"color:#660">?</span><span style=3D"color:#000"> A=
</span><span style=3D"color:#660">{}</span><span style=3D"color:#000"> </sp=
an><span style=3D"color:#660">:</span><span style=3D"color:#000"> B</span><=
span style=3D"color:#660">{};</span><span style=3D"color:#000"> </span></di=
v></code></div><br>or<br><br><code><div style=3D"background-color:rgb(250,2=
50,250);border-color:rgb(187,187,187);border-style:solid;border-width:1px">=
<code><div><span style=3D"color:#008">auto</span><span style=3D"color:#000"=
> x </span><span style=3D"color:#660">=3D</span><span style=3D"color:#000">=
runtime_condition </span><span style=3D"color:#660">??</span><span style=
=3D"color:#000"> A</span><span style=3D"color:#660">{}</span><span style=3D=
"color:#000"> </span><span style=3D"color:#660">:</span><span style=3D"colo=
r:#000"> B</span><span style=3D"color:#660">{};</span></div></code></div><s=
pan style=3D"color:#660"><br></span><span style=3D"color:#000"></span></cod=
e>This way, the programmer has to tell the compiler that he want to use the=
generic version. No unexpected exponential growth and no hidden type error=
s. Maybe this is too much for the upcomming standard. There is no room for =
such an extension. The list of must have features is already too long. Ther=
e is not much=C2=A0 room left besides Concepts and Modules, anyway. So this=
will be a proposal for a later standard. I think there are more cases, whr=
ere this technique could be applied. These cases are not explored yet.<br><=
br>Am Montag, 22. Mai 2017 21:57:02 UTC+2 schrieb Bengt Gustafsson:<blockqu=
ote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1=
px #ccc solid;padding-left:1ex"><div dir=3D"ltr">If we limit ourselves to t=
he constexpr condition case I think this proposal has some merit as an if c=
onstexpr stateament can't be used to affect the type of a variable that=
outlives the if statement, which such a constexpr ? could.<div><br></div><=
div>A general non-constexpr version is in my opinion a far too long step aw=
ay from the C++ type system, and also is very prone to hide type errors whe=
re you didn't want the compiler to do any trickery to counteract your m=
istyping, hiding bugs until later in the development cycle.<br><div><br><br=
>Den s=C3=B6ndag 21 maj 2017 kl. 04:54:38 UTC+2 skrev Mingxin Wang:<blockqu=
ote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1=
px #ccc solid;padding-left:1ex"><div dir=3D"ltr">On Sunday, May 21, 2017 at=
5:49:54 AM UTC+8, Nicol Bolas wrote:<blockquote class=3D"gmail_quote" styl=
e=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex=
"><div dir=3D"ltr">On Saturday, May 20, 2017 at 5:01:33 PM UTC-4, Zhihao Yu=
an 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"><div><br>=
<div class=3D"gmail_quote">On Sat, May 20, 2017 at 3:11 PM, Marc Mutz <span=
dir=3D"ltr"><<a rel=3D"nofollow">marc...@kdab.com</a>></span> wrote:=
<br><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;bor=
der-left:1px solid rgb(204,204,204);padding-left:1ex"><blockquote class=3D"=
gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(20=
4,204,204);padding-left:1ex"><br>
auto x =3D (std::is_integral_v<T>) ? A{} : B{};<br>
<br>
This would be like if constexpr with implicit constexpr determinded by<br>
the compiler.<br>
</blockquote>
<br>
I had the same idea the other day :)<br>
<br>
constexpr-if is explicit, why should the the ternary be different?<br>
<br>
=C2=A0 auto x =3D std::is_integral_v<T> constexpr ? A{} : B{};<br>
</blockquote></div><br></div><div>Seems not so hard?<br></div><div><br></di=
v><div>=C2=A0 auto x =3D std::conditional_t<std::is_<wbr>integral_v<T=
>, A, B>{};</div><br></div></blockquote><div><br>If all you want to d=
o is select a type, then it's not hard. If you want to do what the OP s=
uggested (ignoring the fact that his condition was probably not `constexpr`=
), that not something you can do with such a tool.<br></div></div></blockqu=
ote><div><br></div><div>If the condition is not "constexpr",=C2=
=A0=C2=A0and the types are determined at runtime, the "proxies" a=
nd the "wrappers" can be used to solve this problem. (<a href=3D"=
https://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/kvkgsHM6=
wFQ" rel=3D"nofollow" target=3D"_blank" onmousedown=3D"this.href=3D'htt=
ps://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/kvkgsHM6wFQ=
';return true;" onclick=3D"this.href=3D'https://groups.google.com/a=
/isocpp.org/forum/#!topic/std-proposals/kvkgsHM6wFQ';return true;">http=
s://groups.google.com/a/<wbr>isocpp.org/forum/#!topic/std-<wbr>proposals/kv=
kgsHM6wFQ</a>)</div></div></blockquote></div></div></div></blockquote></div=
></blockquote></div></blockquote></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/35841344-e829-4e86-bba2-12c5f3b0085c%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/35841344-e829-4e86-bba2-12c5f3b0085c=
%40isocpp.org</a>.<br />
------=_Part_3250_1487130865.1495532850250--
------=_Part_3249_1005493849.1495532850249--
.
Author: "ma.kalbfuss via ISO C++ Standard - Future Proposals" <std-proposals@isocpp.org>
Date: Tue, 23 May 2017 02:51:22 -0700 (PDT)
Raw View
------=_Part_3355_1812333101.1495533082047
Content-Type: multipart/alternative;
boundary="----=_Part_3356_169792981.1495533082048"
------=_Part_3356_169792981.1495533082048
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
And finally generic type definitions:
[[generic]] class X{};
[[generic]] class Y{};
Their use implies [[generic]] for all expressions. If all types in an=20
expression are generic the expression itself is generic, too.
Am Dienstag, 23. Mai 2017 11:47:30 UTC+2 schrieb ma.ka...@googlemail.com:
>
> Further cases where this could be applied:
>
> // generic variable
> void doit(bool runtime_condition) {
> [[generic]] auto x;
>
> if(runtime_condition) {
> x =3D A{};
> } else {
> x =3D B{};
> } =20
> }
>
> // generic variable with concept
> void doit(bool runtime_condition) {
> [[generic]] Iteratable x;
>
> if(runtime_condition) {
> x =3D A{};
> } else {
> x =3D B{};
> } =20
> }
>
>
>
> Am Dienstag, 23. Mai 2017 10:22:01 UTC+2 schrieb ma.ka...@googlemail.com:
>>
>> I explored other situations where this could be applied.
>>
>> //generic lambda
>> [[generic]] [](bool runtime_condition) {
>> if(runtime_condition) {
>> return A{};
>> } else {
>> return B{};
>> }
>> =20
>> }
>>
>> // generic function
>> [[generic]] auto doit(bool runtime_condition) {
>> if(runtime_condition) {
>> return A{};
>> } else {
>> return B{};
>> } =20
>> }
>>
>> // generic function with generic ternary operator
>> [[generic]] auto doit(bool runtime_condition) {
>> return runtime_condition [[generic]] ? A{} : B{};
>> }
>>
>>
>>
>>
>> Am Dienstag, 23. Mai 2017 10:07:52 UTC+2 schrieb ma.ka...@googlemail.com=
:
>>>
>>> The hiding of type errors and unwanted exponential growth of the code=
=20
>>> size could be avoided by using an attribute or a different operator sym=
bol.=20
>>> Please ignore the attribute name and the choosen symbol for now. They a=
re=20
>>> only placeholers.
>>>
>>> auto x =3D runtime_condition [[generic]] ? A{} : B{};=20
>>>
>>> or
>>>
>>> auto x =3D runtime_condition ?? A{} : B{};
>>>
>>> This way, the programmer has to tell the compiler that he want to use=
=20
>>> the generic version. No unexpected exponential growth and no hidden typ=
e=20
>>> errors. Maybe this is too much for the upcomming standard. There is no =
room=20
>>> for such an extension. The list of must have features is already too lo=
ng.=20
>>> There is not much room left besides Concepts and Modules, anyway. So t=
his=20
>>> will be a proposal for a later standard. I think there are more cases,=
=20
>>> whrere this technique could be applied. These cases are not explored ye=
t.
>>>
>>> Am Montag, 22. Mai 2017 21:57:02 UTC+2 schrieb Bengt Gustafsson:
>>>>
>>>> If we limit ourselves to the constexpr condition case I think this=20
>>>> proposal has some merit as an if constexpr stateament can't be used to=
=20
>>>> affect the type of a variable that outlives the if statement, which su=
ch a=20
>>>> constexpr ? could.
>>>>
>>>> A general non-constexpr version is in my opinion a far too long step=
=20
>>>> away from the C++ type system, and also is very prone to hide type err=
ors=20
>>>> where you didn't want the compiler to do any trickery to counteract yo=
ur=20
>>>> mistyping, hiding bugs until later in the development cycle.
>>>>
>>>>
>>>> Den s=C3=B6ndag 21 maj 2017 kl. 04:54:38 UTC+2 skrev Mingxin Wang:
>>>>>
>>>>> On Sunday, May 21, 2017 at 5:49:54 AM UTC+8, Nicol Bolas wrote:
>>>>>>
>>>>>> On Saturday, May 20, 2017 at 5:01:33 PM UTC-4, Zhihao Yuan wrote:
>>>>>>>
>>>>>>>
>>>>>>> On Sat, May 20, 2017 at 3:11 PM, Marc Mutz <marc...@kdab.com> wrote=
:
>>>>>>>
>>>>>>>>
>>>>>>>>> auto x =3D (std::is_integral_v<T>) ? A{} : B{};
>>>>>>>>>
>>>>>>>>> This would be like if constexpr with implicit constexpr=20
>>>>>>>>> determinded by
>>>>>>>>> the compiler.
>>>>>>>>>
>>>>>>>>
>>>>>>>> I had the same idea the other day :)
>>>>>>>>
>>>>>>>> constexpr-if is explicit, why should the the ternary be different?
>>>>>>>>
>>>>>>>> auto x =3D std::is_integral_v<T> constexpr ? A{} : B{};
>>>>>>>>
>>>>>>>
>>>>>>> Seems not so hard?
>>>>>>>
>>>>>>> auto x =3D std::conditional_t<std::is_integral_v<T>, A, B>{};
>>>>>>>
>>>>>>>
>>>>>> If all you want to do is select a type, then it's not hard. If you=
=20
>>>>>> want to do what the OP suggested (ignoring the fact that his conditi=
on was=20
>>>>>> probably not `constexpr`), that not something you can do with such a=
tool.
>>>>>>
>>>>>
>>>>> If the condition is not "constexpr", and the types are determined at=
=20
>>>>> runtime, the "proxies" and the "wrappers" can be used to solve this=
=20
>>>>> problem. (
>>>>> https://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/kv=
kgsHM6wFQ
>>>>> )
>>>>>
>>>>
--=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/6bf13403-b953-420b-a0f1-37824a969530%40isocpp.or=
g.
------=_Part_3356_169792981.1495533082048
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">And finally generic type definitions:<br><br><div style=3D=
"background-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); bo=
rder-style: solid; border-width: 1px; overflow-wrap: break-word;" class=3D"=
prettyprint"><code class=3D"prettyprint"><div class=3D"subprettyprint"><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">[[</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">generic</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;" cl=
ass=3D"styled-by-prettify">class</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> X</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">{};</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br></span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">[[</span><span style=3D"color: #000;" class=3D"styled-by-prettify">gener=
ic</span><span style=3D"color: #660;" class=3D"styled-by-prettify">]]</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span st=
yle=3D"color: #008;" class=3D"styled-by-prettify">class</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> Y</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">{};</span></div></code></div><br><br=
><br>Their use implies [[generic]] for all expressions. If all types in an =
expression are generic the expression itself is generic, too.<br><br>Am Die=
nstag, 23. Mai 2017 11:47:30 UTC+2 schrieb ma.ka...@googlemail.com:<blockqu=
ote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left=
: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">Further cases where t=
his could be applied:<br><br><div style=3D"background-color:rgb(250,250,250=
);border-color:rgb(187,187,187);border-style:solid;border-width:1px"><code>=
<div><span style=3D"color:#800">// generic variable</span><span style=3D"co=
lor:#000"><br></span><span style=3D"color:#008">void</span><span style=3D"c=
olor:#000"> doit</span><span style=3D"color:#660">(</span><span style=3D"co=
lor:#008">bool</span><span style=3D"color:#000"> runtime_condition</span><s=
pan style=3D"color:#660">)</span><span style=3D"color:#000"> </span><span s=
tyle=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </=
span><span style=3D"color:#660">[[</span><span style=3D"color:#000">generic=
</span><span style=3D"color:#660">]]</span><span style=3D"color:#000"> </sp=
an><span style=3D"color:#008">auto</span><span style=3D"color:#000"> x</spa=
n><span style=3D"color:#660">;</span><span style=3D"color:#000"><br><br>=C2=
=A0 =C2=A0 </span><span style=3D"color:#008">if</span><span style=3D"color:=
#660">(</span><span style=3D"color:#000">runtime_condition</span><span styl=
e=3D"color:#660">)</span><span style=3D"color:#000"> </span><span style=3D"=
color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=
=A0 x </span><span style=3D"color:#660">=3D</span><span style=3D"color:#000=
"> A</span><span style=3D"color:#660">{};</span><span style=3D"color:#000">=
<br>=C2=A0 =C2=A0 </span><span style=3D"color:#660">}</span><span style=3D"=
color:#000"> </span><span style=3D"color:#008">else</span><span style=3D"co=
lor:#000"> </span><span style=3D"color:#660">{</span><span style=3D"color:#=
000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 x </span><span style=3D"color:#660">=
=3D</span><span style=3D"color:#000"> B</span><span style=3D"color:#660">{}=
;</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"=
color:#660">}</span><span style=3D"color:#000"> =C2=A0 =C2=A0<br></span><sp=
an style=3D"color:#660">}</span><span style=3D"color:#000"><br><br></span><=
span style=3D"color:#800">// generic variable with concept</span><span styl=
e=3D"color:#000"><br></span><span style=3D"color:#008">void</span><span sty=
le=3D"color:#000"> doit</span><span style=3D"color:#660">(</span><span styl=
e=3D"color:#008">bool</span><span style=3D"color:#000"> runtime_condition</=
span><span style=3D"color:#660">)</span><span style=3D"color:#000"> </span>=
<span style=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 =
=C2=A0 </span><span style=3D"color:#660">[[</span><span style=3D"color:#000=
">generic</span><span style=3D"color:#660">]]</span><span style=3D"color:#0=
00"> </span><span style=3D"color:#606">Iteratable</span><span style=3D"colo=
r:#000"> x</span><span style=3D"color:#660">;</span><span style=3D"color:#0=
00"><br><br>=C2=A0 =C2=A0 </span><span style=3D"color:#008">if</span><span =
style=3D"color:#660">(</span><span style=3D"color:#000">runtime_condition</=
span><span style=3D"color:#660">)</span><span style=3D"color:#000"> </span>=
<span style=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 x </span><span style=3D"color:#660">=3D</span><span st=
yle=3D"color:#000"> A</span><span style=3D"color:#660">{};</span><span styl=
e=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#660">}</spa=
n><span style=3D"color:#000"> </span><span style=3D"color:#008">else</span>=
<span style=3D"color:#000"> </span><span style=3D"color:#660">{</span><span=
style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 x </span><span style=
=3D"color:#660">=3D</span><span style=3D"color:#000"> B</span><span style=
=3D"color:#660">{};</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </sp=
an><span style=3D"color:#660">}</span><span style=3D"color:#000"> =C2=A0 =
=C2=A0<br></span><span style=3D"color:#660">}</span></div></code></div><br>=
<br><br>Am Dienstag, 23. Mai 2017 10:22:01 UTC+2 schrieb <a>ma.ka...@google=
mail.com</a>:<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">I exp=
lored other situations where this could be applied.<br><br><div style=3D"ba=
ckground-color:rgb(250,250,250);border-color:rgb(187,187,187);border-style:=
solid;border-width:1px"><code><div><span style=3D"color:#800">//generic lam=
bda</span><span style=3D"color:#000"><br></span><span style=3D"color:#660">=
[[</span><span style=3D"color:#000">generic</span><span style=3D"color:#660=
">]]</span><span style=3D"color:#000"> </span><span style=3D"color:#660">[]=
(</span><span style=3D"color:#008">bool</span><span style=3D"color:#000"> r=
untime_condition</span><span style=3D"color:#660">)</span><span style=3D"co=
lor:#000"> </span><span style=3D"color:#660">{</span><span style=3D"color:#=
000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#008">if</span><span sty=
le=3D"color:#660">(</span><span style=3D"color:#000">runtime_condition</spa=
n><span style=3D"color:#660">)</span><span style=3D"color:#000"> </span><sp=
an style=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 =C2=
=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#008">return</span><span styl=
e=3D"color:#000"> A</span><span style=3D"color:#660">{};</span><span style=
=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#660">}</span=
><span style=3D"color:#000"> </span><span style=3D"color:#008">else</span><=
span style=3D"color:#000"> </span><span style=3D"color:#660">{</span><span =
style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"=
color:#008">return</span><span style=3D"color:#000"> B</span><span style=3D=
"color:#660">{};</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span>=
<span style=3D"color:#660">}</span><span style=3D"color:#000"><br>=C2=A0 =
=C2=A0 <br></span><span style=3D"color:#660">}</span><span style=3D"color:#=
000"><br><br></span><span style=3D"color:#800">// generic function</span><s=
pan style=3D"color:#000"><br></span><span style=3D"color:#660">[[</span><sp=
an style=3D"color:#000">generic</span><span style=3D"color:#660">]]</span><=
span style=3D"color:#000"> </span><span style=3D"color:#008">auto</span><sp=
an style=3D"color:#000"> doit</span><span style=3D"color:#660">(</span><spa=
n style=3D"color:#008">bool</span><span style=3D"color:#000"> runtime_condi=
tion</span><span style=3D"color:#660">)</span><span style=3D"color:#000"> <=
/span><span style=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=
=A0 =C2=A0 </span><span style=3D"color:#008">if</span><span style=3D"color:=
#660">(</span><span style=3D"color:#000">runtime_condition</span><span styl=
e=3D"color:#660">)</span><span style=3D"color:#000"> </span><span style=3D"=
color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=
=A0 </span><span style=3D"color:#008">return</span><span style=3D"color:#00=
0"> A</span><span style=3D"color:#660">{};</span><span style=3D"color:#000"=
><br>=C2=A0 =C2=A0 </span><span style=3D"color:#660">}</span><span style=3D=
"color:#000"> </span><span style=3D"color:#008">else</span><span style=3D"c=
olor:#000"> </span><span style=3D"color:#660">{</span><span style=3D"color:=
#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#008">ret=
urn</span><span style=3D"color:#000"> B</span><span style=3D"color:#660">{}=
;</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"=
color:#660">}</span><span style=3D"color:#000"> =C2=A0 =C2=A0<br></span><sp=
an style=3D"color:#660">}</span><span style=3D"color:#000"><br><br></span><=
span style=3D"color:#800">// generic function with generic ternary operator=
</span><span style=3D"color:#000"><br></span><span style=3D"color:#660">[[<=
/span><span style=3D"color:#000">generic</span><span style=3D"color:#660">]=
]</span><span style=3D"color:#000"> </span><span style=3D"color:#008">auto<=
/span><span style=3D"color:#000"> doit</span><span style=3D"color:#660">(</=
span><span style=3D"color:#008">bool</span><span style=3D"color:#000"> runt=
ime_condition</span><span style=3D"color:#660">)</span><span style=3D"color=
:#000"> </span><span style=3D"color:#660">{</span><span style=3D"color:#000=
"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#008">return</span><span st=
yle=3D"color:#000"> runtime_condition </span><span style=3D"color:#660">[[<=
/span><span style=3D"color:#000">generic</span><span style=3D"color:#660">]=
]</span><span style=3D"color:#000"> </span><span style=3D"color:#660">?</sp=
an><span style=3D"color:#000"> A</span><span style=3D"color:#660">{}</span>=
<span style=3D"color:#000"> </span><span style=3D"color:#660">:</span><span=
style=3D"color:#000"> B</span><span style=3D"color:#660">{};</span><span s=
tyle=3D"color:#000"><br></span><span style=3D"color:#660">}</span></div></c=
ode></div><br><br><br><br>Am Dienstag, 23. Mai 2017 10:07:52 UTC+2 schrieb =
<a>ma.ka...@googlemail.com</a>:<blockquote class=3D"gmail_quote" style=3D"m=
argin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div=
dir=3D"ltr">The hiding of type errors and unwanted exponential growth of t=
he code size could be avoided by using an attribute or a different operator=
symbol. Please ignore the attribute name and the choosen symbol for now. T=
hey are only placeholers.<br><br><div style=3D"background-color:rgb(250,250=
,250);border-color:rgb(187,187,187);border-style:solid;border-width:1px"><c=
ode><div><span style=3D"color:#008">auto</span><span style=3D"color:#000"> =
x </span><span style=3D"color:#660">=3D</span><span style=3D"color:#000"> r=
untime_condition </span><span style=3D"color:#660">[[</span><span style=3D"=
color:#000">generic</span><span style=3D"color:#660">]]</span><span style=
=3D"color:#000"> </span><span style=3D"color:#660">?</span><span style=3D"c=
olor:#000"> A</span><span style=3D"color:#660">{}</span><span style=3D"colo=
r:#000"> </span><span style=3D"color:#660">:</span><span style=3D"color:#00=
0"> B</span><span style=3D"color:#660">{};</span><span style=3D"color:#000"=
> </span></div></code></div><br>or<br><br><code><div style=3D"background-co=
lor:rgb(250,250,250);border-color:rgb(187,187,187);border-style:solid;borde=
r-width:1px"><code><div><span style=3D"color:#008">auto</span><span style=
=3D"color:#000"> x </span><span style=3D"color:#660">=3D</span><span style=
=3D"color:#000"> runtime_condition </span><span style=3D"color:#660">??</sp=
an><span style=3D"color:#000"> A</span><span style=3D"color:#660">{}</span>=
<span style=3D"color:#000"> </span><span style=3D"color:#660">:</span><span=
style=3D"color:#000"> B</span><span style=3D"color:#660">{};</span></div><=
/code></div><span style=3D"color:#660"><br></span><span style=3D"color:#000=
"></span></code>This way, the programmer has to tell the compiler that he w=
ant to use the generic version. No unexpected exponential growth and no hid=
den type errors. Maybe this is too much for the upcomming standard. There i=
s no room for such an extension. The list of must have features is already =
too long. There is not much=C2=A0 room left besides Concepts and Modules, a=
nyway. So this will be a proposal for a later standard. I think there are m=
ore cases, whrere this technique could be applied. These cases are not expl=
ored yet.<br><br>Am Montag, 22. Mai 2017 21:57:02 UTC+2 schrieb Bengt Gusta=
fsson:<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">If we limit =
ourselves to the constexpr condition case I think this proposal has some me=
rit as an if constexpr stateament can't be used to affect the type of a=
variable that outlives the if statement, which such a constexpr ? could.<d=
iv><br></div><div>A general non-constexpr version is in my opinion a far to=
o long step away from the C++ type system, and also is very prone to hide t=
ype errors where you didn't want the compiler to do any trickery to cou=
nteract your mistyping, hiding bugs until later in the development cycle.<b=
r><div><br><br>Den s=C3=B6ndag 21 maj 2017 kl. 04:54:38 UTC+2 skrev Mingxin=
Wang:<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 Sunday, M=
ay 21, 2017 at 5:49:54 AM UTC+8, Nicol Bolas wrote:<blockquote class=3D"gma=
il_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;pa=
dding-left:1ex"><div dir=3D"ltr">On Saturday, May 20, 2017 at 5:01:33 PM UT=
C-4, Zhihao Yuan 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"><div><br><div class=3D"gmail_quote">On Sat, May 20, 2017 at 3:11 PM, M=
arc Mutz <span dir=3D"ltr"><<a rel=3D"nofollow">marc...@kdab.com</a>>=
</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px=
0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><blockq=
uote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1p=
x solid rgb(204,204,204);padding-left:1ex"><br>
auto x =3D (std::is_integral_v<T>) ? A{} : B{};<br>
<br>
This would be like if constexpr with implicit constexpr determinded by<br>
the compiler.<br>
</blockquote>
<br>
I had the same idea the other day :)<br>
<br>
constexpr-if is explicit, why should the the ternary be different?<br>
<br>
=C2=A0 auto x =3D std::is_integral_v<T> constexpr ? A{} : B{};<br>
</blockquote></div><br></div><div>Seems not so hard?<br></div><div><br></di=
v><div>=C2=A0 auto x =3D std::conditional_t<std::is_<wbr>integral_v<T=
>, A, B>{};</div><br></div></blockquote><div><br>If all you want to d=
o is select a type, then it's not hard. If you want to do what the OP s=
uggested (ignoring the fact that his condition was probably not `constexpr`=
), that not something you can do with such a tool.<br></div></div></blockqu=
ote><div><br></div><div>If the condition is not "constexpr",=C2=
=A0=C2=A0and the types are determined at runtime, the "proxies" a=
nd the "wrappers" can be used to solve this problem. (<a href=3D"=
https://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/kvkgsHM6=
wFQ" rel=3D"nofollow" target=3D"_blank" onmousedown=3D"this.href=3D'htt=
ps://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/kvkgsHM6wFQ=
';return true;" onclick=3D"this.href=3D'https://groups.google.com/a=
/isocpp.org/forum/#!topic/std-proposals/kvkgsHM6wFQ';return true;">http=
s://groups.google.com/a/<wbr>isocpp.org/forum/#!topic/std-<wbr>proposals/kv=
kgsHM6wFQ</a>)</div></div></blockquote></div></div></div></blockquote></div=
></blockquote></div></blockquote></div></blockquote></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/6bf13403-b953-420b-a0f1-37824a969530%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/6bf13403-b953-420b-a0f1-37824a969530=
%40isocpp.org</a>.<br />
------=_Part_3356_169792981.1495533082048--
------=_Part_3355_1812333101.1495533082047--
.
Author: Thiago Macieira <thiago@macieira.org>
Date: Tue, 23 May 2017 07:47:37 -0700
Raw View
On Tuesday, 23 May 2017 01:07:52 PDT ma.kalbfuss via ISO C++ Standard - Future
Proposals wrote:
> The hiding of type errors and unwanted exponential growth of the code size
> could be avoided by using an attribute or a different operator symbol.
> Please ignore the attribute name and the choosen symbol for now. They are
> only placeholers.
>
> auto x = runtime_condition [[generic]] ? A{} : B{};
>
> or
>
> auto x = runtime_condition ?? A{} : B{};
>
> This way, the programmer has to tell the compiler that he want to use the
> generic version. No unexpected exponential growth and no hidden type
> errors. Maybe this is too much for the upcomming standard. There is no room
> for such an extension. The list of must have features is already too long.
> There is not much room left besides Concepts and Modules, anyway. So this
> will be a proposal for a later standard. I think there are more cases,
> whrere this technique could be applied. These cases are not explored yet.
You're missing the point that the code growth is not optional.
It doesn't matter how you mark this new syntax, the fact that we have a
variable whose type cannot be determined at compile time means that there's
runtime overhead.
With proper reflection, the generic type on the left side can be entirely
impemented in library code, with no compiler magic, with dispatcher functions
to A and B depending on the stored type. For example, it would generate:
template <typename A, typename B>
struct Generic
{
typeinfo *ti;
void *target;
Generic(A *object) : ti(typeinfo(A)), target(object) {}
Generic(B *object) : ti(typeinfo(B)), target(object) {}
int f()
{
return ti == typeinfo(A) ?
static_cast<A *>(target)->f() :
static_cast<B *>(target)->f();
}
};
Then if you have Generic<A, B> x, whenever you do:
x.f();
then the correct function is called.
But there was an overhead, since every call now checks the typeinfo. This
avoids the exponential growth of code, but it does increase the code
nonetheless and introduces a runtime overhead.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
--
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/3491692.i123ijHHWq%40tjmaciei-mobl1.
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Tue, 23 May 2017 09:28:40 -0700 (PDT)
Raw View
------=_Part_3538_1891186954.1495556920490
Content-Type: multipart/alternative;
boundary="----=_Part_3539_1293590208.1495556920491"
------=_Part_3539_1293590208.1495556920491
Content-Type: text/plain; charset="UTF-8"
On Tuesday, May 23, 2017 at 10:47:49 AM UTC-4, Thiago Macieira wrote:
>
> On Tuesday, 23 May 2017 01:07:52 PDT ma.kalbfuss via ISO C++ Standard -
> Future
> Proposals wrote:
> > The hiding of type errors and unwanted exponential growth of the code
> size
> > could be avoided by using an attribute or a different operator symbol.
> > Please ignore the attribute name and the choosen symbol for now. They
> are
> > only placeholers.
> >
> > auto x = runtime_condition [[generic]] ? A{} : B{};
> >
> > or
> >
> > auto x = runtime_condition ?? A{} : B{};
> >
> > This way, the programmer has to tell the compiler that he want to use
> the
> > generic version. No unexpected exponential growth and no hidden type
> > errors. Maybe this is too much for the upcomming standard. There is no
> room
> > for such an extension. The list of must have features is already too
> long.
> > There is not much room left besides Concepts and Modules, anyway. So
> this
> > will be a proposal for a later standard. I think there are more cases,
> > whrere this technique could be applied. These cases are not explored
> yet.
>
> You're missing the point that the code growth is not optional.
>
> It doesn't matter how you mark this new syntax, the fact that we have a
> variable whose type cannot be determined at compile time means that
> there's
> runtime overhead.
>
But that's not what you have. What you have is *two different variables*,
which happen to have the same name. It turns this:
auto x = runtime_condition ?? expr1 : expr2;
x.op1();
auto z = some_y;
x.op2(&some_y);
into this:
if(runtime_condition)
{
auto x = expr1;
x.op1();
auto z = some_y;
x.op2(&some_y);
}
else
{
auto x = expr2;
x.op1();
auto z = some_y;
x.op2(&some_y);
}
The only runtime overhead is the overhead of the runtime condition. At no
time after the `if` statement does the compiler check at runtime which type
`x` happens to be.
You're right that the code growth is not optional. But the code growth is
no different from any other template instantiation either.
--
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/e2eed1c7-f734-4816-9660-7b9f39166af9%40isocpp.org.
------=_Part_3539_1293590208.1495556920491
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Tuesday, May 23, 2017 at 10:47:49 AM UTC-4, Thi=
ago Macieira wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;mar=
gin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On Tuesday,=
23 May 2017 01:07:52 PDT ma.kalbfuss via ISO C++ Standard - Future=20
<br>Proposals wrote:
<br>> The hiding of type errors and unwanted exponential growth of the c=
ode size
<br>> could be avoided by using an attribute or a different operator sym=
bol.
<br>> Please ignore the attribute name and the choosen symbol for now. T=
hey are
<br>> only placeholers.
<br>>=20
<br>> auto x =3D runtime_condition [[generic]] ? A{} : B{};
<br>>=20
<br>> or
<br>>=20
<br>> auto x =3D runtime_condition ?? A{} : B{};
<br>>=20
<br>> This way, the programmer has to tell the compiler that he want to =
use the
<br>> generic version. No unexpected exponential growth and no hidden ty=
pe
<br>> errors. Maybe this is too much for the upcomming standard. There i=
s no room
<br>> for such an extension. The list of must have features is already t=
oo long.
<br>> There is not much =C2=A0room left besides Concepts and Modules, an=
yway. So this
<br>> will be a proposal for a later standard. I think there are more ca=
ses,
<br>> whrere this technique could be applied. These cases are not explor=
ed yet.
<br>
<br>You're missing the point that the code growth is not optional.
<br>
<br>It doesn't matter how you mark this new syntax, the fact that we ha=
ve a=20
<br>variable whose type cannot be determined at compile time means that the=
re's=20
<br>runtime overhead.<br></blockquote><div><br>But that's not what you =
have. What you have is <i>two different variables</i>, which happen to have=
the same name. It turns this:<br><br><div style=3D"background-color: rgb(2=
50, 250, 250); border-color: rgb(187, 187, 187); border-style: solid; borde=
r-width: 1px; overflow-wrap: break-word;" class=3D"prettyprint"><code class=
=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color: #008;"=
class=3D"styled-by-prettify">auto</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> x </span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> runtime_condition </span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">??</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> expr1 </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">:</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
expr2</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>x</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">.</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">op1</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">();</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" cl=
ass=3D"styled-by-prettify">auto</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> z </span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> some_y</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>x=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">.</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify">op2</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">(&</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">some_y</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">);</span></div></code></div><br>=
into 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; overfl=
ow-wrap: break-word;" class=3D"prettyprint"><code class=3D"prettyprint"><di=
v class=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled-by-=
prettify">if</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">runtime=
_condition</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
)</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 </span><span =
style=3D"color: #008;" class=3D"styled-by-prettify">auto</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> x </span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> expr1</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 x</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">.</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify">op1</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">();</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
><br>=C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-prettify=
">auto</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> z <=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> some_y</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 x</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">.</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify">op2</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">(&</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify">some_y</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">);</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"><br></span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">}</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">else=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><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 </span><span s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">auto</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> x </span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> expr2</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 x</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">.</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify">op1</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">();</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
><br>=C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-prettify=
">auto</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> z <=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> some_y</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 x</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">.</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify">op2</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">(&</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify">some_y</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">);</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"><br></span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">}</span></div></code></div><br>The only runtime overhead is the =
overhead of the runtime condition. At no time after the `if` statement does=
the compiler check at runtime which type `x` happens to be.<br><br>You'=
;re right that the code growth is not optional. But the code growth is no d=
ifferent from any other template instantiation either.<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/e2eed1c7-f734-4816-9660-7b9f39166af9%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/e2eed1c7-f734-4816-9660-7b9f39166af9=
%40isocpp.org</a>.<br />
------=_Part_3539_1293590208.1495556920491--
------=_Part_3538_1891186954.1495556920490--
.
Author: Thiago Macieira <thiago@macieira.org>
Date: Tue, 23 May 2017 09:51:13 -0700
Raw View
On Tuesday, 23 May 2017 09:28:40 PDT Nicol Bolas wrote:
> But that's not what you have. What you have is *two different variables*,
> which happen to have the same name. It turns this:
>
> auto x = runtime_condition ?? expr1 : expr2;
> x.op1();
> auto z = some_y;
> x.op2(&some_y);
>
> into this:
>
> if(runtime_condition)
> {
> auto x = expr1;
> x.op1();
> auto z = some_y;
> x.op2(&some_y);
> }
> else
> {
> auto x = expr2;
> x.op1();
> auto z = some_y;
> x.op2(&some_y);
> }
That's only one of the possible expansions. The other is:
storage_area x;
if (runtime_condition) {
new (x) A(expr1);
x.as<A>().op1();
} else {
new (x) B(expr2);
x.as<B>().op1();
}
auto z = some_y;
if (runtime_condition)
x.as<A>().op2(&some_y);
else
x.as<B>().op2(&some_y);
> The only runtime overhead is the overhead of the runtime condition. At no
> time after the `if` statement does the compiler check at runtime which type
> `x` happens to be.
As I said, one of many possible implementations. As in my expansion, it may
want to duplicate the checking of the runtime condition (or save its result in
a hidden variable) so it can use a common code path that doesn't depend on the
runtime condition.
> You're right that the code growth is not optional. But the code growth is
> no different from any other template instantiation either.
That depends on what you're comparing to. If you're comparing to:
if (runtime_condition)
exec<A>();
else
exec<B>();
then I agree.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
--
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/5140577.CpRPiJttCa%40tjmaciei-mobl1.
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Tue, 23 May 2017 10:15:28 -0700 (PDT)
Raw View
------=_Part_3541_414512920.1495559728704
Content-Type: multipart/alternative;
boundary="----=_Part_3542_2100688792.1495559728704"
------=_Part_3542_2100688792.1495559728704
Content-Type: text/plain; charset="UTF-8"
On Tuesday, May 23, 2017 at 12:51:23 PM UTC-4, Thiago Macieira wrote:
>
> On Tuesday, 23 May 2017 09:28:40 PDT Nicol Bolas wrote:
> > But that's not what you have. What you have is *two different
> variables*,
> > which happen to have the same name. It turns this:
> >
> > auto x = runtime_condition ?? expr1 : expr2;
> > x.op1();
> > auto z = some_y;
> > x.op2(&some_y);
> >
> > into this:
> >
> > if(runtime_condition)
> > {
> > auto x = expr1;
> > x.op1();
> > auto z = some_y;
> > x.op2(&some_y);
> > }
> > else
> > {
> > auto x = expr2;
> > x.op1();
> > auto z = some_y;
> > x.op2(&some_y);
> > }
>
> That's only one of the possible expansions. The other is:
>
> storage_area x;
> if (runtime_condition) {
> new (x) A(expr1);
> x.as<A>().op1();
> } else {
> new (x) B(expr2);
> x.as<B>().op1();
> }
> auto z = some_y;
> if (runtime_condition)
> x.as<A>().op2(&some_y);
> else
> x.as<B>().op2(&some_y);
>
Well yes, you could implement the feature in a way that throws performance
away. But I don't think we should evaluate a feature by assuming that
compiler developers will implement it badly for no reason. The main point
is that compilers are perfectly capable of implementing the operation in an
optimal fashion.
Also, the result of contextually converting `runtime_condition` to `bool`
needs to be stored, since it cannot be evaluated more than once.
--
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/1c01d516-1e5d-4b5f-958a-8280164b2936%40isocpp.org.
------=_Part_3542_2100688792.1495559728704
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Tuesday, May 23, 2017 at 12:51:23 PM UTC-4, Thi=
ago Macieira wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;mar=
gin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On Tuesday,=
23 May 2017 09:28:40 PDT Nicol Bolas wrote:
<br>> But that's not what you have. What you have is *two different =
variables*,
<br>> which happen to have the same name. It turns this:
<br>>=20
<br>> auto x =3D runtime_condition ?? expr1 : expr2;
<br>> x.op1();
<br>> auto z =3D some_y;
<br>> x.op2(&some_y);
<br>>=20
<br>> into this:
<br>>=20
<br>> if(runtime_condition)
<br>> {
<br>> =C2=A0 auto x =3D expr1;
<br>> =C2=A0 x.op1();
<br>> =C2=A0 auto z =3D some_y;
<br>> =C2=A0 x.op2(&some_y);
<br>> }
<br>> else
<br>> {
<br>> =C2=A0 auto x =3D expr2;
<br>> =C2=A0 x.op1();
<br>> =C2=A0 auto z =3D some_y;
<br>> =C2=A0 x.op2(&some_y);
<br>> }
<br>
<br>That's only one of the possible expansions. The other is:
<br>
<br>=C2=A0 storage_area x;
<br>=C2=A0 if (runtime_condition) {
<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0new (x) A(expr1);
<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0<a href=3D"http://x.as"=
target=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D'http://=
www.google.com/url?q\x3dhttp%3A%2F%2Fx.as\x26sa\x3dD\x26sntz\x3d1\x26usg\x3=
dAFQjCNF_RgZBHEjoHC6BbryEAu7_i-OuOg';return true;" onclick=3D"this.href=
=3D'http://www.google.com/url?q\x3dhttp%3A%2F%2Fx.as\x26sa\x3dD\x26sntz=
\x3d1\x26usg\x3dAFQjCNF_RgZBHEjoHC6BbryEAu7_i-OuOg';return true;">x.as<=
/a><A>().op1();
<br>=C2=A0 } else {
<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0new (x) B(expr2);
<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0<a href=3D"http://x.as"=
target=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D'http://=
www.google.com/url?q\x3dhttp%3A%2F%2Fx.as\x26sa\x3dD\x26sntz\x3d1\x26usg\x3=
dAFQjCNF_RgZBHEjoHC6BbryEAu7_i-OuOg';return true;" onclick=3D"this.href=
=3D'http://www.google.com/url?q\x3dhttp%3A%2F%2Fx.as\x26sa\x3dD\x26sntz=
\x3d1\x26usg\x3dAFQjCNF_RgZBHEjoHC6BbryEAu7_i-OuOg';return true;">x.as<=
/a><B>().op1();
<br>=C2=A0 }
<br>=C2=A0 auto z =3D some_y;
<br>=C2=A0 if (runtime_condition)=20
<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0<a href=3D"http://x.as"=
target=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D'http://=
www.google.com/url?q\x3dhttp%3A%2F%2Fx.as\x26sa\x3dD\x26sntz\x3d1\x26usg\x3=
dAFQjCNF_RgZBHEjoHC6BbryEAu7_i-OuOg';return true;" onclick=3D"this.href=
=3D'http://www.google.com/url?q\x3dhttp%3A%2F%2Fx.as\x26sa\x3dD\x26sntz=
\x3d1\x26usg\x3dAFQjCNF_RgZBHEjoHC6BbryEAu7_i-OuOg';return true;">x.as<=
/a><A>().op2(&some_y)<wbr>;
<br>=C2=A0 else
<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0<a href=3D"http://x.as"=
target=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D'http://=
www.google.com/url?q\x3dhttp%3A%2F%2Fx.as\x26sa\x3dD\x26sntz\x3d1\x26usg\x3=
dAFQjCNF_RgZBHEjoHC6BbryEAu7_i-OuOg';return true;" onclick=3D"this.href=
=3D'http://www.google.com/url?q\x3dhttp%3A%2F%2Fx.as\x26sa\x3dD\x26sntz=
\x3d1\x26usg\x3dAFQjCNF_RgZBHEjoHC6BbryEAu7_i-OuOg';return true;">x.as<=
/a><B>().op2(&some_y)<wbr>;
<br></blockquote><div><br>Well yes, you could implement the feature in a wa=
y that throws performance away. But I don't think we should evaluate a =
feature by assuming that compiler developers will implement it badly for no=
reason. The main point is that compilers are perfectly capable of implemen=
ting the operation in an optimal fashion.<br><br>Also, the result of contex=
tually converting `runtime_condition` to `bool` needs to be stored, since i=
t cannot be evaluated more than once.</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/1c01d516-1e5d-4b5f-958a-8280164b2936%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/1c01d516-1e5d-4b5f-958a-8280164b2936=
%40isocpp.org</a>.<br />
------=_Part_3542_2100688792.1495559728704--
------=_Part_3541_414512920.1495559728704--
.
Author: ma.kalbfuss@web.de
Date: Tue, 23 May 2017 11:20:17 -0700 (PDT)
Raw View
------=_Part_3573_203431118.1495563617295
Content-Type: multipart/alternative;
boundary="----=_Part_3574_123225151.1495563617295"
------=_Part_3574_123225151.1495563617295
Content-Type: text/plain; charset="UTF-8"
Sorry. This was misleading. I know that we cannot avoid the exponential
growth. My point is, that there is no accidental exponential growth,
because the programmer has to explicitly denote the usage with the
[[generic]] attribute.
Am Dienstag, 23. Mai 2017 16:47:49 UTC+2 schrieb Thiago Macieira:
>
> On Tuesday, 23 May 2017 01:07:52 PDT ma.kalbfuss via ISO C++ Standard -
> Future
> Proposals wrote:
> > The hiding of type errors and unwanted exponential growth of the code
> size
> > could be avoided by using an attribute or a different operator symbol.
> > Please ignore the attribute name and the choosen symbol for now. They
> are
> > only placeholers.
> >
> > auto x = runtime_condition [[generic]] ? A{} : B{};
> >
> > or
> >
> > auto x = runtime_condition ?? A{} : B{};
> >
> > This way, the programmer has to tell the compiler that he want to use
> the
> > generic version. No unexpected exponential growth and no hidden type
> > errors. Maybe this is too much for the upcomming standard. There is no
> room
> > for such an extension. The list of must have features is already too
> long.
> > There is not much room left besides Concepts and Modules, anyway. So
> this
> > will be a proposal for a later standard. I think there are more cases,
> > whrere this technique could be applied. These cases are not explored
> yet.
>
> You're missing the point that the code growth is not optional.
>
> It doesn't matter how you mark this new syntax, the fact that we have a
> variable whose type cannot be determined at compile time means that
> there's
> runtime overhead.
>
> With proper reflection, the generic type on the left side can be entirely
> impemented in library code, with no compiler magic, with dispatcher
> functions
> to A and B depending on the stored type. For example, it would generate:
>
> template <typename A, typename B>
> struct Generic
> {
> typeinfo *ti;
> void *target;
>
> Generic(A *object) : ti(typeinfo(A)), target(object) {}
> Generic(B *object) : ti(typeinfo(B)), target(object) {}
>
> int f()
> {
> return ti == typeinfo(A) ?
> static_cast<A *>(target)->f() :
> static_cast<B *>(target)->f();
> }
> };
>
> Then if you have Generic<A, B> x, whenever you do:
> x.f();
>
> then the correct function is called.
>
> But there was an overhead, since every call now checks the typeinfo. This
> avoids the exponential growth of code, but it does increase the code
> nonetheless and introduces a runtime overhead.
>
> --
> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
> Software Architect - Intel Open Source Technology Center
>
>
--
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/423c4520-1f50-4761-8d02-edfbaaf94827%40isocpp.org.
------=_Part_3574_123225151.1495563617295
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Sorry. This was misleading. I know that we cannot avoid th=
e exponential growth. My point is, that there is no accidental exponential =
growth, because the programmer has to explicitly denote the usage with the =
[[generic]] attribute.<br><br>Am Dienstag, 23. Mai 2017 16:47:49 UTC+2 schr=
ieb Thiago Macieira:<blockquote class=3D"gmail_quote" style=3D"margin: 0;ma=
rgin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On Tuesday=
, 23 May 2017 01:07:52 PDT ma.kalbfuss via ISO C++ Standard - Future=20
<br>Proposals wrote:
<br>> The hiding of type errors and unwanted exponential growth of the c=
ode size
<br>> could be avoided by using an attribute or a different operator sym=
bol.
<br>> Please ignore the attribute name and the choosen symbol for now. T=
hey are
<br>> only placeholers.
<br>>=20
<br>> auto x =3D runtime_condition [[generic]] ? A{} : B{};
<br>>=20
<br>> or
<br>>=20
<br>> auto x =3D runtime_condition ?? A{} : B{};
<br>>=20
<br>> This way, the programmer has to tell the compiler that he want to =
use the
<br>> generic version. No unexpected exponential growth and no hidden ty=
pe
<br>> errors. Maybe this is too much for the upcomming standard. There i=
s no room
<br>> for such an extension. The list of must have features is already t=
oo long.
<br>> There is not much =C2=A0room left besides Concepts and Modules, an=
yway. So this
<br>> will be a proposal for a later standard. I think there are more ca=
ses,
<br>> whrere this technique could be applied. These cases are not explor=
ed yet.
<br>
<br>You're missing the point that the code growth is not optional.
<br>
<br>It doesn't matter how you mark this new syntax, the fact that we ha=
ve a=20
<br>variable whose type cannot be determined at compile time means that the=
re's=20
<br>runtime overhead.
<br>
<br>With proper reflection, the generic type on the left side can be entire=
ly=20
<br>impemented in library code, with no compiler magic, with dispatcher fun=
ctions=20
<br>to A and B depending on the stored type. For example, it would generate=
:
<br>
<br>template <typename A, typename B>
<br>struct Generic
<br>{
<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0typeinfo *ti;
<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0void *target;
<br>
<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0Generic(A *object) : ti=
(typeinfo(A)), target(object) {}
<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0Generic(B *object) : ti=
(typeinfo(B)), target(object) {}
<br>
<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0int f()
<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0{
<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0return ti =3D=3D typeinfo(A) ?=20
<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
<wbr>static_cast<A *>(target)->f() :
<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
<wbr>static_cast<B *>(target)->f();
<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0}
<br>};
<br>
<br>Then if you have Generic<A, B> x, whenever you do:
<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0x.f();
<br>
<br>then the correct function is called.
<br>
<br>But there was an overhead, since every call now checks the typeinfo. Th=
is=20
<br>avoids the exponential growth of code, but it does increase the code=20
<br>nonetheless and introduces a runtime overhead.
<br>
<br>--=20
<br>Thiago Macieira - thiago (AT) <a href=3D"http://macieira.info" target=
=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D'http://www.goo=
gle.com/url?q\x3dhttp%3A%2F%2Fmacieira.info\x26sa\x3dD\x26sntz\x3d1\x26usg\=
x3dAFQjCNEswDUBNCNanbu7euhqLn_62FW8ag';return true;" onclick=3D"this.hr=
ef=3D'http://www.google.com/url?q\x3dhttp%3A%2F%2Fmacieira.info\x26sa\x=
3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEswDUBNCNanbu7euhqLn_62FW8ag';return t=
rue;">macieira.info</a> - thiago (AT) <a href=3D"http://kde.org" target=3D"=
_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D'http://www.google.=
com/url?q\x3dhttp%3A%2F%2Fkde.org\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH=
GRJdo5_JYG1DowztwAHAKs80XSA';return true;" onclick=3D"this.href=3D'=
http://www.google.com/url?q\x3dhttp%3A%2F%2Fkde.org\x26sa\x3dD\x26sntz\x3d1=
\x26usg\x3dAFQjCNHGRJdo5_JYG1DowztwAHAKs80XSA';return true;">kde.org</a=
>
<br>=C2=A0 =C2=A0Software Architect - Intel Open Source Technology Center
<br>
<br></blockquote></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/423c4520-1f50-4761-8d02-edfbaaf94827%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/423c4520-1f50-4761-8d02-edfbaaf94827=
%40isocpp.org</a>.<br />
------=_Part_3574_123225151.1495563617295--
------=_Part_3573_203431118.1495563617295--
.
Author: Thiago Macieira <thiago@macieira.org>
Date: Wed, 24 May 2017 09:49:52 -0700
Raw View
On Tuesday, 23 May 2017 11:20:17 PDT ma.kalbfuss@web.de wrote:
> Sorry. This was misleading. I know that we cannot avoid the exponential
> growth. My point is, that there is no accidental exponential growth,
> because the programmer has to explicitly denote the usage with the
> [[generic]] attribute.
You may notice I ignored your emails talking about the attribute because
that's an invalid use of an attribute. An attribute must be ignorable by a
compiler that doesn't know it and the program must still compile the same way
and run the same way.
You need a new keyword or a new operator.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
--
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/62372169.4SFskC8KQc%40tjmaciei-mobl1.
.
Author: "ma.kalbfuss via ISO C++ Standard - Future Proposals" <std-proposals@isocpp.org>
Date: Wed, 24 May 2017 10:13:05 -0700 (PDT)
Raw View
------=_Part_4465_213730374.1495645985963
Content-Type: multipart/alternative;
boundary="----=_Part_4466_1056312602.1495645985964"
------=_Part_4466_1056312602.1495645985964
Content-Type: text/plain; charset="UTF-8"
Thanks for the hint. When you replace all occurences of [[generic]] with
generic, it should be ok.
//generic lambda
generic [](bool runtime_condition) {
if(runtime_condition) {
return A{};
} else {
return B{};
}
}
// generic function
generic auto doit(bool runtime_condition) {
if(runtime_condition) {
return A{};
} else {
return B{};
}
}
// generic function with generic ternary operator
generic auto doit(bool runtime_condition) {
return runtime_condition [[generic]] ? A{} : B{};
}
// generic variable
void doit(bool runtime_condition) {
generic auto x;
if(runtime_condition) {
x = A{};
} else {
x = B{};
}
}
// generic variable with concept
void doit(bool runtime_condition) {
generic Iteratable x;
if(runtime_condition) {
x = A{};
} else {
x = B{};
}
}
Am Mittwoch, 24. Mai 2017 18:50:32 UTC+2 schrieb Thiago Macieira:
>
> On Tuesday, 23 May 2017 11:20:17 PDT ma.ka...@web.de <javascript:> wrote:
> > Sorry. This was misleading. I know that we cannot avoid the exponential
> > growth. My point is, that there is no accidental exponential growth,
> > because the programmer has to explicitly denote the usage with the
> > [[generic]] attribute.
>
> You may notice I ignored your emails talking about the attribute because
> that's an invalid use of an attribute. An attribute must be ignorable by a
> compiler that doesn't know it and the program must still compile the same
> way
> and run the same way.
>
> You need a new keyword or a new operator.
>
> --
> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
> Software Architect - Intel Open Source Technology Center
>
>
--
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/db4b235b-20aa-4acf-84c0-c79998f94cff%40isocpp.org.
------=_Part_4466_1056312602.1495645985964
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Thanks for the hint. When you replace all occurences of [[=
generic]] with generic, it should be ok.<br><br><div style=3D"background-co=
lor:rgb(250,250,250);border-color:rgb(187,187,187);border-style:solid;borde=
r-width:1px"><code><div><div style=3D"background-color: rgb(250, 250, 250);=
border-color: rgb(187, 187, 187); border-style: solid; border-width: 1px; =
overflow-wrap: break-word;" class=3D"prettyprint"><code class=3D"prettyprin=
t"><div class=3D"subprettyprint"><span style=3D"color: #800;" class=3D"styl=
ed-by-prettify">//generic lambda</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br>generic </span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">[](</span><span style=3D"color: #008;" class=3D"s=
tyled-by-prettify">bool</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> runtime_condition</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">)</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=
=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">if</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify">runtime_condi=
tion</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 <=
/span><span style=3D"color: #008;" class=3D"styled-by-prettify">return</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> A</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 =C2=A0 </span><sp=
an 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">else</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"style=
d-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:=
#008;" class=3D"styled-by-prettify">return</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> B</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">{};</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">}</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"><br></span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">}</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"><br><br></span><span style=3D"color: #800;" class=3D"styled-by-prettify">=
// generic function</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br>generic </span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">auto</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> doit</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
(</span><span style=3D"color: #008;" class=3D"styled-by-prettify">bool</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> runtime_condit=
ion</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span sty=
le=3D"color: #008;" class=3D"styled-by-prettify">if</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify">runtime_condition</span><span style=3D"colo=
r: #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"color: #000;" class=3D"styled-b=
y-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color: #0=
08;" class=3D"styled-by-prettify">return</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify"> A</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">{};</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">}</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-pre=
ttify">else</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"><br>=C2=A0 =C2=A0=
=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-prett=
ify">return</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> B</span><span style=3D"color: #660;" class=3D"styled-by-prettify">{};</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=
=A0 </span><span style=3D"color: #660;" class=3D"styled-by-prettify">}</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> =C2=A0 =C2=A0<=
br></span><span style=3D"color: #660;" class=3D"styled-by-prettify">}</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span><=
span style=3D"color: #800;" class=3D"styled-by-prettify">// generic functio=
n with generic ternary operator</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"><br>generic </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">auto</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> doit</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">(</span><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">bool</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> r=
untime_condition</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">)</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </s=
pan><span style=3D"color: #008;" class=3D"styled-by-prettify">return</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> runtime_conditio=
n </span><span style=3D"color: #660;" class=3D"styled-by-prettify">[[</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify">generic</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">]]</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">?</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify"> A</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">{}</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">:</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> B=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">{};</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">}</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"><br><br><br><br></span><span sty=
le=3D"color: #800;" class=3D"styled-by-prettify">// generic variable</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span =
style=3D"color: #008;" class=3D"styled-by-prettify">void</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> doit</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #00=
8;" class=3D"styled-by-prettify">bool</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> runtime_condition</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">)</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"><br>=C2=A0 =C2=A0 generic </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">auto</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> x</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
><br><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-=
by-prettify">if</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">runt=
ime_condition</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">)</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0=
=C2=A0 x </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> A</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">{};</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </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: #008;" class=3D"styled-by-prettify">else</span><span style=3D"color:=
#000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 x </span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> B</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 =C2=A0 </span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">}</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> =C2=A0 =C2=A0<br></span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">}</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"><br><br></span><span style=3D"color: #800;" class=3D"sty=
led-by-prettify">// generic variable with concept</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #00=
8;" class=3D"styled-by-prettify">void</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> doit</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">(</span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">bool</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> runtime_condition</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">)</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> </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=
=C2=A0 generic </span><span style=3D"color: #606;" class=3D"styled-by-pret=
tify">Iteratable</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> x</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br>=C2=
=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-prettify"=
>if</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify">runtime_conditio=
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 styl=
e=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 x </=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> A</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">{};</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">}</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;=
" class=3D"styled-by-prettify">else</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 x </span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> B</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">{};</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">}</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> =C2=A0 =C2=A0<br></span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">}</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"><br></span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
><br></span></div></code></div></div></code></div><br><br>Am Mittwoch, 24. =
Mai 2017 18:50:32 UTC+2 schrieb Thiago Macieira:<blockquote class=3D"gmail_=
quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;pa=
dding-left: 1ex;">On Tuesday, 23 May 2017 11:20:17 PDT <a href=3D"javascrip=
t:" target=3D"_blank" gdf-obfuscated-mailto=3D"947EZAgrBgAJ" rel=3D"nofollo=
w" onmousedown=3D"this.href=3D'javascript:';return true;" onclick=
=3D"this.href=3D'javascript:';return true;">ma.ka...@web.de</a> wro=
te:
<br>> Sorry. This was misleading. I know that we cannot avoid the expone=
ntial
<br>> growth. My point is, that there is no accidental exponential growt=
h,
<br>> because the programmer has to explicitly denote the usage with the
<br>> [[generic]] attribute.
<br>
<br>You may notice I ignored your emails talking about the attribute becaus=
e=20
<br>that's an invalid use of an attribute. An attribute must be ignorab=
le by a=20
<br>compiler that doesn't know it and the program must still compile th=
e same way=20
<br>and run the same way.
<br>
<br>You need a new keyword or a new operator.
<br>
<br>--=20
<br>Thiago Macieira - thiago (AT) <a href=3D"http://macieira.info" target=
=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D'http://www.goo=
gle.com/url?q\x3dhttp%3A%2F%2Fmacieira.info\x26sa\x3dD\x26sntz\x3d1\x26usg\=
x3dAFQjCNEswDUBNCNanbu7euhqLn_62FW8ag';return true;" onclick=3D"this.hr=
ef=3D'http://www.google.com/url?q\x3dhttp%3A%2F%2Fmacieira.info\x26sa\x=
3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEswDUBNCNanbu7euhqLn_62FW8ag';return t=
rue;">macieira.info</a> - thiago (AT) <a href=3D"http://kde.org" target=3D"=
_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D'http://www.google.=
com/url?q\x3dhttp%3A%2F%2Fkde.org\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH=
GRJdo5_JYG1DowztwAHAKs80XSA';return true;" onclick=3D"this.href=3D'=
http://www.google.com/url?q\x3dhttp%3A%2F%2Fkde.org\x26sa\x3dD\x26sntz\x3d1=
\x26usg\x3dAFQjCNHGRJdo5_JYG1DowztwAHAKs80XSA';return true;">kde.org</a=
>
<br>=C2=A0 =C2=A0Software Architect - Intel Open Source Technology Center
<br>
<br></blockquote></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/db4b235b-20aa-4acf-84c0-c79998f94cff%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/db4b235b-20aa-4acf-84c0-c79998f94cff=
%40isocpp.org</a>.<br />
------=_Part_4466_1056312602.1495645985964--
------=_Part_4465_213730374.1495645985963--
.
Author: "ma.kalbfuss via ISO C++ Standard - Future Proposals" <std-proposals@isocpp.org>
Date: Wed, 24 May 2017 10:22:37 -0700 (PDT)
Raw View
------=_Part_4345_686045255.1495646557788
Content-Type: multipart/alternative;
boundary="----=_Part_4346_181368823.1495646557789"
------=_Part_4346_181368823.1495646557789
Content-Type: text/plain; charset="UTF-8"
Thanks for the hint. When you replace all occurences of [[generic]] with
generic, it should be ok.
//generic lambda
generic [](bool runtime_condition) {
if(runtime_condition) {
return A{};
} else {
return B{};
}
}
// generic function
generic auto doit(bool runtime_condition) {
if(runtime_condition) {
return A{};
} else {
return B{};
}
}
// generic function with generic ternary operator
generic auto doit(bool runtime_condition) {
return runtime_condition generic ? A{} : B{};
}
// generic variable
void doit(bool runtime_condition) {
generic auto x;
if(runtime_condition) {
x = A{};
} else {
x = B{};
}
}
// generic variable with concept
void doit(bool runtime_condition) {
generic Iteratable x;
if(runtime_condition) {
x = A{};
} else {
x = B{};
}
}
As an alternative generic could be a compile time variant. But this way,
the ternary operator could not be marked as generic.
//generic lambda
[](bool runtime_condition)-> generic(auto) {
if(runtime_condition) {
return A{};
} else {
return B{};
}
}
// generic function
generic(auto) doit(bool runtime_condition) {
if(runtime_condition) {
return A{};
} else {
return B{};
}
}
// generic function with generic ternary operator
generic(auto) doit(bool runtime_condition) {
return runtime_condition [[generic]] ? A{} : B{};
}
// generic variable
void doit(bool runtime_condition) {
generic(auto) x;
if(runtime_condition) {
x = A{};
} else {
x = B{};
}
}
// generic variable with concept
void doit(bool runtime_condition) {
generic(Iteratable) x;
if(runtime_condition) {
x = A{};
} else {
x = B{};
}
}
The second version could be extended with limited type sets. For example
generic(int, float, double). Or with concepts: generic(Iteratable,
Indexable) or something like that.
I'm unsure abour generic(auto). Maybe generic(...) or generic(any). or a
simple generic.
Am Mittwoch, 24. Mai 2017 18:50:32 UTC+2 schrieb Thiago Macieira:
>
> On Tuesday, 23 May 2017 11:20:17 PDT ma.ka...@web.de <javascript:> wrote:
> > Sorry. This was misleading. I know that we cannot avoid the exponential
> > growth. My point is, that there is no accidental exponential growth,
> > because the programmer has to explicitly denote the usage with the
> > [[generic]] attribute.
>
> You may notice I ignored your emails talking about the attribute because
> that's an invalid use of an attribute. An attribute must be ignorable by a
> compiler that doesn't know it and the program must still compile the same
> way
> and run the same way.
>
> You need a new keyword or a new operator.
>
> --
> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
> Software Architect - Intel Open Source Technology Center
>
>
--
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/f52cf902-0153-4e56-b993-3f36660bd451%40isocpp.org.
------=_Part_4346_181368823.1495646557789
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Thanks for the hint. When you replace all occurences of [[=
generic]] with generic, it should be ok.<br><br><div style=3D"background-co=
lor:rgb(250,250,250);border-color:rgb(187,187,187);border-style:solid;borde=
r-width:1px"><code><div><div style=3D"background-color:rgb(250,250,250);bor=
der-color:rgb(187,187,187);border-style:solid;border-width:1px"><code><div>=
<span style=3D"color:#800">//generic lambda</span><span style=3D"color:#000=
"><br>generic </span><span style=3D"color:#660">[](</span><span style=3D"co=
lor:#008">bool</span><span style=3D"color:#000"> runtime_condition</span><s=
pan style=3D"color:#660">)</span><span style=3D"color:#000"> </span><span s=
tyle=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </=
span><span style=3D"color:#008">if</span><span style=3D"color:#660">(</span=
><span style=3D"color:#000">runtime_condition</span><span style=3D"color:#6=
60">)</span><span style=3D"color:#000"> </span><span style=3D"color:#660">{=
</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><s=
pan style=3D"color:#008">return</span><span style=3D"color:#000"> A</span><=
span style=3D"color:#660">{};</span><span style=3D"color:#000"><br>=C2=A0 =
=C2=A0 </span><span style=3D"color:#660">}</span><span style=3D"color:#000"=
> </span><span style=3D"color:#008">else</span><span style=3D"color:#000"> =
</span><span style=3D"color:#660">{</span><span style=3D"color:#000"><br>=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#008">return</span>=
<span style=3D"color:#000"> B</span><span style=3D"color:#660">{};</span><s=
pan style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#660=
">}</span><span style=3D"color:#000"><br></span><span style=3D"color:#660">=
}</span><span style=3D"color:#000"><br><br></span><span style=3D"color:#800=
">// generic function</span><span style=3D"color:#000"><br>generic </span><=
span style=3D"color:#008">auto</span><span style=3D"color:#000"> doit</span=
><span style=3D"color:#660">(</span><span style=3D"color:#008">bool</span><=
span style=3D"color:#000"> runtime_condition</span><span style=3D"color:#66=
0">)</span><span style=3D"color:#000"> </span><span style=3D"color:#660">{<=
/span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"co=
lor:#008">if</span><span style=3D"color:#660">(</span><span style=3D"color:=
#000">runtime_condition</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"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#00=
8">return</span><span style=3D"color:#000"> A</span><span style=3D"color:#6=
60">{};</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span sty=
le=3D"color:#660">}</span><span style=3D"color:#000"> </span><span style=3D=
"color:#008">else</span><span style=3D"color:#000"> </span><span style=3D"c=
olor:#660">{</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=
=A0 </span><span style=3D"color:#008">return</span><span style=3D"color:#00=
0"> B</span><span style=3D"color:#660">{};</span><span style=3D"color:#000"=
><br>=C2=A0 =C2=A0 </span><span style=3D"color:#660">}</span><span style=3D=
"color:#000"> =C2=A0 =C2=A0<br></span><span style=3D"color:#660">}</span><s=
pan style=3D"color:#000"><br><br></span><span style=3D"color:#800">// gener=
ic function with generic ternary operator</span><span style=3D"color:#000">=
<br>generic </span><span style=3D"color:#008">auto</span><span style=3D"col=
or:#000"> doit</span><span style=3D"color:#660">(</span><span style=3D"colo=
r:#008">bool</span><span style=3D"color:#000"> runtime_condition</span><spa=
n style=3D"color:#660">)</span><span style=3D"color:#000"> </span><span sty=
le=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </sp=
an><span style=3D"color:#008">return</span><span style=3D"color:#000"> runt=
ime_condition </span><span style=3D"color:#660"></span><span style=3D"color=
:#000">generic</span><span style=3D"color:#660"></span><span style=3D"color=
:#000"> </span><span style=3D"color:#660">?</span><span style=3D"color:#000=
"> A</span><span style=3D"color:#660">{}</span><span style=3D"color:#000"> =
</span><span style=3D"color:#660">:</span><span style=3D"color:#000"> B</sp=
an><span style=3D"color:#660">{};</span><span style=3D"color:#000"><br></sp=
an><span style=3D"color:#660">}</span><span style=3D"color:#000"><br><br><b=
r><br></span><span style=3D"color:#800">// generic variable</span><span sty=
le=3D"color:#000"><br></span><span style=3D"color:#008">void</span><span st=
yle=3D"color:#000"> doit</span><span style=3D"color:#660">(</span><span sty=
le=3D"color:#008">bool</span><span style=3D"color:#000"> runtime_condition<=
/span><span style=3D"color:#660">)</span><span style=3D"color:#000"> </span=
><span style=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 =
=C2=A0 generic </span><span style=3D"color:#008">auto</span><span style=3D"=
color:#000"> x</span><span style=3D"color:#660">;</span><span style=3D"colo=
r:#000"><br><br>=C2=A0 =C2=A0 </span><span style=3D"color:#008">if</span><s=
pan style=3D"color:#660">(</span><span style=3D"color:#000">runtime_conditi=
on</span><span style=3D"color:#660">)</span><span style=3D"color:#000"> </s=
pan><span style=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 x </span><span style=3D"color:#660">=3D</span><spa=
n style=3D"color:#000"> A</span><span style=3D"color:#660">{};</span><span =
style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#660">}<=
/span><span style=3D"color:#000"> </span><span style=3D"color:#008">else</s=
pan><span style=3D"color:#000"> </span><span style=3D"color:#660">{</span><=
span style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 x </span><span st=
yle=3D"color:#660">=3D</span><span style=3D"color:#000"> B</span><span styl=
e=3D"color:#660">{};</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </s=
pan><span style=3D"color:#660">}</span><span style=3D"color:#000"> =C2=A0 =
=C2=A0<br></span><span style=3D"color:#660">}</span><span style=3D"color:#0=
00"><br><br></span><span style=3D"color:#800">// generic variable with conc=
ept</span><span style=3D"color:#000"><br></span><span style=3D"color:#008">=
void</span><span style=3D"color:#000"> doit</span><span style=3D"color:#660=
">(</span><span style=3D"color:#008">bool</span><span style=3D"color:#000">=
runtime_condition</span><span style=3D"color:#660">)</span><span style=3D"=
color:#000"> </span><span style=3D"color:#660">{</span><span style=3D"color=
:#000"><br>=C2=A0 =C2=A0 generic </span><span style=3D"color:#606">Iteratab=
le</span><span style=3D"color:#000"> x</span><span style=3D"color:#660">;</=
span><span style=3D"color:#000"><br><br>=C2=A0 =C2=A0 </span><span style=3D=
"color:#008">if</span><span style=3D"color:#660">(</span><span style=3D"col=
or:#000">runtime_condition</span><span style=3D"color:#660">)</span><span s=
tyle=3D"color:#000"> </span><span style=3D"color:#660">{</span><span style=
=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 x </span><span style=3D"col=
or:#660">=3D</span><span style=3D"color:#000"> A</span><span style=3D"color=
:#660">{};</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span =
style=3D"color:#660">}</span><span style=3D"color:#000"> </span><span style=
=3D"color:#008">else</span><span style=3D"color:#000"> </span><span style=
=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0=
=C2=A0 x </span><span style=3D"color:#660">=3D</span><span style=3D"color:=
#000"> B</span><span style=3D"color:#660">{};</span><span style=3D"color:#0=
00"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#660">}</span><span style=
=3D"color:#000"> =C2=A0 =C2=A0<br></span><span style=3D"color:#660">}</span=
><span style=3D"color:#000"><br></span><span style=3D"color:#000"><br></spa=
n></div></code></div></div></code></div><br><br>As an alternative generic c=
ould be a compile time variant. But this way, the ternary operator could no=
t be marked as generic.<br><br><br><div style=3D"background-color:rgb(250,2=
50,250);border-color:rgb(187,187,187);border-style:solid;border-width:1px">=
<code><div><div style=3D"background-color:rgb(250,250,250);border-color:rgb=
(187,187,187);border-style:solid;border-width:1px"><code><div><span style=
=3D"color:#800">//generic lambda</span><span style=3D"color:#000"><br></spa=
n><span style=3D"color:#660">[](</span><span style=3D"color:#008">bool</spa=
n><span style=3D"color:#000"> runtime_condition</span><span style=3D"color:=
#660">)</span><span style=3D"color:#000">-> generic(auto) </span><span s=
tyle=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </=
span><span style=3D"color:#008">if</span><span style=3D"color:#660">(</span=
><span style=3D"color:#000">runtime_condition</span><span style=3D"color:#6=
60">)</span><span style=3D"color:#000"> </span><span style=3D"color:#660">{=
</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><s=
pan style=3D"color:#008">return</span><span style=3D"color:#000"> A</span><=
span style=3D"color:#660">{};</span><span style=3D"color:#000"><br>=C2=A0 =
=C2=A0 </span><span style=3D"color:#660">}</span><span style=3D"color:#000"=
> </span><span style=3D"color:#008">else</span><span style=3D"color:#000"> =
</span><span style=3D"color:#660">{</span><span style=3D"color:#000"><br>=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#008">return</span>=
<span style=3D"color:#000"> B</span><span style=3D"color:#660">{};</span><s=
pan style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#660=
">}</span><span style=3D"color:#000"><br></span><span style=3D"color:#660">=
}</span><span style=3D"color:#000"><br><br></span><span style=3D"color:#800=
">// generic function</span><span style=3D"color:#000"><br></span><code><co=
de><span style=3D"color:#000">generic(auto)</span></code></code><span style=
=3D"color:#000"> doit</span><span style=3D"color:#660">(</span><span style=
=3D"color:#008">bool</span><span style=3D"color:#000"> runtime_condition</s=
pan><span style=3D"color:#660">)</span><span style=3D"color:#000"> </span><=
span style=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 =C2=
=A0 </span><span style=3D"color:#008">if</span><span style=3D"color:#660">(=
</span><span style=3D"color:#000">runtime_condition</span><span style=3D"co=
lor:#660">)</span><span style=3D"color:#000"> </span><span style=3D"color:#=
660">{</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </s=
pan><span style=3D"color:#008">return</span><span style=3D"color:#000"> A</=
span><span style=3D"color:#660">{};</span><span style=3D"color:#000"><br>=
=C2=A0 =C2=A0 </span><span style=3D"color:#660">}</span><span style=3D"colo=
r:#000"> </span><span style=3D"color:#008">else</span><span style=3D"color:=
#000"> </span><span style=3D"color:#660">{</span><span style=3D"color:#000"=
><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#008">return</=
span><span style=3D"color:#000"> B</span><span style=3D"color:#660">{};</sp=
an><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color=
:#660">}</span><span style=3D"color:#000"> =C2=A0 =C2=A0<br></span><span st=
yle=3D"color:#660">}</span><span style=3D"color:#000"><br><br></span><span =
style=3D"color:#800">// generic function with generic ternary operator</spa=
n><span style=3D"color:#000"><br></span><code><code><span style=3D"color:#0=
00">generic(auto)</span></code></code><span style=3D"color:#008"></span><sp=
an style=3D"color:#000"> doit</span><span style=3D"color:#660">(</span><spa=
n style=3D"color:#008">bool</span><span style=3D"color:#000"> runtime_condi=
tion</span><span style=3D"color:#660">)</span><span style=3D"color:#000"> <=
/span><span style=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=
=A0 =C2=A0 </span><span style=3D"color:#008">return</span><span style=3D"co=
lor:#000"> runtime_condition </span><span style=3D"color:#660">[[</span><sp=
an style=3D"color:#000">generic</span><span style=3D"color:#660">]]</span><=
span style=3D"color:#000"> </span><span style=3D"color:#660">?</span><span =
style=3D"color:#000"> A</span><span style=3D"color:#660">{}</span><span sty=
le=3D"color:#000"> </span><span style=3D"color:#660">:</span><span style=3D=
"color:#000"> B</span><span style=3D"color:#660">{};</span><span style=3D"c=
olor:#000"><br></span><span style=3D"color:#660">}</span><span style=3D"col=
or:#000"><br><br><br><br></span><span style=3D"color:#800">// generic varia=
ble</span><span style=3D"color:#000"><br></span><span style=3D"color:#008">=
void</span><span style=3D"color:#000"> doit</span><span style=3D"color:#660=
">(</span><span style=3D"color:#008">bool</span><span style=3D"color:#000">=
runtime_condition</span><span style=3D"color:#660">)</span><span style=3D"=
color:#000"> </span><span style=3D"color:#660">{</span><span style=3D"color=
:#000"><br>=C2=A0 =C2=A0 generic(</span><span style=3D"color:#008">auto)</s=
pan><span style=3D"color:#000"> x</span><span style=3D"color:#660">;</span>=
<span style=3D"color:#000"><br><br>=C2=A0 =C2=A0 </span><span style=3D"colo=
r:#008">if</span><span style=3D"color:#660">(</span><span style=3D"color:#0=
00">runtime_condition</span><span style=3D"color:#660">)</span><span style=
=3D"color:#000"> </span><span style=3D"color:#660">{</span><span style=3D"c=
olor:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 x </span><span style=3D"color:#6=
60">=3D</span><span style=3D"color:#000"> A</span><span style=3D"color:#660=
">{};</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=
=3D"color:#660">}</span><span style=3D"color:#000"> </span><span style=3D"c=
olor:#008">else</span><span style=3D"color:#000"> </span><span style=3D"col=
or:#660">{</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0=
x </span><span style=3D"color:#660">=3D</span><span style=3D"color:#000"> =
B</span><span style=3D"color:#660">{};</span><span style=3D"color:#000"><br=
>=C2=A0 =C2=A0 </span><span style=3D"color:#660">}</span><span style=3D"col=
or:#000"> =C2=A0 =C2=A0<br></span><span style=3D"color:#660">}</span><span =
style=3D"color:#000"><br><br></span><span style=3D"color:#800">// generic v=
ariable with concept</span><span style=3D"color:#000"><br></span><span styl=
e=3D"color:#008">void</span><span style=3D"color:#000"> doit</span><span st=
yle=3D"color:#660">(</span><span style=3D"color:#008">bool</span><span styl=
e=3D"color:#000"> runtime_condition</span><span style=3D"color:#660">)</spa=
n><span style=3D"color:#000"> </span><span style=3D"color:#660">{</span><sp=
an style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#000"=
><code><code><span style=3D"color:#000">generic(</span></code></code></span=
><span style=3D"color:#606">Iteratable)</span><span style=3D"color:#000"> x=
</span><span style=3D"color:#660">;</span><span style=3D"color:#000"><br><b=
r>=C2=A0 =C2=A0 </span><span style=3D"color:#008">if</span><span style=3D"c=
olor:#660">(</span><span style=3D"color:#000">runtime_condition</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"><br>=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 x </span><span style=3D"color:#660">=3D</span><span style=3D"col=
or:#000"> A</span><span style=3D"color:#660">{};</span><span style=3D"color=
:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#660">}</span><span st=
yle=3D"color:#000"> </span><span style=3D"color:#008">else</span><span styl=
e=3D"color:#000"> </span><span style=3D"color:#660">{</span><span style=3D"=
color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 x </span><span style=3D"color:#=
660">=3D</span><span style=3D"color:#000"> B</span><span style=3D"color:#66=
0">{};</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span styl=
e=3D"color:#660">}</span><span style=3D"color:#000"> =C2=A0 =C2=A0<br></spa=
n><span style=3D"color:#660">}</span><span style=3D"color:#000"><br></span>=
<span style=3D"color:#000"><br></span></div></code></div></div></code></div=
><br>The second version could be extended with limited type sets. For examp=
le generic(int, float, double). Or with concepts: generic(Iteratable, Index=
able) or something like that.<br>I'm unsure abour generic(auto). Maybe =
generic(...) or generic(any). or a simple generic.<br><br><br>Am Mittwoch, =
24. Mai 2017 18:50:32 UTC+2 schrieb Thiago Macieira:<blockquote class=3D"gm=
ail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc soli=
d;padding-left: 1ex;">On Tuesday, 23 May 2017 11:20:17 PDT <a href=3D"javas=
cript:" target=3D"_blank" gdf-obfuscated-mailto=3D"947EZAgrBgAJ" rel=3D"nof=
ollow" onmousedown=3D"this.href=3D'javascript:';return true;" oncli=
ck=3D"this.href=3D'javascript:';return true;">ma.ka...@web.de</a> w=
rote:
<br>> Sorry. This was misleading. I know that we cannot avoid the expone=
ntial
<br>> growth. My point is, that there is no accidental exponential growt=
h,
<br>> because the programmer has to explicitly denote the usage with the
<br>> [[generic]] attribute.
<br>
<br>You may notice I ignored your emails talking about the attribute becaus=
e=20
<br>that's an invalid use of an attribute. An attribute must be ignorab=
le by a=20
<br>compiler that doesn't know it and the program must still compile th=
e same way=20
<br>and run the same way.
<br>
<br>You need a new keyword or a new operator.
<br>
<br>--=20
<br>Thiago Macieira - thiago (AT) <a href=3D"http://macieira.info" target=
=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D'http://www.goo=
gle.com/url?q\x3dhttp%3A%2F%2Fmacieira.info\x26sa\x3dD\x26sntz\x3d1\x26usg\=
x3dAFQjCNEswDUBNCNanbu7euhqLn_62FW8ag';return true;" onclick=3D"this.hr=
ef=3D'http://www.google.com/url?q\x3dhttp%3A%2F%2Fmacieira.info\x26sa\x=
3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEswDUBNCNanbu7euhqLn_62FW8ag';return t=
rue;">macieira.info</a> - thiago (AT) <a href=3D"http://kde.org" target=3D"=
_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D'http://www.google.=
com/url?q\x3dhttp%3A%2F%2Fkde.org\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH=
GRJdo5_JYG1DowztwAHAKs80XSA';return true;" onclick=3D"this.href=3D'=
http://www.google.com/url?q\x3dhttp%3A%2F%2Fkde.org\x26sa\x3dD\x26sntz\x3d1=
\x26usg\x3dAFQjCNHGRJdo5_JYG1DowztwAHAKs80XSA';return true;">kde.org</a=
>
<br>=C2=A0 =C2=A0Software Architect - Intel Open Source Technology Center
<br>
<br></blockquote></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/f52cf902-0153-4e56-b993-3f36660bd451%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/f52cf902-0153-4e56-b993-3f36660bd451=
%40isocpp.org</a>.<br />
------=_Part_4346_181368823.1495646557789--
------=_Part_4345_686045255.1495646557788--
.