Topic: std::meta_switch
Author: Hamza Sood <hamza_sood@me.com>
Date: Tue, 27 Mar 2018 05:40:43 -0700 (PDT)
Raw View
------=_Part_17725_1746844447.1522154443510
Content-Type: multipart/alternative;
boundary="----=_Part_17726_842054172.1522154443511"
------=_Part_17726_842054172.1522154443511
Content-Type: text/plain; charset="UTF-8"
Suppose you want to select a type based on a condition. You can do this
with template specialisations at the language level:
template<bool>
struct MySelector;
template<>
struct MySelector<false> { typedef TypeIfFalse type; };
template<>
struct MySelector<true> { typedef TypeIfTrue type; };
But that's a lot of boilerplate, so C++11 introduced std::conditional.
Now instead suppose that you want to select a type based on the value of
(non-boolean) non-type template parameter.
You can either do the same specialisation trick:
template<int>
struct MySelector;
template<>
struct MySelector<0> { typedef FirstType type; };
template<>
struct MySelector<1> { typedef SecondType type; };
template<>
struct MySelector<2> { typedef ThirdType type; };
// etc.
// Potentially lots of other cases here...
which is a bit cumbersome. Or you can try to chain std::conditionals:
template<int i>
using MyType = std::conditional_t<i == 0, FirstType,
std::conditional_t<i == 1, SecondType,
std::conditional_t<i ==
2, ThirdType, /* potentially lots more stuff here... */>>>;
which is even worse.
I propose that a meta_switch type (better name welcome) is added to
<type_traits>, to enable code such as:
template<int i>
using MyType = std::meta_switch_t<i,
0, FirstType,
1, SecondType,
2, ThirdType,
// etc.
>;
--
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/6b032496-9214-4a13-a5fc-46fa774a4261%40isocpp.org.
------=_Part_17726_842054172.1522154443511
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Suppose you want to select a type based on a condition. Yo=
u can do this with template specialisations at the language level:<div><br>=
<div><div><div class=3D"prettyprint" style=3D"background-color: rgb(250, 25=
0, 250); border: 1px solid rgb(187, 187, 187); word-wrap: break-word;"><cod=
e class=3D"prettyprint"><div class=3D"subprettyprint" style=3D"caret-color:=
rgb(102, 0, 102);"><font color=3D"#660066"><span style=3D"color: #008;" cl=
ass=3D"styled-by-prettify">template</span><span style=3D"color: #080;" clas=
s=3D"styled-by-prettify"><bool></span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" class=3D=
"styled-by-prettify">struct</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #606;" class=3D"styled-by-pr=
ettify">MySelector</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">tem=
plate</span><span style=3D"color: #660;" class=3D"styled-by-prettify"><&=
gt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></s=
pan><span style=3D"color: #008;" class=3D"styled-by-prettify">struct</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span sty=
le=3D"color: #606;" class=3D"styled-by-prettify">MySelector</span><span sty=
le=3D"color: #080;" class=3D"styled-by-prettify"><false></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"> </span><span style=3D"color: #008;" clas=
s=3D"styled-by-prettify">typedef</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=3D"style=
d-by-prettify">TypeIfFalse</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> type</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">};</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span>=
</font><span style=3D"color: #008;" class=3D"styled-by-prettify">template</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify"><></sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">struct</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #606;" class=3D"styled-by-prettify">MySelector</span><span style=3D"c=
olor: #080;" class=3D"styled-by-prettify"><true></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;" cla=
ss=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"sty=
led-by-prettify">typedef</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> </span><span style=3D"color: #606;" class=3D"styled-by-prett=
ify">TypeIfTrue</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> type</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></div></c=
ode></div><div><br></div>But that's a lot of boilerplate, so C++11 intr=
oduced std::conditional.</div></div><div><br></div><div><br></div><div><br>=
</div><div>Now instead suppose that you want to select a type based on the =
value of (non-boolean) non-type template parameter.</div><div>You can eithe=
r do the same specialisation trick:</div><div><br></div><div><div class=3D"=
prettyprint" style=3D"background-color: rgb(250, 250, 250); border: 1px sol=
id rgb(187, 187, 187); word-wrap: break-word;"><code class=3D"prettyprint">=
<div class=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled-=
by-prettify">template</span><span style=3D"color: #080;" class=3D"styled-by=
-prettify"><int></span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"><br></span><span style=3D"color: #008;" class=3D"styled-by-pret=
tify">struct</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">MySelec=
tor</span><span style=3D"color: rgb(102, 102, 0); font-family: Arial, Helve=
tica, sans-serif;"><span style=3D"color: #660;" class=3D"styled-by-prettify=
">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></s=
pan></span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></=
span><span style=3D"color: #008;" class=3D"styled-by-prettify">template</sp=
an><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">struct</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"col=
or: #606;" class=3D"styled-by-prettify">MySelector</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify"><</span><span style=3D"color: #0=
66;" class=3D"styled-by-prettify">0</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">></span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">typedef<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an style=3D"color: #606;" class=3D"styled-by-prettify">FirstType</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> type</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: #660;=
" class=3D"styled-by-prettify">};</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br><br></span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">template</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"st=
yled-by-prettify">struct</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> </span><span style=3D"color: #606;" class=3D"styled-by-prett=
ify">MySelector</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify"><</span><span style=3D"color: #066;" class=3D"styled-by-prettify">1=
</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"> </span><span style=3D"color: #008=
;" class=3D"styled-by-prettify">typedef</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=3D"=
styled-by-prettify">SecondType</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> type</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">};<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br></s=
pan><span style=3D"color: #008;" class=3D"styled-by-prettify">template</spa=
n><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">struct</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #606;" class=3D"styled-by-prettify">MySelector</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify"><</span><font color=3D"#006666"><=
span style=3D"color: #066;" class=3D"styled-by-prettify">2</span></font><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">></span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"col=
or: #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">typedef</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> </span><span style=3D"color: #606;" class=3D"styled-b=
y-prettify">ThirdType</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> type</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><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span><span=
style=3D"color: #800;" class=3D"styled-by-prettify">// etc.</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D=
"color: #800;" class=3D"styled-by-prettify">// Potentially lots of other ca=
ses here...</span></div></code></div><div><br></div>which is a bit cumberso=
me. Or you can try to chain std::conditionals:</div><div><br></div><div><di=
v class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); bord=
er: 1px solid rgb(187, 187, 187); word-wrap: break-word;"><code class=3D"pr=
ettyprint"><div class=3D"subprettyprint"><font><span style=3D"color: #008;"=
class=3D"styled-by-prettify">template</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify"><</span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">int</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> i</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">></span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">usi=
ng</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span>=
<span style=3D"color: #606;" class=3D"styled-by-prettify">MyType</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> std</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">::</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify">conditional_t</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify"><</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">i </span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">=3D=3D</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> </span><span style=3D"color: #066;" class=3D"styled-by-prettif=
y">0</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: #606;" class=3D"styled-by-prettify">FirstType</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 =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 std</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y">conditional_t</span><font color=3D"#008800"><span style=3D"color: #660;"=
class=3D"styled-by-prettify"><</span><span style=3D"caret-color: rgb(0,=
136, 0);"><span style=3D"color: #000;" class=3D"styled-by-prettify">i</spa=
n></span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">=3D=3D</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #066;" class=3D"styled-by-prettify">1</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: #606;" class=3D"=
styled-by-prettify">SecondType</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"><br></span></font><span style=3D"color: #000;" class=3D"styled-b=
y-prettify">=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 =C2=A0 =C2=A0 =C2=A0std</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify">conditional_t</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify"><</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify">i </span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">=3D=3D</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #066;" class=3D"style=
d-by-prettify">2</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: #606;" class=3D"styled-by-prettify">ThirdType</s=
pan><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: #800;" class=3D"styled-by-prettify">/* potentially lots more stuff =
here... */</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
>>>;</span></font></div></code></div><div><br></div>which is even =
worse.</div><div><br></div><div><br></div><div><br></div><div>I propose tha=
t a meta_switch type (better name welcome) is added to <type_traits>,=
to enable code such as:</div><div><br></div><div><div class=3D"prettyprint=
" style=3D"background-color: rgb(250, 250, 250); border: 1px solid rgb(187,=
187, 187); word-wrap: break-word;"><code class=3D"prettyprint"><div class=
=3D"subprettyprint"><font><span style=3D"color: #008;" class=3D"styled-by-p=
rettify">template</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify"><</span><span style=3D"color: #008;" class=3D"styled-by-prettify"=
>int</span><font color=3D"#000000"><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> i</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">></span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">us=
ing</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span style=3D"color: #606;" class=3D"styled-by-prettify">MyType</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> std</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">::</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify">meta_switch_t</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify"><</span><span style=3D"caret-color: rgb(102=
, 0, 102);"><span style=3D"color: #000;" class=3D"styled-by-prettify">i</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 </spa=
n><span style=3D"color: #066;" class=3D"styled-by-prettify">0</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: #60=
6;" class=3D"styled-by-prettify">FirstType</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: #066=
;" class=3D"styled-by-prettify">1</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> </span><span style=3D"color: #606;" class=3D"styled-by-pret=
tify">SecondType</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br=
>=C2=A0 =C2=A0 </span><span style=3D"color: #066;" class=3D"styled-by-prett=
ify">2</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span=
style=3D"color: #606;" class=3D"styled-by-prettify">ThirdType</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 s=
tyle=3D"color: #800;" class=3D"styled-by-prettify">// etc.</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></font></font>=
</div></code></div></div></div><br></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/6b032496-9214-4a13-a5fc-46fa774a4261%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/6b032496-9214-4a13-a5fc-46fa774a4261=
%40isocpp.org</a>.<br />
------=_Part_17726_842054172.1522154443511--
------=_Part_17725_1746844447.1522154443510--
.
Author: Larry Evans <cppljevans@suddenlink.net>
Date: Tue, 27 Mar 2018 08:44:02 -0500
Raw View
On 03/27/2018 07:40 AM, Hamza Sood wrote:
> Suppose you want to select a type based on a condition. You can do this
> with template specialisations at the language level:
[snip]
> I propose that a meta_switch type (better name welcome) is added to
> <type_traits>, to enable code such as:
>
> template<int i>
> using MyType = std::meta_switch_t<i,
> 0, FirstType,
> 1, SecondType,
> 2, ThirdType,
> // etc.
>> ;
>
There's already boost::mpl::at_c:
http://www.boost.org/doc/libs/1_61_0/libs/mpl/doc/refmanual/at-c.html
which is a little different:
template<int i>
using MyType = typename boost::mpl::at_c
< boost::mpl::vector
< FirstType
, SecondType
, ThirdType
// etc.
>
, long(i)
>::type;
I also think there's another intrinsic proposal for something
similar, but with another syntax and using parameter packs.
Please see:
https://groups.google.com/a/isocpp.org/forum/#!msg/std-proposals/ajLcDl8GbpA/uAVgEWI5CAAJ
-regards,
Larry
--
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/p9dhn3%24r8k%241%40blaine.gmane.org.
.
Author: hamza_sood@me.com
Date: Tue, 27 Mar 2018 06:57:25 -0700 (PDT)
Raw View
------=_Part_5157_1076353167.1522159045424
Content-Type: multipart/alternative;
boundary="----=_Part_5158_1535056930.1522159045424"
------=_Part_5158_1535056930.1522159045424
Content-Type: text/plain; charset="UTF-8"
From what I can tell, the links you've posted seem to be solving a
different problem. Accessing a parameter pack by index admittedly solves
the example I posted, however I'm proposing a more generic switch where the
cases aren't necessarily integers in the sequence 0,1,2,...
E.g. they could be arbitrary enum constants:
template<MyEnum x>
using MyType = std::meta_switch_t<x,
MyEnum_SomeValue, int,
MyEnum_AnotherThing, float,
// etc
>;
where the enum values could be 900 and 28712.
Alternatively you could use it to match negative numbers:
template<int i>
using MyType = std::meta_switch_t<I,
-1, FirstType,
-2, SecondType,
// etc.
>;
I don't think that either of those examples are possible with the solutions
that you posted.
On Tuesday, March 27, 2018 at 2:44:17 PM UTC+1, Larry Evans wrote:
>
> On 03/27/2018 07:40 AM, Hamza Sood wrote:
> > Suppose you want to select a type based on a condition. You can do this
> > with template specialisations at the language level:
> [snip]
>
> > I propose that a meta_switch type (better name welcome) is added to
> > <type_traits>, to enable code such as:
> >
> > template<int i>
> > using MyType = std::meta_switch_t<i,
> > 0, FirstType,
> > 1, SecondType,
> > 2, ThirdType,
> > // etc.
> >> ;
> >
> There's already boost::mpl::at_c:
>
> http://www.boost.org/doc/libs/1_61_0/libs/mpl/doc/refmanual/at-c.html
>
> which is a little different:
>
> template<int i>
> using MyType = typename boost::mpl::at_c
> < boost::mpl::vector
> < FirstType
> , SecondType
> , ThirdType
> // etc.
> >
> , long(i)
> >::type;
>
>
> I also think there's another intrinsic proposal for something
> similar, but with another syntax and using parameter packs.
>
> Please see:
>
>
> https://groups.google.com/a/isocpp.org/forum/#!msg/std-proposals/ajLcDl8GbpA/uAVgEWI5CAAJ
>
> -regards,
> Larry
>
>
--
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/1930dfaf-f40d-4d5d-b7ea-30b7d13ab82d%40isocpp.org.
------=_Part_5158_1535056930.1522159045424
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">From what I can tell, the links you've posted seem to =
be solving a different problem. Accessing a parameter pack by index admitte=
dly solves the example I posted, however I'm proposing a more generic s=
witch where the cases aren't necessarily integers in the sequence 0,1,2=
,...<div><br></div><div>E.g. they could be arbitrary enum constants:</div><=
div><div class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250=
); border: 1px solid rgb(187, 187, 187); word-wrap: break-word;"><code clas=
s=3D"prettyprint"><div class=3D"subprettyprint" style=3D"caret-color: rgb(1=
02, 0, 102);"><span style=3D"color: #008;" class=3D"styled-by-prettify">tem=
plate</span><span style=3D"color: #660;" class=3D"styled-by-prettify"><<=
/span><span style=3D"color: #606;" class=3D"styled-by-prettify">MyEnum</spa=
n><span style=3D"color: #000;" class=3D"styled-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></span><span style=3D"co=
lor: #008;" class=3D"styled-by-prettify">using</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #606;" cl=
ass=3D"styled-by-prettify">MyType</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">=3D</span><font color=3D"#000000"><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> std</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify">meta_switch_t</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify"><</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify">x</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br=
>=C2=A0 =C2=A0 </span><span style=3D"color: #606;" class=3D"styled-by-prett=
ify">MyEnum_SomeValue</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">int</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 </spa=
n><span style=3D"color: #606;" class=3D"styled-by-prettify">MyEnum_AnotherT=
hing</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: #008;" class=3D"styled-by-prettify">float</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: #800;" class=3D"styled-by-prettify">// etc</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color:=
#660;" class=3D"styled-by-prettify">>;</span></font></div></code></div>=
where the enum values could be 900 and 28712.</div><div><br></div><div>Alte=
rnatively you could use it to match negative numbers:</div><div><div class=
=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); border: 1px=
solid rgb(187, 187, 187); word-wrap: break-word;"><code class=3D"prettypri=
nt"><div class=3D"subprettyprint"><font><span style=3D"color: #008;" class=
=3D"styled-by-prettify">template</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify"><</span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">int</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> i</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">></span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br=
></span><span style=3D"color: #008;" class=3D"styled-by-prettify">using</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span =
style=3D"color: #606;" class=3D"styled-by-prettify">MyType</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> std</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify">meta_switch_t</span><span style=3D"caret-color: rgb(102, =
0, 102);"><span style=3D"color: #660;" class=3D"styled-by-prettify"><</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify">I</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: #066;" class=3D"styled-by-prettify">1</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">,</span><font color=3D"#660066"><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"col=
or: #606;" class=3D"styled-by-prettify">FirstType</span><span style=3D"colo=
r: #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: #066;" =
class=3D"styled-by-prettify">2</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: #606;" class=3D"styled-by-prettify=
">SecondType</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: #800;" class=3D"styled-by-prettify"=
>// etc.</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><b=
r></span><span style=3D"color: #660;" class=3D"styled-by-prettify">>;</s=
pan></font></span></font></div></code></div><div><br></div>I don't thin=
k that either of those examples are possible with the solutions that you po=
sted.<br><br></div><div><br>On Tuesday, March 27, 2018 at 2:44:17 PM UTC+1,=
Larry Evans wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;mar=
gin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On 03/27/20=
18 07:40 AM, Hamza Sood wrote:
<br>> Suppose you want to select a type based on a condition. You can do=
this
<br>> with template specialisations at the language level:
<br>[snip]
<br>
<br>> I propose that a meta_switch type (better name welcome) is added t=
o
<br>> <type_traits>, to enable code such as:
<br>>=20
<br>> template<int i>
<br>> using MyType =3D std::meta_switch_t<i,
<br>> =C2=A0 =C2=A0 =C2=A00, FirstType,
<br>> =C2=A0 =C2=A0 =C2=A01, SecondType,
<br>> =C2=A0 =C2=A0 =C2=A02, ThirdType,
<br>> =C2=A0 =C2=A0 =C2=A0// etc.
<br>>> ;
<br>>=20
<br>There's already boost::mpl::at_c:
<br>
<br><a href=3D"http://www.boost.org/doc/libs/1_61_0/libs/mpl/doc/refmanual/=
at-c.html" target=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D&#=
39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.boost.org%2Fdoc%2Flibs%2=
F1_61_0%2Flibs%2Fmpl%2Fdoc%2Frefmanual%2Fat-c.html\x26sa\x3dD\x26sntz\x3d1\=
x26usg\x3dAFQjCNF6J-iP4pPJ79g2VuZnI_Od0nAm1w';return true;" onclick=3D"=
this.href=3D'http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.boost.org%=
2Fdoc%2Flibs%2F1_61_0%2Flibs%2Fmpl%2Fdoc%2Frefmanual%2Fat-c.html\x26sa\x3dD=
\x26sntz\x3d1\x26usg\x3dAFQjCNF6J-iP4pPJ79g2VuZnI_Od0nAm1w';return true=
;">http://www.boost.org/doc/libs/<wbr>1_61_0/libs/mpl/doc/refmanual/<wbr>at=
-c.html</a>
<br>
<br>which is a little different:
<br>
<br>template<int i>
<br>using MyType =3D typename boost::mpl::at_c
<br>=C2=A0 =C2=A0< boost::mpl::vector
<br>=C2=A0 =C2=A0 =C2=A0< FirstType
<br>=C2=A0 =C2=A0 =C2=A0, SecondType
<br>=C2=A0 =C2=A0 =C2=A0, ThirdType
<br>=C2=A0 =C2=A0 =C2=A0// etc.
<br>=C2=A0 =C2=A0 =C2=A0>
<br>=C2=A0 =C2=A0, long(i)
<br>=C2=A0 =C2=A0>::type;
<br>
<br>
<br>I also think there's another intrinsic proposal for something
<br>similar, but with another syntax and using parameter packs.
<br>
<br>Please see:
<br>
<br><a href=3D"https://groups.google.com/a/isocpp.org/forum/#!msg/std-propo=
sals/ajLcDl8GbpA/uAVgEWI5CAAJ" target=3D"_blank" rel=3D"nofollow" onmousedo=
wn=3D"this.href=3D'https://groups.google.com/a/isocpp.org/forum/#!msg/s=
td-proposals/ajLcDl8GbpA/uAVgEWI5CAAJ';return true;" onclick=3D"this.hr=
ef=3D'https://groups.google.com/a/isocpp.org/forum/#!msg/std-proposals/=
ajLcDl8GbpA/uAVgEWI5CAAJ';return true;">https://groups.google.com/a/<wb=
r>isocpp.org/forum/#!msg/std-<wbr>proposals/ajLcDl8GbpA/<wbr>uAVgEWI5CAAJ</=
a>
<br>
<br>-regards,
<br>Larry
<br>
<br></blockquote></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/1930dfaf-f40d-4d5d-b7ea-30b7d13ab82d%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/1930dfaf-f40d-4d5d-b7ea-30b7d13ab82d=
%40isocpp.org</a>.<br />
------=_Part_5158_1535056930.1522159045424--
------=_Part_5157_1076353167.1522159045424--
.
Author: Richard Hodges <hodges.r@gmail.com>
Date: Tue, 27 Mar 2018 14:37:48 +0000
Raw View
--94eb2c0646464e8d16056865d6c8
Content-Type: text/plain; charset="UTF-8"
On Tue, 27 Mar 2018 at 14:40, Hamza Sood <hamza_sood@me.com> wrote:
> Suppose you want to select a type based on a condition. You can do this
> with template specialisations at the language level:
>
> template<bool>
> struct MySelector;
>
> template<>
> struct MySelector<false> { typedef TypeIfFalse type; };
>
> template<>
> struct MySelector<true> { typedef TypeIfTrue type; };
>
> But that's a lot of boilerplate, so C++11 introduced std::conditional.
>
>
>
> Now instead suppose that you want to select a type based on the value of
> (non-boolean) non-type template parameter.
> You can either do the same specialisation trick:
>
> template<int>
> struct MySelector;
>
> template<>
> struct MySelector<0> { typedef FirstType type; };
>
> template<>
> struct MySelector<1> { typedef SecondType type; };
>
> template<>
> struct MySelector<2> { typedef ThirdType type; };
>
> // etc.
> // Potentially lots of other cases here...
>
> which is a bit cumbersome. Or you can try to chain std::conditionals:
>
> template<int i>
> using MyType = std::conditional_t<i == 0, FirstType,
> std::conditional_t<i == 1, SecondType,
> std::conditional_t<i
> == 2, ThirdType, /* potentially lots more stuff here... */>>>;
>
> which is even worse.
>
>
>
> I propose that a meta_switch type (better name welcome) is added to
> <type_traits>, to enable code such as:
>
> template<int i>
> using MyType = std::meta_switch_t<i,
> 0, FirstType,
> 1, SecondType,
> 2, ThirdType,
> // etc.
> >;
>
It seems to me to be a logical and sensible addition. Do you have a
compelling motivating example to hand?
>
> --
> 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/6b032496-9214-4a13-a5fc-46fa774a4261%40isocpp.org
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/6b032496-9214-4a13-a5fc-46fa774a4261%40isocpp.org?utm_medium=email&utm_source=footer>
> .
>
--
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/CALvx3ha54zGODuWuC4bpM2aY5_6xDBdfmQvOf%2B%2B3Vk9mzJk0DA%40mail.gmail.com.
--94eb2c0646464e8d16056865d6c8
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div><br><div class=3D"gmail_quote"><div dir=3D"auto">On Tue, 27 Mar 2018 a=
t 14:40, Hamza Sood <<a href=3D"mailto:hamza_sood@me.com">hamza_sood@me.=
com</a>> wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"marg=
in:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>Suppose you=
want to select a type based on a condition. You can do this with template =
specialisations at the language level:<div><br><div><div><div class=3D"m_81=
36854274653084753prettyprint" style=3D"background-color:rgb(250,250,250);bo=
rder:1px solid rgb(187,187,187);word-wrap:break-word"><code class=3D"m_8136=
854274653084753prettyprint"><div class=3D"m_8136854274653084753subprettypri=
nt"><font color=3D"#660066"><span style=3D"color:#008" class=3D"m_813685427=
4653084753styled-by-prettify">template</span><span style=3D"color:#080" cla=
ss=3D"m_8136854274653084753styled-by-prettify"><bool></span><span sty=
le=3D"color:#000" class=3D"m_8136854274653084753styled-by-prettify"><br></s=
pan><span style=3D"color:#008" class=3D"m_8136854274653084753styled-by-pret=
tify">struct</span><span style=3D"color:#000" class=3D"m_813685427465308475=
3styled-by-prettify"> </span><span style=3D"color:#606" class=3D"m_81368542=
74653084753styled-by-prettify">MySelector</span><span style=3D"color:#660" =
class=3D"m_8136854274653084753styled-by-prettify">;</span><span style=3D"co=
lor:#000" class=3D"m_8136854274653084753styled-by-prettify"><br><br></span>=
<span style=3D"color:#008" class=3D"m_8136854274653084753styled-by-prettify=
">template</span><span style=3D"color:#660" class=3D"m_8136854274653084753s=
tyled-by-prettify"><></span><span style=3D"color:#000" class=3D"m_813=
6854274653084753styled-by-prettify"><br></span><span style=3D"color:#008" c=
lass=3D"m_8136854274653084753styled-by-prettify">struct</span><span style=
=3D"color:#000" class=3D"m_8136854274653084753styled-by-prettify"> </span><=
span style=3D"color:#606" class=3D"m_8136854274653084753styled-by-prettify"=
>MySelector</span><span style=3D"color:#080" class=3D"m_8136854274653084753=
styled-by-prettify"><false></span><span style=3D"color:#000" class=3D=
"m_8136854274653084753styled-by-prettify"> </span><span style=3D"color:#660=
" class=3D"m_8136854274653084753styled-by-prettify">{</span><span style=3D"=
color:#000" class=3D"m_8136854274653084753styled-by-prettify"> </span><span=
style=3D"color:#008" class=3D"m_8136854274653084753styled-by-prettify">typ=
edef</span><span style=3D"color:#000" class=3D"m_8136854274653084753styled-=
by-prettify"> </span><span style=3D"color:#606" class=3D"m_8136854274653084=
753styled-by-prettify">TypeIfFalse</span><span style=3D"color:#000" class=
=3D"m_8136854274653084753styled-by-prettify"> type</span><span style=3D"col=
or:#660" class=3D"m_8136854274653084753styled-by-prettify">;</span><span st=
yle=3D"color:#000" class=3D"m_8136854274653084753styled-by-prettify"> </spa=
n><span style=3D"color:#660" class=3D"m_8136854274653084753styled-by-pretti=
fy">};</span><span style=3D"color:#000" class=3D"m_8136854274653084753style=
d-by-prettify"><br><br></span></font><span style=3D"color:#008" class=3D"m_=
8136854274653084753styled-by-prettify">template</span><span style=3D"color:=
#660" class=3D"m_8136854274653084753styled-by-prettify"><></span><spa=
n style=3D"color:#000" class=3D"m_8136854274653084753styled-by-prettify"><b=
r></span><span style=3D"color:#008" class=3D"m_8136854274653084753styled-by=
-prettify">struct</span><span style=3D"color:#000" class=3D"m_8136854274653=
084753styled-by-prettify"> </span><span style=3D"color:#606" class=3D"m_813=
6854274653084753styled-by-prettify">MySelector</span><span style=3D"color:#=
080" class=3D"m_8136854274653084753styled-by-prettify"><true></span><=
span style=3D"color:#000" class=3D"m_8136854274653084753styled-by-prettify"=
> </span><span style=3D"color:#660" class=3D"m_8136854274653084753styled-by=
-prettify">{</span><span style=3D"color:#000" class=3D"m_813685427465308475=
3styled-by-prettify"> </span><span style=3D"color:#008" class=3D"m_81368542=
74653084753styled-by-prettify">typedef</span><span style=3D"color:#000" cla=
ss=3D"m_8136854274653084753styled-by-prettify"> </span><span style=3D"color=
:#606" class=3D"m_8136854274653084753styled-by-prettify">TypeIfTrue</span><=
span style=3D"color:#000" class=3D"m_8136854274653084753styled-by-prettify"=
> type</span><span style=3D"color:#660" class=3D"m_8136854274653084753style=
d-by-prettify">;</span><span style=3D"color:#000" class=3D"m_81368542746530=
84753styled-by-prettify"> </span><span style=3D"color:#660" class=3D"m_8136=
854274653084753styled-by-prettify">};</span></div></code></div><div><br></d=
iv>But that's a lot of boilerplate, so C++11 introduced std::conditiona=
l.</div></div><div><br></div><div><br></div><div><br></div><div>Now instead=
suppose that you want to select a type based on the value of (non-boolean)=
non-type template parameter.</div><div>You can either do the same speciali=
sation trick:</div><div><br></div><div><div class=3D"m_8136854274653084753p=
rettyprint" style=3D"background-color:rgb(250,250,250);border:1px solid rgb=
(187,187,187);word-wrap:break-word"><code class=3D"m_8136854274653084753pre=
ttyprint"><div class=3D"m_8136854274653084753subprettyprint"><span style=3D=
"color:#008" class=3D"m_8136854274653084753styled-by-prettify">template</sp=
an><span style=3D"color:#080" class=3D"m_8136854274653084753styled-by-prett=
ify"><int></span><span style=3D"color:#000" class=3D"m_81368542746530=
84753styled-by-prettify"><br></span><span style=3D"color:#008" class=3D"m_8=
136854274653084753styled-by-prettify">struct</span><span style=3D"color:#00=
0" class=3D"m_8136854274653084753styled-by-prettify"> </span><span style=3D=
"color:#606" class=3D"m_8136854274653084753styled-by-prettify">MySelector</=
span><span style=3D"color:rgb(102,102,0);font-family:Arial,Helvetica,sans-s=
erif"><span style=3D"color:#660" class=3D"m_8136854274653084753styled-by-pr=
ettify">;</span><span style=3D"color:#000" class=3D"m_8136854274653084753st=
yled-by-prettify"><br></span></span><span style=3D"color:#000" class=3D"m_8=
136854274653084753styled-by-prettify"><br></span><span style=3D"color:#008"=
class=3D"m_8136854274653084753styled-by-prettify">template</span><span sty=
le=3D"color:#660" class=3D"m_8136854274653084753styled-by-prettify"><>=
;</span><span style=3D"color:#000" class=3D"m_8136854274653084753styled-by-=
prettify"><br></span><span style=3D"color:#008" class=3D"m_8136854274653084=
753styled-by-prettify">struct</span><span style=3D"color:#000" class=3D"m_8=
136854274653084753styled-by-prettify"> </span><span style=3D"color:#606" cl=
ass=3D"m_8136854274653084753styled-by-prettify">MySelector</span><span styl=
e=3D"color:#660" class=3D"m_8136854274653084753styled-by-prettify"><</sp=
an><span style=3D"color:#066" class=3D"m_8136854274653084753styled-by-prett=
ify">0</span><span style=3D"color:#660" class=3D"m_8136854274653084753style=
d-by-prettify">></span><span style=3D"color:#000" class=3D"m_81368542746=
53084753styled-by-prettify"> </span><span style=3D"color:#660" class=3D"m_8=
136854274653084753styled-by-prettify">{</span><span style=3D"color:#000" cl=
ass=3D"m_8136854274653084753styled-by-prettify"> </span><span style=3D"colo=
r:#008" class=3D"m_8136854274653084753styled-by-prettify">typedef</span><sp=
an style=3D"color:#000" class=3D"m_8136854274653084753styled-by-prettify"> =
</span><span style=3D"color:#606" class=3D"m_8136854274653084753styled-by-p=
rettify">FirstType</span><span style=3D"color:#000" class=3D"m_813685427465=
3084753styled-by-prettify"> type</span><span style=3D"color:#660" class=3D"=
m_8136854274653084753styled-by-prettify">;</span><span style=3D"color:#000"=
class=3D"m_8136854274653084753styled-by-prettify"> </span><span style=3D"c=
olor:#660" class=3D"m_8136854274653084753styled-by-prettify">};</span><span=
style=3D"color:#000" class=3D"m_8136854274653084753styled-by-prettify"><br=
><br></span><span style=3D"color:#008" class=3D"m_8136854274653084753styled=
-by-prettify">template</span><span style=3D"color:#660" class=3D"m_81368542=
74653084753styled-by-prettify"><></span><span style=3D"color:#000" cl=
ass=3D"m_8136854274653084753styled-by-prettify"><br></span><span style=3D"c=
olor:#008" class=3D"m_8136854274653084753styled-by-prettify">struct</span><=
span style=3D"color:#000" class=3D"m_8136854274653084753styled-by-prettify"=
> </span><span style=3D"color:#606" class=3D"m_8136854274653084753styled-by=
-prettify">MySelector</span><span style=3D"color:#660" class=3D"m_813685427=
4653084753styled-by-prettify"><</span><span style=3D"color:#066" class=
=3D"m_8136854274653084753styled-by-prettify">1</span><span style=3D"color:#=
660" class=3D"m_8136854274653084753styled-by-prettify">></span><span sty=
le=3D"color:#000" class=3D"m_8136854274653084753styled-by-prettify"> </span=
><span style=3D"color:#660" class=3D"m_8136854274653084753styled-by-prettif=
y">{</span><span style=3D"color:#000" class=3D"m_8136854274653084753styled-=
by-prettify"> </span><span style=3D"color:#008" class=3D"m_8136854274653084=
753styled-by-prettify">typedef</span><span style=3D"color:#000" class=3D"m_=
8136854274653084753styled-by-prettify"> </span><span style=3D"color:#606" c=
lass=3D"m_8136854274653084753styled-by-prettify">SecondType</span><span sty=
le=3D"color:#000" class=3D"m_8136854274653084753styled-by-prettify"> type</=
span><span style=3D"color:#660" class=3D"m_8136854274653084753styled-by-pre=
ttify">;</span><span style=3D"color:#000" class=3D"m_8136854274653084753sty=
led-by-prettify"> </span><span style=3D"color:#660" class=3D"m_813685427465=
3084753styled-by-prettify">};</span><span style=3D"color:#000" class=3D"m_8=
136854274653084753styled-by-prettify"><br><br></span><span style=3D"color:#=
008" class=3D"m_8136854274653084753styled-by-prettify">template</span><span=
style=3D"color:#660" class=3D"m_8136854274653084753styled-by-prettify"><=
;></span><span style=3D"color:#000" class=3D"m_8136854274653084753styled=
-by-prettify"><br></span><span style=3D"color:#008" class=3D"m_813685427465=
3084753styled-by-prettify">struct</span><span style=3D"color:#000" class=3D=
"m_8136854274653084753styled-by-prettify"> </span><span style=3D"color:#606=
" class=3D"m_8136854274653084753styled-by-prettify">MySelector</span><span =
style=3D"color:#660" class=3D"m_8136854274653084753styled-by-prettify"><=
</span><font color=3D"#006666"><span style=3D"color:#066" class=3D"m_813685=
4274653084753styled-by-prettify">2</span></font><span style=3D"color:#660" =
class=3D"m_8136854274653084753styled-by-prettify">></span><span style=3D=
"color:#000" class=3D"m_8136854274653084753styled-by-prettify"> </span><spa=
n style=3D"color:#660" class=3D"m_8136854274653084753styled-by-prettify">{<=
/span><span style=3D"color:#000" class=3D"m_8136854274653084753styled-by-pr=
ettify"> </span><span style=3D"color:#008" class=3D"m_8136854274653084753st=
yled-by-prettify">typedef</span><span style=3D"color:#000" class=3D"m_81368=
54274653084753styled-by-prettify"> </span><span style=3D"color:#606" class=
=3D"m_8136854274653084753styled-by-prettify">ThirdType</span><span style=3D=
"color:#000" class=3D"m_8136854274653084753styled-by-prettify"> type</span>=
<span style=3D"color:#660" class=3D"m_8136854274653084753styled-by-prettify=
">;</span><span style=3D"color:#000" class=3D"m_8136854274653084753styled-b=
y-prettify"> </span><span style=3D"color:#660" class=3D"m_81368542746530847=
53styled-by-prettify">};</span><span style=3D"color:#000" class=3D"m_813685=
4274653084753styled-by-prettify"><br><br></span><span style=3D"color:#800" =
class=3D"m_8136854274653084753styled-by-prettify">// etc.</span><span style=
=3D"color:#000" class=3D"m_8136854274653084753styled-by-prettify"><br></spa=
n><span style=3D"color:#800" class=3D"m_8136854274653084753styled-by-pretti=
fy">// Potentially lots of other cases here...</span></div></code></div><di=
v><br></div>which is a bit cumbersome. Or you can try to chain std::conditi=
onals:</div><div><br></div><div><div class=3D"m_8136854274653084753prettypr=
int" style=3D"background-color:rgb(250,250,250);border:1px solid rgb(187,18=
7,187);word-wrap:break-word"><code class=3D"m_8136854274653084753prettyprin=
t"><div class=3D"m_8136854274653084753subprettyprint"><font><span style=3D"=
color:#008" class=3D"m_8136854274653084753styled-by-prettify">template</spa=
n><span style=3D"color:#660" class=3D"m_8136854274653084753styled-by-pretti=
fy"><</span><span style=3D"color:#008" class=3D"m_8136854274653084753sty=
led-by-prettify">int</span><span style=3D"color:#000" class=3D"m_8136854274=
653084753styled-by-prettify"> i</span><span style=3D"color:#660" class=3D"m=
_8136854274653084753styled-by-prettify">></span><span style=3D"color:#00=
0" class=3D"m_8136854274653084753styled-by-prettify"><br></span><span style=
=3D"color:#008" class=3D"m_8136854274653084753styled-by-prettify">using</sp=
an><span style=3D"color:#000" class=3D"m_8136854274653084753styled-by-prett=
ify"> </span><span style=3D"color:#606" class=3D"m_8136854274653084753style=
d-by-prettify">MyType</span><span style=3D"color:#000" class=3D"m_813685427=
4653084753styled-by-prettify"> </span><span style=3D"color:#660" class=3D"m=
_8136854274653084753styled-by-prettify">=3D</span><span style=3D"color:#000=
" class=3D"m_8136854274653084753styled-by-prettify"> std</span><span style=
=3D"color:#660" class=3D"m_8136854274653084753styled-by-prettify">::</span>=
<span style=3D"color:#000" class=3D"m_8136854274653084753styled-by-prettify=
">conditional_t</span><span style=3D"color:#660" class=3D"m_813685427465308=
4753styled-by-prettify"><</span><span style=3D"color:#000" class=3D"m_81=
36854274653084753styled-by-prettify">i </span><span style=3D"color:#660" cl=
ass=3D"m_8136854274653084753styled-by-prettify">=3D=3D</span><span style=3D=
"color:#000" class=3D"m_8136854274653084753styled-by-prettify"> </span><spa=
n style=3D"color:#066" class=3D"m_8136854274653084753styled-by-prettify">0<=
/span><span style=3D"color:#660" class=3D"m_8136854274653084753styled-by-pr=
ettify">,</span><span style=3D"color:#000" class=3D"m_8136854274653084753st=
yled-by-prettify"> </span><span style=3D"color:#606" class=3D"m_81368542746=
53084753styled-by-prettify">FirstType</span><span style=3D"color:#660" clas=
s=3D"m_8136854274653084753styled-by-prettify">,</span><span style=3D"color:=
#000" class=3D"m_8136854274653084753styled-by-prettify"><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 std</span><span style=3D"color:#660" class=
=3D"m_8136854274653084753styled-by-prettify">::</span><span style=3D"color:=
#000" class=3D"m_8136854274653084753styled-by-prettify">conditional_t</span=
><font color=3D"#008800"><span style=3D"color:#660" class=3D"m_813685427465=
3084753styled-by-prettify"><</span><span><span style=3D"color:#000" clas=
s=3D"m_8136854274653084753styled-by-prettify">i</span></span><span style=3D=
"color:#000" class=3D"m_8136854274653084753styled-by-prettify"> </span><spa=
n style=3D"color:#660" class=3D"m_8136854274653084753styled-by-prettify">=
=3D=3D</span><span style=3D"color:#000" class=3D"m_8136854274653084753style=
d-by-prettify"> </span><span style=3D"color:#066" class=3D"m_81368542746530=
84753styled-by-prettify">1</span><span style=3D"color:#660" class=3D"m_8136=
854274653084753styled-by-prettify">,</span><span style=3D"color:#000" class=
=3D"m_8136854274653084753styled-by-prettify"> </span><span style=3D"color:#=
606" class=3D"m_8136854274653084753styled-by-prettify">SecondType</span><sp=
an style=3D"color:#660" class=3D"m_8136854274653084753styled-by-prettify">,=
</span><span style=3D"color:#000" class=3D"m_8136854274653084753styled-by-p=
rettify"><br></span></font><span style=3D"color:#000" class=3D"m_8136854274=
653084753styled-by-prettify">=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 =C2=A0 =C2=A0 =C2=A0std</s=
pan><span style=3D"color:#660" class=3D"m_8136854274653084753styled-by-pret=
tify">::</span><span style=3D"color:#000" class=3D"m_8136854274653084753sty=
led-by-prettify">conditional_t</span><span style=3D"color:#660" class=3D"m_=
8136854274653084753styled-by-prettify"><</span><span style=3D"color:#000=
" class=3D"m_8136854274653084753styled-by-prettify">i </span><span style=3D=
"color:#660" class=3D"m_8136854274653084753styled-by-prettify">=3D=3D</span=
><span style=3D"color:#000" class=3D"m_8136854274653084753styled-by-prettif=
y"> </span><span style=3D"color:#066" class=3D"m_8136854274653084753styled-=
by-prettify">2</span><span style=3D"color:#660" class=3D"m_8136854274653084=
753styled-by-prettify">,</span><span style=3D"color:#000" class=3D"m_813685=
4274653084753styled-by-prettify"> </span><span style=3D"color:#606" class=
=3D"m_8136854274653084753styled-by-prettify">ThirdType</span><span style=3D=
"color:#660" class=3D"m_8136854274653084753styled-by-prettify">,</span><spa=
n style=3D"color:#000" class=3D"m_8136854274653084753styled-by-prettify"> <=
/span><span style=3D"color:#800" class=3D"m_8136854274653084753styled-by-pr=
ettify">/* potentially lots more stuff here... */</span><span style=3D"colo=
r:#660" class=3D"m_8136854274653084753styled-by-prettify">>>>;</sp=
an></font></div></code></div><div><br></div>which is even worse.</div><div>=
<br></div><div><br></div><div><br></div><div>I propose that a meta_switch t=
ype (better name welcome) is added to <type_traits>, to enable code s=
uch as:</div><div><br></div><div><div class=3D"m_8136854274653084753prettyp=
rint" style=3D"background-color:rgb(250,250,250);border:1px solid rgb(187,1=
87,187);word-wrap:break-word"><code class=3D"m_8136854274653084753prettypri=
nt"><div class=3D"m_8136854274653084753subprettyprint"><font><span style=3D=
"color:#008" class=3D"m_8136854274653084753styled-by-prettify">template</sp=
an><span style=3D"color:#660" class=3D"m_8136854274653084753styled-by-prett=
ify"><</span><span style=3D"color:#008" class=3D"m_8136854274653084753st=
yled-by-prettify">int</span><font color=3D"#000000"><span style=3D"color:#0=
00" class=3D"m_8136854274653084753styled-by-prettify"> i</span><span style=
=3D"color:#660" class=3D"m_8136854274653084753styled-by-prettify">></spa=
n><span style=3D"color:#000" class=3D"m_8136854274653084753styled-by-pretti=
fy"><br></span><span style=3D"color:#008" class=3D"m_8136854274653084753sty=
led-by-prettify">using</span><span style=3D"color:#000" class=3D"m_81368542=
74653084753styled-by-prettify"> </span><span style=3D"color:#606" class=3D"=
m_8136854274653084753styled-by-prettify">MyType</span><span style=3D"color:=
#000" class=3D"m_8136854274653084753styled-by-prettify"> </span><span style=
=3D"color:#660" class=3D"m_8136854274653084753styled-by-prettify">=3D</span=
><span style=3D"color:#000" class=3D"m_8136854274653084753styled-by-prettif=
y"> std</span><span style=3D"color:#660" class=3D"m_8136854274653084753styl=
ed-by-prettify">::</span><span style=3D"color:#000" class=3D"m_813685427465=
3084753styled-by-prettify">meta_switch_t</span><span style=3D"color:#660" c=
lass=3D"m_8136854274653084753styled-by-prettify"><</span><span><span sty=
le=3D"color:#000" class=3D"m_8136854274653084753styled-by-prettify">i</span=
><span style=3D"color:#660" class=3D"m_8136854274653084753styled-by-prettif=
y">,</span><span style=3D"color:#000" class=3D"m_8136854274653084753styled-=
by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#066" class=3D"m=
_8136854274653084753styled-by-prettify">0</span><span style=3D"color:#660" =
class=3D"m_8136854274653084753styled-by-prettify">,</span><span style=3D"co=
lor:#000" class=3D"m_8136854274653084753styled-by-prettify"> </span><span s=
tyle=3D"color:#606" class=3D"m_8136854274653084753styled-by-prettify">First=
Type</span><span style=3D"color:#660" class=3D"m_8136854274653084753styled-=
by-prettify">,</span><span style=3D"color:#000" class=3D"m_8136854274653084=
753styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#066" =
class=3D"m_8136854274653084753styled-by-prettify">1</span><span style=3D"co=
lor:#660" class=3D"m_8136854274653084753styled-by-prettify">,</span><span s=
tyle=3D"color:#000" class=3D"m_8136854274653084753styled-by-prettify"> </sp=
an><span style=3D"color:#606" class=3D"m_8136854274653084753styled-by-prett=
ify">SecondType</span><span style=3D"color:#660" class=3D"m_813685427465308=
4753styled-by-prettify">,</span><span style=3D"color:#000" class=3D"m_81368=
54274653084753styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"c=
olor:#066" class=3D"m_8136854274653084753styled-by-prettify">2</span><span =
style=3D"color:#660" class=3D"m_8136854274653084753styled-by-prettify">,</s=
pan><span style=3D"color:#000" class=3D"m_8136854274653084753styled-by-pret=
tify"> </span><span style=3D"color:#606" class=3D"m_8136854274653084753styl=
ed-by-prettify">ThirdType</span><span style=3D"color:#660" class=3D"m_81368=
54274653084753styled-by-prettify">,</span><span style=3D"color:#000" class=
=3D"m_8136854274653084753styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span=
style=3D"color:#800" class=3D"m_8136854274653084753styled-by-prettify">// =
etc.</span><span style=3D"color:#000" class=3D"m_8136854274653084753styled-=
by-prettify"><br></span><span style=3D"color:#660" class=3D"m_8136854274653=
084753styled-by-prettify">>;</span></span></font></font></div></code></d=
iv></div></div></div></blockquote><div dir=3D"auto"><br></div><div dir=3D"a=
uto"><br></div><div dir=3D"auto">It seems to me to be a logical and sensibl=
e addition. Do you have a compelling motivating example to hand?=C2=A0</div=
><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1=
px #ccc solid;padding-left:1ex"><div><br></div>
<p></p>
-- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org" target=3D"_=
blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">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/6b032496-9214-4a13-a5fc-46fa774a4261%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" target=3D"_blank">=
https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/6b032496-9214-=
4a13-a5fc-46fa774a4261%40isocpp.org</a>.<br>
</blockquote></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/CALvx3ha54zGODuWuC4bpM2aY5_6xDBdfmQvO=
f%2B%2B3Vk9mzJk0DA%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CALvx3ha54zGO=
DuWuC4bpM2aY5_6xDBdfmQvOf%2B%2B3Vk9mzJk0DA%40mail.gmail.com</a>.<br />
--94eb2c0646464e8d16056865d6c8--
.
Author: Hyman Rosen <hyman.rosen@gmail.com>
Date: Tue, 27 Mar 2018 10:51:21 -0400
Raw View
--001a11498928494d96056866077c
Content-Type: text/plain; charset="UTF-8"
On Tue, Mar 27, 2018 at 8:40 AM, Hamza Sood <hamza_sood@me.com> wrote:
>
> Or you can try to chain std::conditionals:
>
> template<int i>
> using MyType = std::conditional_t<i == 0, FirstType,
> std::conditional_t<i == 1, SecondType,
> std::conditional_t<i
> == 2, ThirdType, /* potentially lots more stuff here... */>>>;
>
> which is even worse.
>
If you write it as
template<int i> using MyType =
std::conditional_t<i == 0, FirstType,
std::conditional_t<i == 1, SecondType,
std::conditional_t<i == 2, ThirdType,
/* potentially lots more stuff here */
>>>;
it looks much less bad, somewhat reducing the strength of the argument.
Also, are there SFINAE issues here? It seems like we might want a construct
that returns the first matching type without failing altogether if a later
type fails
instantiation.
--
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/CAHSYqdYZP9e5mz0DFVn6RiiGFKvJXYpB52TD1jw_6%3DaynDzG2Q%40mail.gmail.com.
--001a11498928494d96056866077c
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On T=
ue, Mar 27, 2018 at 8:40 AM, Hamza Sood <span dir=3D"ltr"><<a href=3D"ma=
ilto:hamza_sood@me.com" target=3D"_blank">hamza_sood@me.com</a>></span> =
wrote:<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-l=
eft:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div><div>Or you can =
try to chain std::conditionals:</div><div><br></div><div><div class=3D"m_-2=
490841964736461158prettyprint" style=3D"background-color:rgb(250,250,250);b=
order:1px solid rgb(187,187,187);word-wrap:break-word"><code class=3D"m_-24=
90841964736461158prettyprint"><div class=3D"m_-2490841964736461158subpretty=
print"><font><span style=3D"color:#008" class=3D"m_-2490841964736461158styl=
ed-by-prettify">template</span><span style=3D"color:#660" class=3D"m_-24908=
41964736461158styled-by-prettify"><</span><span style=3D"color:#008" cla=
ss=3D"m_-2490841964736461158styled-by-prettify">int</span><span style=3D"co=
lor:#000" class=3D"m_-2490841964736461158styled-by-prettify"> i</span><span=
style=3D"color:#660" class=3D"m_-2490841964736461158styled-by-prettify">&g=
t;</span><span style=3D"color:#000" class=3D"m_-2490841964736461158styled-b=
y-prettify"><br></span><span style=3D"color:#008" class=3D"m_-2490841964736=
461158styled-by-prettify">using</span><span style=3D"color:#000" class=3D"m=
_-2490841964736461158styled-by-prettify"> </span><span style=3D"color:#606"=
class=3D"m_-2490841964736461158styled-by-prettify">MyType</span><span styl=
e=3D"color:#000" class=3D"m_-2490841964736461158styled-by-prettify"> </span=
><span style=3D"color:#660" class=3D"m_-2490841964736461158styled-by-pretti=
fy">=3D</span><span style=3D"color:#000" class=3D"m_-2490841964736461158sty=
led-by-prettify"> std</span><span style=3D"color:#660" class=3D"m_-24908419=
64736461158styled-by-prettify">::</span><span style=3D"color:#000" class=3D=
"m_-2490841964736461158styled-by-prettify">conditional_t</span><span style=
=3D"color:#660" class=3D"m_-2490841964736461158styled-by-prettify"><</sp=
an><span style=3D"color:#000" class=3D"m_-2490841964736461158styled-by-pret=
tify">i </span><span style=3D"color:#660" class=3D"m_-2490841964736461158st=
yled-by-prettify">=3D=3D</span><span style=3D"color:#000" class=3D"m_-24908=
41964736461158styled-by-prettify"> </span><span style=3D"color:#066" class=
=3D"m_-2490841964736461158styled-by-prettify">0</span><span style=3D"color:=
#660" class=3D"m_-2490841964736461158styled-by-prettify">,</span><span styl=
e=3D"color:#000" class=3D"m_-2490841964736461158styled-by-prettify"> </span=
><span style=3D"color:#606" class=3D"m_-2490841964736461158styled-by-pretti=
fy">FirstType</span><span style=3D"color:#660" class=3D"m_-2490841964736461=
158styled-by-prettify">,</span><span style=3D"color:#000" class=3D"m_-24908=
41964736461158styled-by-prettify"><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 std</span><span style=3D"color:#660" class=3D"m_-249084196473646=
1158styled-by-prettify">::</span><span style=3D"color:#000" class=3D"m_-249=
0841964736461158styled-by-prettify">conditional_t</span><font color=3D"#008=
800"><span style=3D"color:#660" class=3D"m_-2490841964736461158styled-by-pr=
ettify"><</span><span><span style=3D"color:#000" class=3D"m_-24908419647=
36461158styled-by-prettify">i</span></span><span style=3D"color:#000" class=
=3D"m_-2490841964736461158styled-by-prettify"> </span><span style=3D"color:=
#660" class=3D"m_-2490841964736461158styled-by-prettify">=3D=3D</span><span=
style=3D"color:#000" class=3D"m_-2490841964736461158styled-by-prettify"> <=
/span><span style=3D"color:#066" class=3D"m_-2490841964736461158styled-by-p=
rettify">1</span><span style=3D"color:#660" class=3D"m_-2490841964736461158=
styled-by-prettify">,</span><span style=3D"color:#000" class=3D"m_-24908419=
64736461158styled-by-prettify"> </span><span style=3D"color:#606" class=3D"=
m_-2490841964736461158styled-by-prettify">SecondType</span><span style=3D"c=
olor:#660" class=3D"m_-2490841964736461158styled-by-prettify">,</span><span=
style=3D"color:#000" class=3D"m_-2490841964736461158styled-by-prettify"><b=
r></span></font><span style=3D"color:#000" class=3D"m_-2490841964736461158s=
tyled-by-prettify">=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 =C2=A0 =C2=A0 =C2=A0std</span><span =
style=3D"color:#660" class=3D"m_-2490841964736461158styled-by-prettify">::<=
/span><span style=3D"color:#000" class=3D"m_-2490841964736461158styled-by-p=
rettify">conditional_t</span><span style=3D"color:#660" class=3D"m_-2490841=
964736461158styled-by-prettify"><</span><span style=3D"color:#000" class=
=3D"m_-2490841964736461158styled-by-prettify">i </span><span style=3D"color=
:#660" class=3D"m_-2490841964736461158styled-by-prettify">=3D=3D</span><spa=
n style=3D"color:#000" class=3D"m_-2490841964736461158styled-by-prettify"> =
</span><span style=3D"color:#066" class=3D"m_-2490841964736461158styled-by-=
prettify">2</span><span style=3D"color:#660" class=3D"m_-249084196473646115=
8styled-by-prettify">,</span><span style=3D"color:#000" class=3D"m_-2490841=
964736461158styled-by-prettify"> </span><span style=3D"color:#606" class=3D=
"m_-2490841964736461158styled-by-prettify">ThirdType</span><span style=3D"c=
olor:#660" class=3D"m_-2490841964736461158styled-by-prettify">,</span><span=
style=3D"color:#000" class=3D"m_-2490841964736461158styled-by-prettify"> <=
/span><span style=3D"color:#800" class=3D"m_-2490841964736461158styled-by-p=
rettify">/* potentially lots more stuff here... */</span><span style=3D"col=
or:#660" class=3D"m_-2490841964736461158styled-by-prettify">>>>;</=
span></font></div></code></div><div><br></div>which is even worse.</div></d=
iv></div></blockquote><div><br>If you write it as<br><br><span class=3D"gma=
il-m_-2490841964736461158styled-by-prettify" style=3D"font-family:monospace=
;font-size:small;font-style:normal;font-variant-ligatures:normal;font-varia=
nt-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-=
indent:0px;text-transform:none;white-space:normal;word-spacing:0px;backgrou=
nd-color:rgb(250,250,250);text-decoration-style:initial;text-decoration-col=
or:initial;color:rgb(0,0,136)">template</span><span class=3D"gmail-m_-24908=
41964736461158styled-by-prettify" style=3D"font-family:monospace;font-size:=
small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:nor=
mal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;=
text-transform:none;white-space:normal;word-spacing:0px;background-color:rg=
b(250,250,250);text-decoration-style:initial;text-decoration-color:initial;=
color:rgb(102,102,0)"><</span><span class=3D"gmail-m_-249084196473646115=
8styled-by-prettify" style=3D"font-family:monospace;font-size:small;font-st=
yle:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weig=
ht:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transfor=
m:none;white-space:normal;word-spacing:0px;background-color:rgb(250,250,250=
);text-decoration-style:initial;text-decoration-color:initial;color:rgb(0,0=
,136)">int</span><span class=3D"gmail-m_-2490841964736461158styled-by-prett=
ify" style=3D"font-family:monospace;font-size:small;font-style:normal;font-=
variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-sp=
acing:normal;text-align:start;text-indent:0px;text-transform:none;white-spa=
ce:normal;word-spacing:0px;background-color:rgb(250,250,250);text-decoratio=
n-style:initial;text-decoration-color:initial;color:rgb(0,0,0)"><span>=C2=
=A0</span>i</span><span class=3D"gmail-m_-2490841964736461158styled-by-pret=
tify" style=3D"font-family:monospace;font-size:small;font-style:normal;font=
-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-s=
pacing:normal;text-align:start;text-indent:0px;text-transform:none;white-sp=
ace:normal;word-spacing:0px;background-color:rgb(250,250,250);text-decorati=
on-style:initial;text-decoration-color:initial;color:rgb(102,102,0)">>=
=C2=A0</span><span class=3D"gmail-m_-2490841964736461158styled-by-prettify"=
style=3D"font-family:monospace;font-size:small;font-style:normal;font-vari=
ant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacin=
g:normal;text-align:start;text-indent:0px;text-transform:none;white-space:n=
ormal;word-spacing:0px;background-color:rgb(250,250,250);text-decoration-st=
yle:initial;text-decoration-color:initial;color:rgb(0,0,136)">using</span><=
span class=3D"gmail-m_-2490841964736461158styled-by-prettify" style=3D"font=
-family:monospace;font-size:small;font-style:normal;font-variant-ligatures:=
normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-=
align:start;text-indent:0px;text-transform:none;white-space:normal;word-spa=
cing:0px;background-color:rgb(250,250,250);text-decoration-style:initial;te=
xt-decoration-color:initial;color:rgb(0,0,0)"><span>=C2=A0</span></span><sp=
an class=3D"gmail-m_-2490841964736461158styled-by-prettify" style=3D"font-f=
amily:monospace;font-size:small;font-style:normal;font-variant-ligatures:no=
rmal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-al=
ign:start;text-indent:0px;text-transform:none;white-space:normal;word-spaci=
ng:0px;background-color:rgb(250,250,250);text-decoration-style:initial;text=
-decoration-color:initial;color:rgb(102,0,102)">MyType</span><span class=3D=
"gmail-m_-2490841964736461158styled-by-prettify" style=3D"font-family:monos=
pace;font-size:small;font-style:normal;font-variant-ligatures:normal;font-v=
ariant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;t=
ext-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;back=
ground-color:rgb(250,250,250);text-decoration-style:initial;text-decoration=
-color:initial;color:rgb(0,0,0)"><span>=C2=A0</span></span><span class=3D"g=
mail-m_-2490841964736461158styled-by-prettify" style=3D"font-family:monospa=
ce;font-size:small;font-style:normal;font-variant-ligatures:normal;font-var=
iant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;tex=
t-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;backgr=
ound-color:rgb(250,250,250);text-decoration-style:initial;text-decoration-c=
olor:initial;color:rgb(102,102,0)">=3D<br></span><span class=3D"gmail-m_-24=
90841964736461158styled-by-prettify" style=3D"font-family:monospace;font-si=
ze:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:=
normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0=
px;text-transform:none;white-space:normal;word-spacing:0px;background-color=
:rgb(250,250,250);text-decoration-style:initial;text-decoration-color:initi=
al;color:rgb(0,0,0)">std</span><span class=3D"gmail-m_-2490841964736461158s=
tyled-by-prettify" style=3D"font-family:monospace;font-size:small;font-styl=
e:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight=
:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:=
none;white-space:normal;word-spacing:0px;background-color:rgb(250,250,250);=
text-decoration-style:initial;text-decoration-color:initial;color:rgb(102,1=
02,0)">::</span><span class=3D"gmail-m_-2490841964736461158styled-by-pretti=
fy" style=3D"font-family:monospace;font-size:small;font-style:normal;font-v=
ariant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spa=
cing:normal;text-align:start;text-indent:0px;text-transform:none;white-spac=
e:normal;word-spacing:0px;background-color:rgb(250,250,250);text-decoration=
-style:initial;text-decoration-color:initial;color:rgb(0,0,0)">conditional_=
t</span><span class=3D"gmail-m_-2490841964736461158styled-by-prettify" styl=
e=3D"font-family:monospace;font-size:small;font-style:normal;font-variant-l=
igatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:nor=
mal;text-align:start;text-indent:0px;text-transform:none;white-space:normal=
;word-spacing:0px;background-color:rgb(250,250,250);text-decoration-style:i=
nitial;text-decoration-color:initial;color:rgb(102,102,0)"><</span><span=
class=3D"gmail-m_-2490841964736461158styled-by-prettify" style=3D"font-fam=
ily:monospace;font-size:small;font-style:normal;font-variant-ligatures:norm=
al;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-alig=
n:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing=
:0px;background-color:rgb(250,250,250);text-decoration-style:initial;text-d=
ecoration-color:initial;color:rgb(0,0,0)">i<span>=C2=A0</span></span><span =
class=3D"gmail-m_-2490841964736461158styled-by-prettify" style=3D"font-fami=
ly:monospace;font-size:small;font-style:normal;font-variant-ligatures:norma=
l;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align=
:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:=
0px;background-color:rgb(250,250,250);text-decoration-style:initial;text-de=
coration-color:initial;color:rgb(102,102,0)">=3D=3D</span><span class=3D"gm=
ail-m_-2490841964736461158styled-by-prettify" style=3D"font-family:monospac=
e;font-size:small;font-style:normal;font-variant-ligatures:normal;font-vari=
ant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text=
-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;backgro=
und-color:rgb(250,250,250);text-decoration-style:initial;text-decoration-co=
lor:initial;color:rgb(0,0,0)"><span>=C2=A0</span></span><span class=3D"gmai=
l-m_-2490841964736461158styled-by-prettify" style=3D"font-family:monospace;=
font-size:small;font-style:normal;font-variant-ligatures:normal;font-varian=
t-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-i=
ndent:0px;text-transform:none;white-space:normal;word-spacing:0px;backgroun=
d-color:rgb(250,250,250);text-decoration-style:initial;text-decoration-colo=
r:initial;color:rgb(0,102,102)">0</span><span class=3D"gmail-m_-24908419647=
36461158styled-by-prettify" style=3D"font-family:monospace;font-size:small;=
font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;fo=
nt-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-t=
ransform:none;white-space:normal;word-spacing:0px;background-color:rgb(250,=
250,250);text-decoration-style:initial;text-decoration-color:initial;color:=
rgb(102,102,0)">,</span><span class=3D"gmail-m_-2490841964736461158styled-b=
y-prettify" style=3D"font-family:monospace;font-size:small;font-style:norma=
l;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;le=
tter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;wh=
ite-space:normal;word-spacing:0px;background-color:rgb(250,250,250);text-de=
coration-style:initial;text-decoration-color:initial;color:rgb(0,0,0)"><spa=
n>=C2=A0</span></span><span class=3D"gmail-m_-2490841964736461158styled-by-=
prettify" style=3D"font-family:monospace;font-size:small;font-style:normal;=
font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;lett=
er-spacing:normal;text-align:start;text-indent:0px;text-transform:none;whit=
e-space:normal;word-spacing:0px;background-color:rgb(250,250,250);text-deco=
ration-style:initial;text-decoration-color:initial;color:rgb(102,0,102)">Fi=
rstType</span><span class=3D"gmail-m_-2490841964736461158styled-by-prettify=
" style=3D"font-family:monospace;font-size:small;font-style:normal;font-var=
iant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spaci=
ng:normal;text-align:start;text-indent:0px;text-transform:none;white-space:=
normal;word-spacing:0px;background-color:rgb(250,250,250);text-decoration-s=
tyle:initial;text-decoration-color:initial;color:rgb(102,102,0)">,</span><s=
pan class=3D"gmail-m_-2490841964736461158styled-by-prettify" style=3D"font-=
family:monospace;font-size:small;font-style:normal;font-variant-ligatures:n=
ormal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-a=
lign:start;text-indent:0px;text-transform:none;white-space:normal;word-spac=
ing:0px;background-color:rgb(250,250,250);text-decoration-style:initial;tex=
t-decoration-color:initial;color:rgb(0,0,0)"><br>std</span><span class=3D"g=
mail-m_-2490841964736461158styled-by-prettify" style=3D"font-family:monospa=
ce;font-size:small;font-style:normal;font-variant-ligatures:normal;font-var=
iant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;tex=
t-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;backgr=
ound-color:rgb(250,250,250);text-decoration-style:initial;text-decoration-c=
olor:initial;color:rgb(102,102,0)">::</span><span class=3D"gmail-m_-2490841=
964736461158styled-by-prettify" style=3D"font-family:monospace;font-size:sm=
all;font-style:normal;font-variant-ligatures:normal;font-variant-caps:norma=
l;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;te=
xt-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(=
250,250,250);text-decoration-style:initial;text-decoration-color:initial;co=
lor:rgb(0,0,0)">conditional_t</span><font color=3D"#008800" style=3D"font-f=
amily:monospace;font-size:small;font-style:normal;font-variant-ligatures:no=
rmal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-al=
ign:start;text-indent:0px;text-transform:none;white-space:normal;word-spaci=
ng:0px;background-color:rgb(250,250,250);text-decoration-style:initial;text=
-decoration-color:initial"><span class=3D"gmail-m_-2490841964736461158style=
d-by-prettify" style=3D"color:rgb(102,102,0)"><</span><span><span class=
=3D"gmail-m_-2490841964736461158styled-by-prettify" style=3D"color:rgb(0,0,=
0)">i</span></span><span class=3D"gmail-m_-2490841964736461158styled-by-pre=
ttify" style=3D"color:rgb(0,0,0)"><span>=C2=A0</span></span><span class=3D"=
gmail-m_-2490841964736461158styled-by-prettify" style=3D"color:rgb(102,102,=
0)">=3D=3D</span><span class=3D"gmail-m_-2490841964736461158styled-by-prett=
ify" style=3D"color:rgb(0,0,0)"><span>=C2=A0</span></span><span class=3D"gm=
ail-m_-2490841964736461158styled-by-prettify" style=3D"color:rgb(0,102,102)=
">1</span><span class=3D"gmail-m_-2490841964736461158styled-by-prettify" st=
yle=3D"color:rgb(102,102,0)">,</span><span class=3D"gmail-m_-24908419647364=
61158styled-by-prettify" style=3D"color:rgb(0,0,0)"><span>=C2=A0</span></sp=
an><span class=3D"gmail-m_-2490841964736461158styled-by-prettify" style=3D"=
color:rgb(102,0,102)">SecondType</span><span class=3D"gmail-m_-249084196473=
6461158styled-by-prettify" style=3D"color:rgb(102,102,0)">,</span><span cla=
ss=3D"gmail-m_-2490841964736461158styled-by-prettify" style=3D"color:rgb(0,=
0,0)"><br></span></font><span class=3D"gmail-m_-2490841964736461158styled-b=
y-prettify" style=3D"font-family:monospace;font-size:small;font-style:norma=
l;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;le=
tter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;wh=
ite-space:normal;word-spacing:0px;background-color:rgb(250,250,250);text-de=
coration-style:initial;text-decoration-color:initial;color:rgb(0,0,0)">std<=
/span><span class=3D"gmail-m_-2490841964736461158styled-by-prettify" style=
=3D"font-family:monospace;font-size:small;font-style:normal;font-variant-li=
gatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:norm=
al;text-align:start;text-indent:0px;text-transform:none;white-space:normal;=
word-spacing:0px;background-color:rgb(250,250,250);text-decoration-style:in=
itial;text-decoration-color:initial;color:rgb(102,102,0)">::</span><span cl=
ass=3D"gmail-m_-2490841964736461158styled-by-prettify" style=3D"font-family=
:monospace;font-size:small;font-style:normal;font-variant-ligatures:normal;=
font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:s=
tart;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0p=
x;background-color:rgb(250,250,250);text-decoration-style:initial;text-deco=
ration-color:initial;color:rgb(0,0,0)">conditional_t</span><span class=3D"g=
mail-m_-2490841964736461158styled-by-prettify" style=3D"font-family:monospa=
ce;font-size:small;font-style:normal;font-variant-ligatures:normal;font-var=
iant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;tex=
t-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;backgr=
ound-color:rgb(250,250,250);text-decoration-style:initial;text-decoration-c=
olor:initial;color:rgb(102,102,0)"><</span><span class=3D"gmail-m_-24908=
41964736461158styled-by-prettify" style=3D"font-family:monospace;font-size:=
small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:nor=
mal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;=
text-transform:none;white-space:normal;word-spacing:0px;background-color:rg=
b(250,250,250);text-decoration-style:initial;text-decoration-color:initial;=
color:rgb(0,0,0)">i<span>=C2=A0</span></span><span class=3D"gmail-m_-249084=
1964736461158styled-by-prettify" style=3D"font-family:monospace;font-size:s=
mall;font-style:normal;font-variant-ligatures:normal;font-variant-caps:norm=
al;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;t=
ext-transform:none;white-space:normal;word-spacing:0px;background-color:rgb=
(250,250,250);text-decoration-style:initial;text-decoration-color:initial;c=
olor:rgb(102,102,0)">=3D=3D</span><span class=3D"gmail-m_-24908419647364611=
58styled-by-prettify" style=3D"font-family:monospace;font-size:small;font-s=
tyle:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-wei=
ght:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transfo=
rm:none;white-space:normal;word-spacing:0px;background-color:rgb(250,250,25=
0);text-decoration-style:initial;text-decoration-color:initial;color:rgb(0,=
0,0)"><span>=C2=A0</span></span><span class=3D"gmail-m_-2490841964736461158=
styled-by-prettify" style=3D"font-family:monospace;font-size:small;font-sty=
le:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weigh=
t:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform=
:none;white-space:normal;word-spacing:0px;background-color:rgb(250,250,250)=
;text-decoration-style:initial;text-decoration-color:initial;color:rgb(0,10=
2,102)">2</span><span class=3D"gmail-m_-2490841964736461158styled-by-pretti=
fy" style=3D"font-family:monospace;font-size:small;font-style:normal;font-v=
ariant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spa=
cing:normal;text-align:start;text-indent:0px;text-transform:none;white-spac=
e:normal;word-spacing:0px;background-color:rgb(250,250,250);text-decoration=
-style:initial;text-decoration-color:initial;color:rgb(102,102,0)">,</span>=
<span class=3D"gmail-m_-2490841964736461158styled-by-prettify" style=3D"fon=
t-family:monospace;font-size:small;font-style:normal;font-variant-ligatures=
:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text=
-align:start;text-indent:0px;text-transform:none;white-space:normal;word-sp=
acing:0px;background-color:rgb(250,250,250);text-decoration-style:initial;t=
ext-decoration-color:initial;color:rgb(0,0,0)"><span>=C2=A0</span></span><s=
pan class=3D"gmail-m_-2490841964736461158styled-by-prettify" style=3D"font-=
family:monospace;font-size:small;font-style:normal;font-variant-ligatures:n=
ormal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-a=
lign:start;text-indent:0px;text-transform:none;white-space:normal;word-spac=
ing:0px;background-color:rgb(250,250,250);text-decoration-style:initial;tex=
t-decoration-color:initial;color:rgb(102,0,102)">ThirdType</span><span clas=
s=3D"gmail-m_-2490841964736461158styled-by-prettify" style=3D"font-family:m=
onospace;font-size:small;font-style:normal;font-variant-ligatures:normal;fo=
nt-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:sta=
rt;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;=
background-color:rgb(250,250,250);text-decoration-style:initial;text-decora=
tion-color:initial;color:rgb(102,102,0)">,<br></span><span class=3D"gmail-m=
_-2490841964736461158styled-by-prettify" style=3D"font-family:monospace;fon=
t-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-c=
aps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-inde=
nt:0px;text-transform:none;white-space:normal;word-spacing:0px;background-c=
olor:rgb(250,250,250);text-decoration-style:initial;text-decoration-color:i=
nitial;color:rgb(136,0,0)">=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/* potentially lots more s=
tuff here */<br></span><span class=3D"gmail-m_-2490841964736461158styled-by=
-prettify" style=3D"font-family:monospace;font-size:small;font-style:normal=
;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;let=
ter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;whi=
te-space:normal;word-spacing:0px;background-color:rgb(250,250,250);text-dec=
oration-style:initial;text-decoration-color:initial;color:rgb(102,102,0)">&=
gt;>>;</span><br><br>it looks much less bad, somewhat reducing the st=
rength of the argument.<br><br>Also, are there SFINAE issues here?=C2=A0 It=
seems like we might want a construct<br>that returns the first matching ty=
pe without failing altogether if a later type fails<br>instantiation.</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/CAHSYqdYZP9e5mz0DFVn6RiiGFKvJXYpB52TD=
1jw_6%3DaynDzG2Q%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">h=
ttps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAHSYqdYZP9e5mz=
0DFVn6RiiGFKvJXYpB52TD1jw_6%3DaynDzG2Q%40mail.gmail.com</a>.<br />
--001a11498928494d96056866077c--
.
Author: hamza_sood@me.com
Date: Tue, 27 Mar 2018 08:10:38 -0700 (PDT)
Raw View
------=_Part_18659_363599997.1522163438559
Content-Type: multipart/alternative;
boundary="----=_Part_18660_363459618.1522163438560"
------=_Part_18660_363459618.1522163438560
Content-Type: text/plain; charset="UTF-8"
That's definitely a nicer way of formatting it, however I still think
there's a few issues with it:
1. Heavy nesting of the conditional_t types will leave you with one huge
">>>>>>>>>>>>>>;" at the end of the line. That's really difficult to manage
(I've tried it and it's a real pain).
2. You're explicitly comparing each case, which is somewhat error prone
and the intent is less clear. It's like how most people favour a switch
statement over a huge if/else chain.
As for substitution failures: conditional_t doesn't allow erroneous
constructs for the unselected type, so I'd imagine that this would work in
the same way.
On Tuesday, March 27, 2018 at 3:51:44 PM UTC+1, Hyman Rosen wrote:
>
> On Tue, Mar 27, 2018 at 8:40 AM, Hamza Sood <hamza...@me.com <javascript:>
> > wrote:
>>
>> Or you can try to chain std::conditionals:
>>
>> template<int i>
>> using MyType = std::conditional_t<i == 0, FirstType,
>> std::conditional_t<i == 1, SecondType,
>> std::conditional_t<i
>> == 2, ThirdType, /* potentially lots more stuff here... */>>>;
>>
>> which is even worse.
>>
>
> If you write it as
>
> template<int i> using MyType =
> std::conditional_t<i == 0, FirstType,
> std::conditional_t<i == 1, SecondType,
> std::conditional_t<i == 2, ThirdType,
> /* potentially lots more stuff here */
> >>>;
>
> it looks much less bad, somewhat reducing the strength of the argument.
>
> Also, are there SFINAE issues here? It seems like we might want a
> construct
> that returns the first matching type without failing altogether if a later
> type fails
> instantiation.
>
--
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/6c97ed4c-6d3c-414f-8621-10daad8a9cab%40isocpp.org.
------=_Part_18660_363459618.1522163438560
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">That's definitely a nicer way of formatting it, howeve=
r I still think there's a few issues with it:<div><ol><li>Heavy nesting=
of the conditional_t types will leave you with one huge ">>>=
>>>>>>>>>>>;" at the end of the line.=
That's really difficult to manage (I've tried it and it's a re=
al pain).</li><li>You're explicitly comparing each case, which is somew=
hat error prone and the intent is less clear. It's like how most people=
favour a switch statement over a huge if/else chain.</li></ol><div>As for =
substitution failures: conditional_t doesn't allow erroneous constructs=
for the unselected type, so I'd imagine that this would work in the sa=
me way.</div><div><br></div>On Tuesday, March 27, 2018 at 3:51:44 PM UTC+1,=
Hyman Rosen wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;mar=
gin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D=
"ltr"><div><div class=3D"gmail_quote">On Tue, Mar 27, 2018 at 8:40 AM, Hamz=
a Sood <span dir=3D"ltr"><<a href=3D"javascript:" target=3D"_blank" gdf-=
obfuscated-mailto=3D"ioIulVViAwAJ" rel=3D"nofollow" onmousedown=3D"this.hre=
f=3D'javascript:';return true;" onclick=3D"this.href=3D'javascr=
ipt:';return true;">hamza...@me.com</a>></span> wrote:<blockquote cl=
ass=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;p=
adding-left:1ex"><div dir=3D"ltr"><div><div>Or you can try to chain std::co=
nditionals:</div><div><br></div><div><div style=3D"background-color:rgb(250=
,250,250);border:1px solid rgb(187,187,187);word-wrap:break-word"><code><di=
v><font><span style=3D"color:#008">template</span><span style=3D"color:#660=
"><</span><span style=3D"color:#008">int</span><span style=3D"color:#000=
"> i</span><span style=3D"color:#660">></span><span style=3D"color:#000"=
><br></span><span style=3D"color:#008">using</span><span style=3D"color:#00=
0"> </span><span style=3D"color:#606">MyType</span><span style=3D"color:#00=
0"> </span><span style=3D"color:#660">=3D</span><span style=3D"color:#000">=
std</span><span style=3D"color:#660">::</span><span style=3D"color:#000">c=
onditional_t</span><span style=3D"color:#660"><</span><span style=3D"col=
or:#000">i </span><span style=3D"color:#660">=3D=3D</span><span style=3D"co=
lor:#000"> </span><span style=3D"color:#066">0</span><span style=3D"color:#=
660">,</span><span style=3D"color:#000"> </span><span style=3D"color:#606">=
FirstType</span><span style=3D"color:#660">,</span><span style=3D"color:#00=
0"><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 std</span><span style=
=3D"color:#660">::</span><span style=3D"color:#000">conditional_t</span><fo=
nt color=3D"#008800"><span style=3D"color:#660"><</span><span><span styl=
e=3D"color:#000">i</span></span><span style=3D"color:#000"> </span><span st=
yle=3D"color:#660">=3D=3D</span><span style=3D"color:#000"> </span><span st=
yle=3D"color:#066">1</span><span style=3D"color:#660">,</span><span style=
=3D"color:#000"> </span><span style=3D"color:#606">SecondType</span><span s=
tyle=3D"color:#660">,</span><span style=3D"color:#000"><br></span></font><s=
pan style=3D"color:#000">=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 =C2=A0 =C2=A0 =C2=A0std</span=
><span style=3D"color:#660">::</span><span style=3D"color:#000">conditional=
_t</span><span style=3D"color:#660"><</span><span style=3D"color:#000">i=
</span><span style=3D"color:#660">=3D=3D</span><span style=3D"color:#000">=
</span><span style=3D"color:#066">2</span><span style=3D"color:#660">,</sp=
an><span style=3D"color:#000"> </span><span style=3D"color:#606">ThirdType<=
/span><span style=3D"color:#660">,</span><span style=3D"color:#000"> </span=
><span style=3D"color:#800">/* potentially lots more stuff here... */</span=
><span style=3D"color:#660">>>>;</span></font></div></code></div><=
div><br></div>which is even worse.</div></div></div></blockquote><div><br>I=
f you write it as<br><br><span style=3D"font-family:monospace;font-size:sma=
ll;font-style:normal;font-weight:400;letter-spacing:normal;text-align:start=
;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;ba=
ckground-color:rgb(250,250,250);color:rgb(0,0,136)">template</span><span st=
yle=3D"font-family:monospace;font-size:small;font-style:normal;font-weight:=
400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:n=
one;white-space:normal;word-spacing:0px;background-color:rgb(250,250,250);c=
olor:rgb(102,102,0)"><</span><span style=3D"font-family:monospace;font-s=
ize:small;font-style:normal;font-weight:400;letter-spacing:normal;text-alig=
n:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing=
:0px;background-color:rgb(250,250,250);color:rgb(0,0,136)">int</span><span =
style=3D"font-family:monospace;font-size:small;font-style:normal;font-weigh=
t:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform=
:none;white-space:normal;word-spacing:0px;background-color:rgb(250,250,250)=
;color:rgb(0,0,0)"><span>=C2=A0</span>i</span><span style=3D"font-family:mo=
nospace;font-size:small;font-style:normal;font-weight:400;letter-spacing:no=
rmal;text-align:start;text-indent:0px;text-transform:none;white-space:norma=
l;word-spacing:0px;background-color:rgb(250,250,250);color:rgb(102,102,0)">=
>=C2=A0</span><span style=3D"font-family:monospace;font-size:small;font-=
style:normal;font-weight:400;letter-spacing:normal;text-align:start;text-in=
dent:0px;text-transform:none;white-space:normal;word-spacing:0px;background=
-color:rgb(250,250,250);color:rgb(0,0,136)">using</span><span style=3D"font=
-family:monospace;font-size:small;font-style:normal;font-weight:400;letter-=
spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-s=
pace:normal;word-spacing:0px;background-color:rgb(250,250,250);color:rgb(0,=
0,0)"><span>=C2=A0</span></span><span style=3D"font-family:monospace;font-s=
ize:small;font-style:normal;font-weight:400;letter-spacing:normal;text-alig=
n:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing=
:0px;background-color:rgb(250,250,250);color:rgb(102,0,102)">MyType</span><=
span style=3D"font-family:monospace;font-size:small;font-style:normal;font-=
weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-tran=
sform:none;white-space:normal;word-spacing:0px;background-color:rgb(250,250=
,250);color:rgb(0,0,0)"><span>=C2=A0</span></span><span style=3D"font-famil=
y:monospace;font-size:small;font-style:normal;font-weight:400;letter-spacin=
g:normal;text-align:start;text-indent:0px;text-transform:none;white-space:n=
ormal;word-spacing:0px;background-color:rgb(250,250,250);color:rgb(102,102,=
0)">=3D<br></span><span style=3D"font-family:monospace;font-size:small;font=
-style:normal;font-weight:400;letter-spacing:normal;text-align:start;text-i=
ndent:0px;text-transform:none;white-space:normal;word-spacing:0px;backgroun=
d-color:rgb(250,250,250);color:rgb(0,0,0)">std</span><span style=3D"font-fa=
mily:monospace;font-size:small;font-style:normal;font-weight:400;letter-spa=
cing:normal;text-align:start;text-indent:0px;text-transform:none;white-spac=
e:normal;word-spacing:0px;background-color:rgb(250,250,250);color:rgb(102,1=
02,0)">::</span><span style=3D"font-family:monospace;font-size:small;font-s=
tyle:normal;font-weight:400;letter-spacing:normal;text-align:start;text-ind=
ent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-=
color:rgb(250,250,250);color:rgb(0,0,0)">conditional_t</span><span style=3D=
"font-family:monospace;font-size:small;font-style:normal;font-weight:400;le=
tter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;wh=
ite-space:normal;word-spacing:0px;background-color:rgb(250,250,250);color:r=
gb(102,102,0)"><</span><span style=3D"font-family:monospace;font-size:sm=
all;font-style:normal;font-weight:400;letter-spacing:normal;text-align:star=
t;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;b=
ackground-color:rgb(250,250,250);color:rgb(0,0,0)">i<span>=C2=A0</span></sp=
an><span style=3D"font-family:monospace;font-size:small;font-style:normal;f=
ont-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-=
transform:none;white-space:normal;word-spacing:0px;background-color:rgb(250=
,250,250);color:rgb(102,102,0)">=3D=3D</span><span style=3D"font-family:mon=
ospace;font-size:small;font-style:normal;font-weight:400;letter-spacing:nor=
mal;text-align:start;text-indent:0px;text-transform:none;white-space:normal=
;word-spacing:0px;background-color:rgb(250,250,250);color:rgb(0,0,0)"><span=
>=C2=A0</span></span><span style=3D"font-family:monospace;font-size:small;f=
ont-style:normal;font-weight:400;letter-spacing:normal;text-align:start;tex=
t-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;backgr=
ound-color:rgb(250,250,250);color:rgb(0,102,102)">0</span><span style=3D"fo=
nt-family:monospace;font-size:small;font-style:normal;font-weight:400;lette=
r-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white=
-space:normal;word-spacing:0px;background-color:rgb(250,250,250);color:rgb(=
102,102,0)">,</span><span style=3D"font-family:monospace;font-size:small;fo=
nt-style:normal;font-weight:400;letter-spacing:normal;text-align:start;text=
-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;backgro=
und-color:rgb(250,250,250);color:rgb(0,0,0)"><span>=C2=A0</span></span><spa=
n style=3D"font-family:monospace;font-size:small;font-style:normal;font-wei=
ght:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transfo=
rm:none;white-space:normal;word-spacing:0px;background-color:rgb(250,250,25=
0);color:rgb(102,0,102)">Fir<wbr>stType</span><span style=3D"font-family:mo=
nospace;font-size:small;font-style:normal;font-weight:400;letter-spacing:no=
rmal;text-align:start;text-indent:0px;text-transform:none;white-space:norma=
l;word-spacing:0px;background-color:rgb(250,250,250);color:rgb(102,102,0)">=
,</span><span style=3D"font-family:monospace;font-size:small;font-style:nor=
mal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;=
text-transform:none;white-space:normal;word-spacing:0px;background-color:rg=
b(250,250,250);color:rgb(0,0,0)"><br>std</span><span style=3D"font-family:m=
onospace;font-size:small;font-style:normal;font-weight:400;letter-spacing:n=
ormal;text-align:start;text-indent:0px;text-transform:none;white-space:norm=
al;word-spacing:0px;background-color:rgb(250,250,250);color:rgb(102,102,0)"=
>::</span><span style=3D"font-family:monospace;font-size:small;font-style:n=
ormal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0p=
x;text-transform:none;white-space:normal;word-spacing:0px;background-color:=
rgb(250,250,250);color:rgb(0,0,0)">conditional_t</span><font color=3D"#0088=
00" style=3D"font-family:monospace;font-size:small;font-style:normal;font-w=
eight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-trans=
form:none;white-space:normal;word-spacing:0px;background-color:rgb(250,250,=
250)"><span style=3D"color:rgb(102,102,0)"><</span><span><span style=3D"=
color:rgb(0,0,0)">i</span></span><span style=3D"color:rgb(0,0,0)"><span>=C2=
=A0</span></span><span style=3D"color:rgb(102,102,0)">=3D=3D</span><span st=
yle=3D"color:rgb(0,0,0)"><span>=C2=A0</span></span><span style=3D"color:rgb=
(0,102,102)">1</span><span style=3D"color:rgb(102,102,0)">,</span><span sty=
le=3D"color:rgb(0,0,0)"><span>=C2=A0</span></span><span style=3D"color:rgb(=
102,0,102)">Sec<wbr>ondType</span><span style=3D"color:rgb(102,102,0)">,</s=
pan><span style=3D"color:rgb(0,0,0)"><br></span></font><span style=3D"font-=
family:monospace;font-size:small;font-style:normal;font-weight:400;letter-s=
pacing:normal;text-align:start;text-indent:0px;text-transform:none;white-sp=
ace:normal;word-spacing:0px;background-color:rgb(250,250,250);color:rgb(0,0=
,0)">std</span><span style=3D"font-family:monospace;font-size:small;font-st=
yle:normal;font-weight:400;letter-spacing:normal;text-align:start;text-inde=
nt:0px;text-transform:none;white-space:normal;word-spacing:0px;background-c=
olor:rgb(250,250,250);color:rgb(102,102,0)">::</span><span style=3D"font-fa=
mily:monospace;font-size:small;font-style:normal;font-weight:400;letter-spa=
cing:normal;text-align:start;text-indent:0px;text-transform:none;white-spac=
e:normal;word-spacing:0px;background-color:rgb(250,250,250);color:rgb(0,0,0=
)">conditional_t</span><span style=3D"font-family:monospace;font-size:small=
;font-style:normal;font-weight:400;letter-spacing:normal;text-align:start;t=
ext-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;back=
ground-color:rgb(250,250,250);color:rgb(102,102,0)"><</span><span style=
=3D"font-family:monospace;font-size:small;font-style:normal;font-weight:400=
;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none=
;white-space:normal;word-spacing:0px;background-color:rgb(250,250,250);colo=
r:rgb(0,0,0)">i<span>=C2=A0</span></span><span style=3D"font-family:monospa=
ce;font-size:small;font-style:normal;font-weight:400;letter-spacing:normal;=
text-align:start;text-indent:0px;text-transform:none;white-space:normal;wor=
d-spacing:0px;background-color:rgb(250,250,250);color:rgb(102,102,0)">=3D=
=3D</span><span style=3D"font-family:monospace;font-size:small;font-style:n=
ormal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0p=
x;text-transform:none;white-space:normal;word-spacing:0px;background-color:=
rgb(250,250,250);color:rgb(0,0,0)"><span>=C2=A0</span></span><span style=3D=
"font-family:monospace;font-size:small;font-style:normal;font-weight:400;le=
tter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;wh=
ite-space:normal;word-spacing:0px;background-color:rgb(250,250,250);color:r=
gb(0,102,102)">2</span><span style=3D"font-family:monospace;font-size:small=
;font-style:normal;font-weight:400;letter-spacing:normal;text-align:start;t=
ext-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;back=
ground-color:rgb(250,250,250);color:rgb(102,102,0)">,</span><span style=3D"=
font-family:monospace;font-size:small;font-style:normal;font-weight:400;let=
ter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;whi=
te-space:normal;word-spacing:0px;background-color:rgb(250,250,250);color:rg=
b(0,0,0)"><span>=C2=A0</span></span><span style=3D"font-family:monospace;fo=
nt-size:small;font-style:normal;font-weight:400;letter-spacing:normal;text-=
align:start;text-indent:0px;text-transform:none;white-space:normal;word-spa=
cing:0px;background-color:rgb(250,250,250);color:rgb(102,0,102)">Thi<wbr>rd=
Type</span><span style=3D"font-family:monospace;font-size:small;font-style:=
normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0=
px;text-transform:none;white-space:normal;word-spacing:0px;background-color=
:rgb(250,250,250);color:rgb(102,102,0)">,<br></span><span style=3D"font-fam=
ily:monospace;font-size:small;font-style:normal;font-weight:400;letter-spac=
ing:normal;text-align:start;text-indent:0px;text-transform:none;white-space=
:normal;word-spacing:0px;background-color:rgb(250,250,250);color:rgb(136,0,=
0)">=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/* potentially lots more stuff here */<br></span=
><span style=3D"font-family:monospace;font-size:small;font-style:normal;fon=
t-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-tr=
ansform:none;white-space:normal;word-spacing:0px;background-color:rgb(250,2=
50,250);color:rgb(102,102,0)">>>>;</span><br><br>it looks much les=
s bad, somewhat reducing the strength of the argument.<br><br>Also, are the=
re SFINAE issues here?=C2=A0 It seems like we might want a construct<br>tha=
t returns the first matching type without failing altogether if a later typ=
e fails<br>instantiation.</div></div></div></div>
</blockquote></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/6c97ed4c-6d3c-414f-8621-10daad8a9cab%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/6c97ed4c-6d3c-414f-8621-10daad8a9cab=
%40isocpp.org</a>.<br />
------=_Part_18660_363459618.1522163438560--
------=_Part_18659_363599997.1522163438559--
.
Author: Arthur O'Dwyer <arthur.j.odwyer@gmail.com>
Date: Tue, 27 Mar 2018 15:47:59 -0700 (PDT)
Raw View
------=_Part_14970_1683263056.1522190879959
Content-Type: multipart/alternative;
boundary="----=_Part_14971_922896902.1522190879959"
------=_Part_14971_922896902.1522190879959
Content-Type: text/plain; charset="UTF-8"
On Tuesday, March 27, 2018 at 8:10:38 AM UTC-7, hamza...@me.com wrote:
>
> That's definitely a nicer way of formatting it, however I still think
> there's a few issues with it:
>
> 1. Heavy nesting of the conditional_t types will leave you with one
> huge ">>>>>>>>>>>>>>;" at the end of the line. That's really difficult to
> manage (I've tried it and it's a real pain).
> 2. You're explicitly comparing each case, which is somewhat error
> prone and the intent is less clear. It's like how most people favour a
> switch statement over a huge if/else chain.
>
> But if the `i` values are possibly not consecutive, then I'd consider (2)
a huge win. For example, it lets you write
template<int i> using MyType =
std::conditional_t<i < 1, FirstType,
std::conditional_t<1 <= i && i < 10, SecondType,
std::conditional_t<10 <= i, ThirdType>>>;
However, in C++17 we get `if constexpr`, so personally I would just use
that:
https://wandbox.org/permlink/3EnvHel8t0jucpk2
template<class T> struct wrap {};
template<class T> struct unwrapper;
template<class T> struct unwrapper<wrap<T>> { using type = T; };
template<class T> using unwrap = typename unwrapper<T>::type;
template<int i>
auto helper() {
if constexpr(i == 0) {
return wrap<FirstType>{};
} else if constexpr (i == 1) {
return wrap<SecondType>{};
} else if constexpr (i == 2) {
return wrap<ThirdType>{};
}
}
template<int i> using MyType = unwrap<decltype(helper<i>())>;
I suspect (but do not know for sure) that this formulation will also be
much much easier on the compiler's internal data structures.
HTH,
Arthur
>
--
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/4c759727-42af-4dd2-a7d7-26807c5889eb%40isocpp.org.
------=_Part_14971_922896902.1522190879959
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Tuesday, March 27, 2018 at 8:10:38 AM UTC-7, hamza...@m=
e.com 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">T=
hat's definitely a nicer way of formatting it, however I still think th=
ere's a few issues with it:<div><ol><li>Heavy nesting of the conditiona=
l_t types will leave you with one huge ">>>>>>>&g=
t;>>>>>>;" at the end of the line. That's really=
difficult to manage (I've tried it and it's a real pain).</li><li>=
You're explicitly comparing each case, which is somewhat error prone an=
d the intent is less clear. It's like how most people favour a switch s=
tatement over a huge if/else chain.</li></ol></div></div></blockquote><div>=
But if the `i` values are possibly not consecutive, then I'd consider (=
2) a huge win. For example, it lets you write</div><div><br></div><div><div=
class=3D"F0XO1GC-Db-b"><span style=3D"font-family: monospace; font-size: s=
mall; background-color: rgb(250, 250, 250); color: rgb(0, 0, 136);">templat=
e</span><span style=3D"font-family: monospace; font-size: small; background=
-color: rgb(250, 250, 250); color: rgb(102, 102, 0);"><</span><span styl=
e=3D"font-family: monospace; font-size: small; background-color: rgb(250, 2=
50, 250); color: rgb(0, 0, 136);">int</span><span style=3D"font-family: mon=
ospace; font-size: small; background-color: rgb(250, 250, 250); color: rgb(=
0, 0, 0);">=C2=A0i</span><span style=3D"font-family: monospace; font-size: =
small; background-color: rgb(250, 250, 250); color: rgb(102, 102, 0);">>=
=C2=A0</span><span style=3D"font-family: monospace; font-size: small; backg=
round-color: rgb(250, 250, 250); color: rgb(0, 0, 136);">using</span><span =
style=3D"font-family: monospace; font-size: small; background-color: rgb(25=
0, 250, 250); color: rgb(0, 0, 0);">=C2=A0</span><span style=3D"font-family=
: monospace; font-size: small; background-color: rgb(250, 250, 250); color:=
rgb(102, 0, 102);">MyType</span><span style=3D"font-family: monospace; fon=
t-size: small; background-color: rgb(250, 250, 250); color: rgb(0, 0, 0);">=
=C2=A0</span><span style=3D"font-family: monospace; font-size: small; backg=
round-color: rgb(250, 250, 250); color: rgb(102, 102, 0);">=3D<br></span></=
div><div class=3D"F0XO1GC-Db-b"><span style=3D"font-family: monospace; font=
-size: small; background-color: rgb(250, 250, 250); color: rgb(0, 0, 0);">=
=C2=A0 =C2=A0 std</span><span style=3D"font-family: monospace; font-size: s=
mall; background-color: rgb(250, 250, 250); color: rgb(102, 102, 0);">::</s=
pan><span style=3D"font-family: monospace; font-size: small; background-col=
or: rgb(250, 250, 250); color: rgb(0, 0, 0);">conditional_t</span><span sty=
le=3D"font-family: monospace; font-size: small; background-color: rgb(250, =
250, 250); color: rgb(102, 102, 0);"><</span><span style=3D"font-family:=
monospace; font-size: small; background-color: rgb(250, 250, 250); color: =
rgb(0, 0, 0);">i=C2=A0</span><span style=3D"color: rgb(102, 102, 0); font-f=
amily: monospace; font-size: small; background-color: rgb(250, 250, 250);">=
<</span><span style=3D"font-family: monospace; font-size: small; backgro=
und-color: rgb(250, 250, 250); color: rgb(0, 0, 0);">=C2=A0</span><span sty=
le=3D"color: rgb(0, 102, 102); font-family: monospace; font-size: small; ba=
ckground-color: rgb(250, 250, 250);">1</span><span style=3D"font-family: mo=
nospace; font-size: small; background-color: rgb(250, 250, 250); color: rgb=
(102, 102, 0);">,</span><span style=3D"font-family: monospace; font-size: s=
mall; background-color: rgb(250, 250, 250); color: rgb(0, 0, 0);">=C2=A0</s=
pan><span style=3D"font-family: monospace; font-size: small; background-col=
or: rgb(250, 250, 250); color: rgb(102, 0, 102);">Fir<wbr>stType</span><spa=
n style=3D"font-family: monospace; font-size: small; background-color: rgb(=
250, 250, 250); color: rgb(102, 102, 0);">,</span><span style=3D"font-famil=
y: monospace; font-size: small; background-color: rgb(250, 250, 250); color=
: rgb(0, 0, 0);"><br>=C2=A0 =C2=A0 std</span><span style=3D"font-family: mo=
nospace; font-size: small; background-color: rgb(250, 250, 250); color: rgb=
(102, 102, 0);">::</span><span style=3D"font-family: monospace; font-size: =
small; background-color: rgb(250, 250, 250); color: rgb(0, 0, 0);">conditio=
nal_t</span><font color=3D"#008800" style=3D"font-family: monospace; font-s=
ize: small; background-color: rgb(250, 250, 250);"><span style=3D"color: rg=
b(102, 102, 0);"><</span></font><span style=3D"color: rgb(0, 102, 102); =
font-family: monospace; font-size: small; background-color: rgb(250, 250, 2=
50);">1</span><font color=3D"#008800" style=3D"font-family: monospace; font=
-size: small; background-color: rgb(250, 250, 250);"><span style=3D"color: =
rgb(102, 102, 0);">=C2=A0<=3D=C2=A0</span><span style=3D"color: rgb(0, 0=
, 0);">i && i</span><span style=3D"color: rgb(0, 0, 0);">=C2=A0</sp=
an><span style=3D"color: rgb(102, 102, 0);"><</span><span style=3D"color=
: rgb(0, 0, 0);">=C2=A0</span><span style=3D"color: rgb(0, 102, 102);">10</=
span><span style=3D"color: rgb(102, 102, 0);">,</span><span style=3D"color:=
rgb(0, 0, 0);">=C2=A0</span><span style=3D"color: rgb(102, 0, 102);">Sec<w=
br>ondType</span><span style=3D"color: rgb(102, 102, 0);">,</span><span sty=
le=3D"color: rgb(0, 0, 0);"><br></span></font><span style=3D"font-family: m=
onospace; font-size: small; background-color: rgb(250, 250, 250); color: rg=
b(0, 0, 0);">=C2=A0 =C2=A0 std</span><span style=3D"font-family: monospace;=
font-size: small; background-color: rgb(250, 250, 250); color: rgb(102, 10=
2, 0);">::</span><span style=3D"font-family: monospace; font-size: small; b=
ackground-color: rgb(250, 250, 250); color: rgb(0, 0, 0);">conditional_t</s=
pan><span style=3D"font-family: monospace; font-size: small; background-col=
or: rgb(250, 250, 250); color: rgb(102, 102, 0);"><</span><span style=3D=
"color: rgb(0, 102, 102); font-family: monospace; font-size: small; backgro=
und-color: rgb(250, 250, 250);">10</span><span style=3D"font-family: monosp=
ace; font-size: small; background-color: rgb(250, 250, 250); color: rgb(0, =
0, 0);">=C2=A0</span><span style=3D"font-family: monospace; font-size: smal=
l; background-color: rgb(250, 250, 250); color: rgb(102, 102, 0);"><=3D<=
/span><span style=3D"font-family: monospace; font-size: small; background-c=
olor: rgb(250, 250, 250); color: rgb(0, 0, 0);">=C2=A0</span><span style=3D=
"font-family: monospace; font-size: small; background-color: rgb(250, 250, =
250); color: rgb(0, 0, 0);">i</span><span style=3D"font-family: monospace; =
font-size: small; background-color: rgb(250, 250, 250); color: rgb(102, 102=
, 0);">,</span><span style=3D"font-family: monospace; font-size: small; bac=
kground-color: rgb(250, 250, 250); color: rgb(0, 0, 0);">=C2=A0</span><span=
style=3D"font-family: monospace; font-size: small; background-color: rgb(2=
50, 250, 250); color: rgb(102, 0, 102);">Thi<wbr>rdType</span><span style=
=3D"color: rgb(102, 102, 0); font-family: monospace; font-size: small; back=
ground-color: rgb(250, 250, 250);">>>>;<br></span></div></div><div=
><br></div><div>However, in C++17 we get `if constexpr`, so personally I wo=
uld just use that:</div><div><a href=3D"https://wandbox.org/permlink/3EnvHe=
l8t0jucpk2">https://wandbox.org/permlink/3EnvHel8t0jucpk2</a><br></div><div=
><br></div><div>template<class T> struct wrap {};</div><div>template&=
lt;class T> struct unwrapper;</div><div>template<class T> struct u=
nwrapper<wrap<T>> { using type =3D T; };</div><div>template<=
class T> using unwrap =3D typename unwrapper<T>::type;</div><div><=
br></div><div>template<int i></div><div>auto helper() {</div><div>=C2=
=A0 =C2=A0 if constexpr(i =3D=3D 0) {</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0=
return wrap<FirstType>{};</div><div>=C2=A0 =C2=A0 } else if constexp=
r (i =3D=3D 1) {</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 return wrap<Secon=
dType>{};</div><div>=C2=A0 =C2=A0 } else if constexpr (i =3D=3D 2) {</di=
v><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 return wrap<ThirdType>{};</div><di=
v>=C2=A0 =C2=A0 }</div><div>}</div><div><br></div><div>template<int i>=
; using MyType =3D unwrap<decltype(helper<i>())>;</div><div><br=
></div><div>I suspect (but do not know for sure) that this formulation will=
also be much much easier on the compiler's internal data structures.</=
div><div><br></div><div>HTH,</div><div>Arthur</div><blockquote class=3D"gma=
il_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid=
;padding-left: 1ex;"><div dir=3D"ltr"><div><blockquote class=3D"gmail_quote=
" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-le=
ft:1ex">
</blockquote></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/4c759727-42af-4dd2-a7d7-26807c5889eb%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/4c759727-42af-4dd2-a7d7-26807c5889eb=
%40isocpp.org</a>.<br />
------=_Part_14971_922896902.1522190879959--
------=_Part_14970_1683263056.1522190879959--
.
Author: inkwizytoryankes@gmail.com
Date: Tue, 27 Mar 2018 16:13:13 -0700 (PDT)
Raw View
------=_Part_20046_694843531.1522192393338
Content-Type: multipart/alternative;
boundary="----=_Part_20047_389886014.1522192393339"
------=_Part_20047_389886014.1522192393339
Content-Type: text/plain; charset="UTF-8"
On Tuesday, March 27, 2018 at 2:40:43 PM UTC+2, Hamza Sood wrote:
>
> Suppose you want to select a type based on a condition. You can do this
> with template specialisations at the language level:
>
> template<bool>
> struct MySelector;
>
> template<>
> struct MySelector<false> { typedef TypeIfFalse type; };
>
> template<>
> struct MySelector<true> { typedef TypeIfTrue type; };
>
> But that's a lot of boilerplate, so C++11 introduced std::conditional.
>
>
>
> Now instead suppose that you want to select a type based on the value of
> (non-boolean) non-type template parameter.
> You can either do the same specialisation trick:
>
> template<int>
> struct MySelector;
>
> template<>
> struct MySelector<0> { typedef FirstType type; };
>
> template<>
> struct MySelector<1> { typedef SecondType type; };
>
> template<>
> struct MySelector<2> { typedef ThirdType type; };
>
> // etc.
> // Potentially lots of other cases here...
>
> which is a bit cumbersome. Or you can try to chain std::conditionals:
>
> template<int i>
> using MyType = std::conditional_t<i == 0, FirstType,
> std::conditional_t<i == 1, SecondType,
> std::conditional_t<i
> == 2, ThirdType, /* potentially lots more stuff here... */>>>;
>
> which is even worse.
>
>
>
> I propose that a meta_switch type (better name welcome) is added to
> <type_traits>, to enable code such as:
>
> template<int i>
> using MyType = std::meta_switch_t<i,
> 0, FirstType,
> 1, SecondType,
> 2, ThirdType,
> // etc.
> >;
>
>
One nitpick, AFAIK you can't have mixed values and types in variadic
template parameters (until someone add `using...` parameters pack that
accepts types and values), it probably should look like:
std::meta_switch_t<i,
std::meta_case<0, FirstType>,
std::meta_case<1, SecondType>,
std::meta_case<2, ThirdType>
>;
--
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/097f9ce6-fe49-4d8b-93ea-b6345db56e89%40isocpp.org.
------=_Part_20047_389886014.1522192393339
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Tuesday, March 27, 2018 at 2:40:43 PM UTC+2, Ha=
mza Sood 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=
">Suppose you want to select a type based on a condition. You can do this w=
ith template specialisations at the language level:<div><br><div><div><div =
style=3D"background-color:rgb(250,250,250);border:1px solid rgb(187,187,187=
);word-wrap:break-word"><code><div><font color=3D"#660066"><span style=3D"c=
olor:#008">template</span><span style=3D"color:#080"><bool></span><sp=
an style=3D"color:#000"><br></span><span style=3D"color:#008">struct</span>=
<span style=3D"color:#000"> </span><span style=3D"color:#606">MySelector</s=
pan><span style=3D"color:#660">;</span><span style=3D"color:#000"><br><br><=
/span><span style=3D"color:#008">template</span><span style=3D"color:#660">=
<></span><span style=3D"color:#000"><br></span><span style=3D"color:#=
008">struct</span><span style=3D"color:#000"> </span><span style=3D"color:#=
606">MySelector</span><span style=3D"color:#080"><false></span><span =
style=3D"color:#000"> </span><span style=3D"color:#660">{</span><span style=
=3D"color:#000"> </span><span style=3D"color:#008">typedef</span><span styl=
e=3D"color:#000"> </span><span style=3D"color:#606">TypeIfFalse</span><span=
style=3D"color:#000"> type</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"><br><br></span></font><span style=3D"color:#008">template<=
/span><span style=3D"color:#660"><></span><span style=3D"color:#000">=
<br></span><span style=3D"color:#008">struct</span><span style=3D"color:#00=
0"> </span><span style=3D"color:#606">MySelector</span><span style=3D"color=
:#080"><true></span><span style=3D"color:#000"> </span><span style=3D=
"color:#660">{</span><span style=3D"color:#000"> </span><span style=3D"colo=
r:#008">typedef</span><span style=3D"color:#000"> </span><span style=3D"col=
or:#606">TypeIfTrue</span><span style=3D"color:#000"> type</span><span styl=
e=3D"color:#660">;</span><span style=3D"color:#000"> </span><span style=3D"=
color:#660">};</span></div></code></div><div><br></div>But that's a lot=
of boilerplate, so C++11 introduced std::conditional.</div></div><div><br>=
</div><div><br></div><div><br></div><div>Now instead suppose that you want =
to select a type based on the value of (non-boolean) non-type template para=
meter.</div><div>You can either do the same specialisation trick:</div><div=
><br></div><div><div style=3D"background-color:rgb(250,250,250);border:1px =
solid rgb(187,187,187);word-wrap:break-word"><code><div><span style=3D"colo=
r:#008">template</span><span style=3D"color:#080"><int></span><span s=
tyle=3D"color:#000"><br></span><span style=3D"color:#008">struct</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#606">MySelector</span>=
<span style=3D"color:rgb(102,102,0);font-family:Arial,Helvetica,sans-serif"=
><span style=3D"color:#660">;</span><span style=3D"color:#000"><br></span><=
/span><span style=3D"color:#000"><br></span><span style=3D"color:#008">temp=
late</span><span style=3D"color:#660"><></span><span style=3D"color:#=
000"><br></span><span style=3D"color:#008">struct</span><span style=3D"colo=
r:#000"> </span><span style=3D"color:#606">MySelector</span><span style=3D"=
color:#660"><</span><span style=3D"color:#066">0</span><span style=3D"co=
lor:#660">></span><span style=3D"color:#000"> </span><span style=3D"colo=
r:#660">{</span><span style=3D"color:#000"> </span><span style=3D"color:#00=
8">typedef</span><span style=3D"color:#000"> </span><span style=3D"color:#6=
06">FirstType</span><span style=3D"color:#000"> type</span><span style=3D"c=
olor:#660">;</span><span style=3D"color:#000"> </span><span style=3D"color:=
#660">};</span><span style=3D"color:#000"><br><br></span><span style=3D"col=
or:#008">template</span><span style=3D"color:#660"><></span><span sty=
le=3D"color:#000"><br></span><span style=3D"color:#008">struct</span><span =
style=3D"color:#000"> </span><span style=3D"color:#606">MySelector</span><s=
pan style=3D"color:#660"><</span><span style=3D"color:#066">1</span><spa=
n style=3D"color:#660">></span><span style=3D"color:#000"> </span><span =
style=3D"color:#660">{</span><span style=3D"color:#000"> </span><span style=
=3D"color:#008">typedef</span><span style=3D"color:#000"> </span><span styl=
e=3D"color:#606">SecondType</span><span style=3D"color:#000"> type</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><br></span><spa=
n style=3D"color:#008">template</span><span style=3D"color:#660"><></=
span><span style=3D"color:#000"><br></span><span style=3D"color:#008">struc=
t</span><span style=3D"color:#000"> </span><span style=3D"color:#606">MySel=
ector</span><span style=3D"color:#660"><</span><font color=3D"#006666"><=
span style=3D"color:#066">2</span></font><span style=3D"color:#660">></s=
pan><span style=3D"color:#000"> </span><span style=3D"color:#660">{</span><=
span style=3D"color:#000"> </span><span style=3D"color:#008">typedef</span>=
<span style=3D"color:#000"> </span><span style=3D"color:#606">ThirdType</sp=
an><span style=3D"color:#000"> type</span><span style=3D"color:#660">;</spa=
n><span style=3D"color:#000"> </span><span style=3D"color:#660">};</span><s=
pan style=3D"color:#000"><br><br></span><span style=3D"color:#800">// etc.<=
/span><span style=3D"color:#000"><br></span><span style=3D"color:#800">// P=
otentially lots of other cases here...</span></div></code></div><div><br></=
div>which is a bit cumbersome. Or you can try to chain std::conditionals:</=
div><div><br></div><div><div style=3D"background-color:rgb(250,250,250);bor=
der:1px solid rgb(187,187,187);word-wrap:break-word"><code><div><font><span=
style=3D"color:#008">template</span><span style=3D"color:#660"><</span>=
<span style=3D"color:#008">int</span><span style=3D"color:#000"> i</span><s=
pan style=3D"color:#660">></span><span style=3D"color:#000"><br></span><=
span style=3D"color:#008">using</span><span style=3D"color:#000"> </span><s=
pan style=3D"color:#606">MyType</span><span style=3D"color:#000"> </span><s=
pan style=3D"color:#660">=3D</span><span style=3D"color:#000"> std</span><s=
pan style=3D"color:#660">::</span><span style=3D"color:#000">conditional_t<=
/span><span style=3D"color:#660"><</span><span style=3D"color:#000">i </=
span><span style=3D"color:#660">=3D=3D</span><span style=3D"color:#000"> </=
span><span style=3D"color:#066">0</span><span style=3D"color:#660">,</span>=
<span style=3D"color:#000"> </span><span style=3D"color:#606">FirstType</sp=
an><span style=3D"color:#660">,</span><span style=3D"color:#000"><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 std</span><span style=3D"color:#660"=
>::</span><span style=3D"color:#000">conditional_t</span><font color=3D"#00=
8800"><span style=3D"color:#660"><</span><span><span style=3D"color:#000=
">i</span></span><span style=3D"color:#000"> </span><span style=3D"color:#6=
60">=3D=3D</span><span style=3D"color:#000"> </span><span style=3D"color:#0=
66">1</span><span style=3D"color:#660">,</span><span style=3D"color:#000"> =
</span><span style=3D"color:#606">SecondType</span><span style=3D"color:#66=
0">,</span><span style=3D"color:#000"><br></span></font><span style=3D"colo=
r:#000">=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 =C2=A0 =C2=A0 =C2=A0std</span><span style=3D"co=
lor:#660">::</span><span style=3D"color:#000">conditional_t</span><span sty=
le=3D"color:#660"><</span><span style=3D"color:#000">i </span><span styl=
e=3D"color:#660">=3D=3D</span><span style=3D"color:#000"> </span><span styl=
e=3D"color:#066">2</span><span style=3D"color:#660">,</span><span style=3D"=
color:#000"> </span><span style=3D"color:#606">ThirdType</span><span style=
=3D"color:#660">,</span><span style=3D"color:#000"> </span><span style=3D"c=
olor:#800">/* potentially lots more stuff here... */</span><span style=3D"c=
olor:#660">>>>;</span></font></div></code></div><div><br></div>whi=
ch is even worse.</div><div><br></div><div><br></div><div><br></div><div>I =
propose that a meta_switch type (better name welcome) is added to <type_=
traits>, to enable code such as:</div><div><br></div><div><div style=3D"=
background-color:rgb(250,250,250);border:1px solid rgb(187,187,187);word-wr=
ap:break-word"><code><div><font><span style=3D"color:#008">template</span><=
span style=3D"color:#660"><</span><span style=3D"color:#008">int</span><=
font color=3D"#000000"><span style=3D"color:#000"> i</span><span style=3D"c=
olor:#660">></span><span style=3D"color:#000"><br></span><span style=3D"=
color:#008">using</span><span style=3D"color:#000"> </span><span style=3D"c=
olor:#606">MyType</span><span style=3D"color:#000"> </span><span style=3D"c=
olor:#660">=3D</span><span style=3D"color:#000"> std</span><span style=3D"c=
olor:#660">::</span><span style=3D"color:#000">meta_switch_t</span><span st=
yle=3D"color:#660"><</span><span><span style=3D"color:#000">i</span><spa=
n style=3D"color:#660">,</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0=
</span><span style=3D"color:#066">0</span><span style=3D"color:#660">,</sp=
an><span style=3D"color:#000"> </span><span style=3D"color:#606">FirstType<=
/span><span style=3D"color:#660">,</span><span style=3D"color:#000"><br>=C2=
=A0 =C2=A0 </span><span style=3D"color:#066">1</span><span style=3D"color:#=
660">,</span><span style=3D"color:#000"> </span><span style=3D"color:#606">=
SecondType</span><span style=3D"color:#660">,</span><span style=3D"color:#0=
00"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#066">2</span><span style=
=3D"color:#660">,</span><span style=3D"color:#000"> </span><span style=3D"c=
olor:#606">ThirdType</span><span style=3D"color:#660">,</span><span style=
=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#800">// etc.=
</span><span style=3D"color:#000"><br></span><span style=3D"color:#660">>=
;;</span></span></font></font></div></code></div></div></div><br></div></bl=
ockquote><div><br>One nitpick, AFAIK you can't have mixed values and ty=
pes in variadic template parameters (until someone add `using...` parameter=
s pack that accepts types and values), it probably should look like:<br><di=
v 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"prettyprint"><div class=3D"subprettyp=
rint"><span style=3D"color: #000;" class=3D"styled-by-prettify">std</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify">meta_switch_t</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify"><</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">i</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">,</span><code class=3D"prettyprint"><=
span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 std</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify">meta_case</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify"><</span><span style=
=3D"color: #066;" class=3D"styled-by-prettify">0</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: #606;" class=3D"=
styled-by-prettify">FirstType</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">></span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"></span></code><code class=3D"prettyprint"><span style=3D"color=
: #000;" class=3D"styled-by-prettify">,<br>=C2=A0 std</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify">meta_case</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify"><</span><span style=3D"color: #066;" c=
lass=3D"styled-by-prettify">1</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify"=
>SecondType</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>></span><span style=3D"color: #000;" class=3D"styled-by-prettify"></spa=
n></code><code class=3D"prettyprint"><span style=3D"color: #000;" class=3D"=
styled-by-prettify">,<br>=C2=A0 std</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify">meta_case</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify"><</span><span style=3D"color: #066;" class=3D"styled-by-=
prettify">2</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: #606;" class=3D"styled-by-prettify">ThirdType</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">></span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"></span></code><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:=
#000;" class=3D"styled-by-prettify"><br></span></div></code></div><br><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/097f9ce6-fe49-4d8b-93ea-b6345db56e89%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/097f9ce6-fe49-4d8b-93ea-b6345db56e89=
%40isocpp.org</a>.<br />
------=_Part_20047_389886014.1522192393339--
------=_Part_20046_694843531.1522192393338--
.
Author: hamza_sood@me.com
Date: Wed, 28 Mar 2018 03:21:58 -0700 (PDT)
Raw View
------=_Part_22441_1559524591.1522232518154
Content-Type: multipart/alternative;
boundary="----=_Part_22442_1203680396.1522232518155"
------=_Part_22442_1203680396.1522232518155
Content-Type: text/plain; charset="UTF-8"
Sure. But if you have a regular int and you want to match ranges like in
your example (1 <= i && i < 10), then you'd probably use if statements over
a switch.
It's really the same with meta-programming.
- If you'd usually use an if statement, then use std::conditional.
- If you'd usually use a switch statement, then use meta_switch.
On Tuesday, March 27, 2018 at 11:48:00 PM UTC+1, Arthur O'Dwyer wrote:
>
> On Tuesday, March 27, 2018 at 8:10:38 AM UTC-7, hamza...@me.com wrote:
>>
>> That's definitely a nicer way of formatting it, however I still think
>> there's a few issues with it:
>>
>> 1. Heavy nesting of the conditional_t types will leave you with one
>> huge ">>>>>>>>>>>>>>;" at the end of the line. That's really difficult to
>> manage (I've tried it and it's a real pain).
>> 2. You're explicitly comparing each case, which is somewhat error
>> prone and the intent is less clear. It's like how most people favour a
>> switch statement over a huge if/else chain.
>>
>> But if the `i` values are possibly not consecutive, then I'd consider (2)
> a huge win. For example, it lets you write
>
> template<int i> using MyType =
> std::conditional_t<i < 1, FirstType,
> std::conditional_t<1 <= i && i < 10, SecondType,
> std::conditional_t<10 <= i, ThirdType>>>;
>
> However, in C++17 we get `if constexpr`, so personally I would just use
> that:
> https://wandbox.org/permlink/3EnvHel8t0jucpk2
>
> template<class T> struct wrap {};
> template<class T> struct unwrapper;
> template<class T> struct unwrapper<wrap<T>> { using type = T; };
> template<class T> using unwrap = typename unwrapper<T>::type;
>
> template<int i>
> auto helper() {
> if constexpr(i == 0) {
> return wrap<FirstType>{};
> } else if constexpr (i == 1) {
> return wrap<SecondType>{};
> } else if constexpr (i == 2) {
> return wrap<ThirdType>{};
> }
> }
>
> template<int i> using MyType = unwrap<decltype(helper<i>())>;
>
> I suspect (but do not know for sure) that this formulation will also be
> much much easier on the compiler's internal data structures.
>
> HTH,
> Arthur
>
>>
--
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/0d99bca4-8b24-46cf-b325-8c2a885dec65%40isocpp.org.
------=_Part_22442_1203680396.1522232518155
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Sure. But if you have a regular int and you want to match =
ranges like in your example (1 <=3D i && i < 10), then you=
9;d probably use if statements over a switch.<div>It's really the same =
with meta-programming.<div><ul><li>If you'd usually use an if statement=
, then use std::conditional.<br></li><li>If you'd usually use a switch =
statement, then use meta_switch.</li></ul></div><div><br>On Tuesday, March =
27, 2018 at 11:48:00 PM UTC+1, Arthur O'Dwyer wrote:<blockquote class=
=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #cc=
c solid;padding-left: 1ex;"><div dir=3D"ltr">On Tuesday, March 27, 2018 at =
8:10:38 AM UTC-7, <a>hamza...@me.com</a> wrote:<blockquote class=3D"gmail_q=
uote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;paddin=
g-left:1ex"><div dir=3D"ltr">That's definitely a nicer way of formattin=
g it, however I still think there's a few issues with it:<div><ol><li>H=
eavy nesting of the conditional_t types will leave you with one huge "=
>>>>>>>>>>>>>>;" at the end =
of the line. That's really difficult to manage (I've tried it and i=
t's a real pain).</li><li>You're explicitly comparing each case, wh=
ich is somewhat error prone and the intent is less clear. It's like how=
most people favour a switch statement over a huge if/else chain.</li></ol>=
</div></div></blockquote><div>But if the `i` values are possibly not consec=
utive, then I'd consider (2) a huge win. For example, it lets you write=
</div><div><br></div><div><div><span style=3D"font-family:monospace;font-si=
ze:small;background-color:rgb(250,250,250);color:rgb(0,0,136)">template</sp=
an><span style=3D"font-family:monospace;font-size:small;background-color:rg=
b(250,250,250);color:rgb(102,102,0)"><</span><span style=3D"font-family:=
monospace;font-size:small;background-color:rgb(250,250,250);color:rgb(0,0,1=
36)">int</span><span style=3D"font-family:monospace;font-size:small;backgro=
und-color:rgb(250,250,250);color:rgb(0,0,0)">=C2=A0i</span><span style=3D"f=
ont-family:monospace;font-size:small;background-color:rgb(250,250,250);colo=
r:rgb(102,102,0)">>=C2=A0</span><span style=3D"font-family:monospace;fon=
t-size:small;background-color:rgb(250,250,250);color:rgb(0,0,136)">using</s=
pan><span style=3D"font-family:monospace;font-size:small;background-color:r=
gb(250,250,250);color:rgb(0,0,0)">=C2=A0</span><span style=3D"font-family:m=
onospace;font-size:small;background-color:rgb(250,250,250);color:rgb(102,0,=
102)">MyType</span><span style=3D"font-family:monospace;font-size:small;bac=
kground-color:rgb(250,250,250);color:rgb(0,0,0)">=C2=A0</span><span style=
=3D"font-family:monospace;font-size:small;background-color:rgb(250,250,250)=
;color:rgb(102,102,0)">=3D<br></span></div><div><span style=3D"font-family:=
monospace;font-size:small;background-color:rgb(250,250,250);color:rgb(0,0,0=
)">=C2=A0 =C2=A0 std</span><span style=3D"font-family:monospace;font-size:s=
mall;background-color:rgb(250,250,250);color:rgb(102,102,0)">::</span><span=
style=3D"font-family:monospace;font-size:small;background-color:rgb(250,25=
0,250);color:rgb(0,0,0)">conditional_t</span><span style=3D"font-family:mon=
ospace;font-size:small;background-color:rgb(250,250,250);color:rgb(102,102,=
0)"><</span><span style=3D"font-family:monospace;font-size:small;backgro=
und-color:rgb(250,250,250);color:rgb(0,0,0)">i=C2=A0</span><span style=3D"c=
olor:rgb(102,102,0);font-family:monospace;font-size:small;background-color:=
rgb(250,250,250)"><</span><span style=3D"font-family:monospace;font-size=
:small;background-color:rgb(250,250,250);color:rgb(0,0,0)">=C2=A0</span><sp=
an style=3D"color:rgb(0,102,102);font-family:monospace;font-size:small;back=
ground-color:rgb(250,250,250)">1</span><span style=3D"font-family:monospace=
;font-size:small;background-color:rgb(250,250,250);color:rgb(102,102,0)">,<=
/span><span style=3D"font-family:monospace;font-size:small;background-color=
:rgb(250,250,250);color:rgb(0,0,0)">=C2=A0</span><span style=3D"font-family=
:monospace;font-size:small;background-color:rgb(250,250,250);color:rgb(102,=
0,102)">Firs<wbr>tType</span><span style=3D"font-family:monospace;font-size=
:small;background-color:rgb(250,250,250);color:rgb(102,102,0)">,</span><spa=
n style=3D"font-family:monospace;font-size:small;background-color:rgb(250,2=
50,250);color:rgb(0,0,0)"><br>=C2=A0 =C2=A0 std</span><span style=3D"font-f=
amily:monospace;font-size:small;background-color:rgb(250,250,250);color:rgb=
(102,102,0)">::</span><span style=3D"font-family:monospace;font-size:small;=
background-color:rgb(250,250,250);color:rgb(0,0,0)">conditional_t</span><fo=
nt color=3D"#008800" style=3D"font-family:monospace;font-size:small;backgro=
und-color:rgb(250,250,250)"><span style=3D"color:rgb(102,102,0)"><</span=
></font><span style=3D"color:rgb(0,102,102);font-family:monospace;font-size=
:small;background-color:rgb(250,250,250)">1</span><font color=3D"#008800" s=
tyle=3D"font-family:monospace;font-size:small;background-color:rgb(250,250,=
250)"><span style=3D"color:rgb(102,102,0)">=C2=A0<=3D=C2=A0</span><span =
style=3D"color:rgb(0,0,0)">i && i</span><span style=3D"color:rgb(0,=
0,0)">=C2=A0</span><span style=3D"color:rgb(102,102,0)"><</span><span st=
yle=3D"color:rgb(0,0,0)">=C2=A0</span><span style=3D"color:rgb(0,102,102)">=
10</span><span style=3D"color:rgb(102,102,0)">,</span><span style=3D"color:=
rgb(0,0,0)">=C2=A0</span><span style=3D"color:rgb(102,0,102)">SecondType</s=
pan><span style=3D"color:rgb(102,102,0)">,</span><span style=3D"color:rgb(0=
,0,0)"><br></span></font><span style=3D"font-family:monospace;font-size:sma=
ll;background-color:rgb(250,250,250);color:rgb(0,0,0)">=C2=A0 =C2=A0 std</s=
pan><span style=3D"font-family:monospace;font-size:small;background-color:r=
gb(250,250,250);color:rgb(102,102,0)">::</span><span style=3D"font-family:m=
onospace;font-size:small;background-color:rgb(250,250,250);color:rgb(0,0,0)=
">conditional_t</span><span style=3D"font-family:monospace;font-size:small;=
background-color:rgb(250,250,250);color:rgb(102,102,0)"><</span><span st=
yle=3D"color:rgb(0,102,102);font-family:monospace;font-size:small;backgroun=
d-color:rgb(250,250,250)">10</span><span style=3D"font-family:monospace;fon=
t-size:small;background-color:rgb(250,250,250);color:rgb(0,0,0)">=C2=A0</sp=
an><span style=3D"font-family:monospace;font-size:small;background-color:rg=
b(250,250,250);color:rgb(102,102,0)"><=3D</span><span style=3D"font-fami=
ly:monospace;font-size:small;background-color:rgb(250,250,250);color:rgb(0,=
0,0)">=C2=A0</span><span style=3D"font-family:monospace;font-size:small;bac=
kground-color:rgb(250,250,250);color:rgb(0,0,0)">i</span><span style=3D"fon=
t-family:monospace;font-size:small;background-color:rgb(250,250,250);color:=
rgb(102,102,0)">,</span><span style=3D"font-family:monospace;font-size:smal=
l;background-color:rgb(250,250,250);color:rgb(0,0,0)">=C2=A0</span><span st=
yle=3D"font-family:monospace;font-size:small;background-color:rgb(250,250,2=
50);color:rgb(102,0,102)">Th<wbr>irdType</span><span style=3D"color:rgb(102=
,102,0);font-family:monospace;font-size:small;background-color:rgb(250,250,=
250)">>>>;<br></span></div></div><div><br></div><div>However, in C=
++17 we get `if constexpr`, so personally I would just use that:</div><div>=
<a href=3D"https://wandbox.org/permlink/3EnvHel8t0jucpk2" target=3D"_blank"=
rel=3D"nofollow" onmousedown=3D"this.href=3D'https://www.google.com/ur=
l?q\x3dhttps%3A%2F%2Fwandbox.org%2Fpermlink%2F3EnvHel8t0jucpk2\x26sa\x3dD\x=
26sntz\x3d1\x26usg\x3dAFQjCNFV1VjkdM777Wby2In8wXbjaVVu0g';return true;"=
onclick=3D"this.href=3D'https://www.google.com/url?q\x3dhttps%3A%2F%2F=
wandbox.org%2Fpermlink%2F3EnvHel8t0jucpk2\x26sa\x3dD\x26sntz\x3d1\x26usg\x3=
dAFQjCNFV1VjkdM777Wby2In8wXbjaVVu0g';return true;">https://wandbox.org/=
permlink/<wbr>3EnvHel8t0jucpk2</a><br></div><div><br></div><div>template<=
;class T> struct wrap {};</div><div>template<class T> struct unwra=
pper;</div><div>template<class T> struct unwrapper<wrap<T>&g=
t; { using type =3D T; };</div><div>template<class T> using unwrap =
=3D typename unwrapper<T>::type;</div><div><br></div><div>template<=
;int i></div><div>auto helper() {</div><div>=C2=A0 =C2=A0 if constexpr(i=
=3D=3D 0) {</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 return wrap<FirstType=
>{};</div><div>=C2=A0 =C2=A0 } else if constexpr (i =3D=3D 1) {</div><di=
v>=C2=A0 =C2=A0 =C2=A0 =C2=A0 return wrap<SecondType>{};</div><div>=
=C2=A0 =C2=A0 } else if constexpr (i =3D=3D 2) {</div><div>=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 return wrap<ThirdType>{};</div><div>=C2=A0 =C2=A0 }</di=
v><div>}</div><div><br></div><div>template<int i> using MyType =3D un=
wrap<decltype(helper<i>())>;</div><div><br></div><div>I suspect=
(but do not know for sure) that this formulation will also be much much ea=
sier on the compiler's internal data structures.</div><div><br></div><d=
iv>HTH,</div><div>Arthur</div><blockquote class=3D"gmail_quote" style=3D"ma=
rgin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div =
dir=3D"ltr"><div><blockquote class=3D"gmail_quote" style=3D"margin:0;margin=
-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex">
</blockquote></div></div></blockquote></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/0d99bca4-8b24-46cf-b325-8c2a885dec65%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/0d99bca4-8b24-46cf-b325-8c2a885dec65=
%40isocpp.org</a>.<br />
------=_Part_22442_1203680396.1522232518155--
------=_Part_22441_1559524591.1522232518154--
.
Author: hamza_sood@me.com
Date: Wed, 28 Mar 2018 03:28:05 -0700 (PDT)
Raw View
------=_Part_21975_461845762.1522232885922
Content-Type: multipart/alternative;
boundary="----=_Part_21976_795017491.1522232885922"
------=_Part_21976_795017491.1522232885922
Content-Type: text/plain; charset="UTF-8"
That's a really good point, thanks for the correction!
I did a quick example implementation to make sure that everything else is
possible, and it works really well.
I've attached the code if anyone wants to try it out.
On Wednesday, March 28, 2018 at 12:13:13 AM UTC+1, Marcin Jaczewski wrote:
>
>
>
> On Tuesday, March 27, 2018 at 2:40:43 PM UTC+2, Hamza Sood wrote:
>>
>> Suppose you want to select a type based on a condition. You can do this
>> with template specialisations at the language level:
>>
>> template<bool>
>> struct MySelector;
>>
>> template<>
>> struct MySelector<false> { typedef TypeIfFalse type; };
>>
>> template<>
>> struct MySelector<true> { typedef TypeIfTrue type; };
>>
>> But that's a lot of boilerplate, so C++11 introduced std::conditional.
>>
>>
>>
>> Now instead suppose that you want to select a type based on the value of
>> (non-boolean) non-type template parameter.
>> You can either do the same specialisation trick:
>>
>> template<int>
>> struct MySelector;
>>
>> template<>
>> struct MySelector<0> { typedef FirstType type; };
>>
>> template<>
>> struct MySelector<1> { typedef SecondType type; };
>>
>> template<>
>> struct MySelector<2> { typedef ThirdType type; };
>>
>> // etc.
>> // Potentially lots of other cases here...
>>
>> which is a bit cumbersome. Or you can try to chain std::conditionals:
>>
>> template<int i>
>> using MyType = std::conditional_t<i == 0, FirstType,
>> std::conditional_t<i == 1, SecondType,
>> std::conditional_t<i
>> == 2, ThirdType, /* potentially lots more stuff here... */>>>;
>>
>> which is even worse.
>>
>>
>>
>> I propose that a meta_switch type (better name welcome) is added to
>> <type_traits>, to enable code such as:
>>
>> template<int i>
>> using MyType = std::meta_switch_t<i,
>> 0, FirstType,
>> 1, SecondType,
>> 2, ThirdType,
>> // etc.
>> >;
>>
>>
> One nitpick, AFAIK you can't have mixed values and types in variadic
> template parameters (until someone add `using...` parameters pack that
> accepts types and values), it probably should look like:
> std::meta_switch_t<i,
> std::meta_case<0, FirstType>,
> std::meta_case<1, SecondType>,
> std::meta_case<2, ThirdType>
> >;
>
>
>
--
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/15b1d379-9890-44d6-8759-be9458a4f7fe%40isocpp.org.
------=_Part_21976_795017491.1522232885922
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">That's a really good point, thanks for the correction!=
<div><br><div>I did a quick example implementation to make sure that everyt=
hing else is possible, and it works really well.</div><div>I've attache=
d the code if anyone wants to try it out.<br><br>On Wednesday, March 28, 20=
18 at 12:13:13 AM UTC+1, Marcin Jaczewski wrote:<blockquote class=3D"gmail_=
quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;pa=
dding-left: 1ex;"><div dir=3D"ltr"><br><br>On Tuesday, March 27, 2018 at 2:=
40:43 PM UTC+2, Hamza Sood wrote:<blockquote class=3D"gmail_quote" style=3D=
"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><d=
iv dir=3D"ltr">Suppose you want to select a type based on a condition. You =
can do this with template specialisations at the language level:<div><br><d=
iv><div><div style=3D"background-color:rgb(250,250,250);border:1px solid rg=
b(187,187,187);word-wrap:break-word"><code><div><font color=3D"#660066"><sp=
an style=3D"color:#008">template</span><span style=3D"color:#080"><bool&=
gt;</span><span style=3D"color:#000"><br></span><span style=3D"color:#008">=
struct</span><span style=3D"color:#000"> </span><span style=3D"color:#606">=
MySelector</span><span style=3D"color:#660">;</span><span style=3D"color:#0=
00"><br><br></span><span style=3D"color:#008">template</span><span style=3D=
"color:#660"><></span><span style=3D"color:#000"><br></span><span sty=
le=3D"color:#008">struct</span><span style=3D"color:#000"> </span><span sty=
le=3D"color:#606">MySelector</span><span style=3D"color:#080"><false>=
</span><span style=3D"color:#000"> </span><span style=3D"color:#660">{</spa=
n><span style=3D"color:#000"> </span><span style=3D"color:#008">typedef</sp=
an><span style=3D"color:#000"> </span><span style=3D"color:#606">TypeIfFals=
e</span><span style=3D"color:#000"> type</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><br></span></font><span style=3D"color:#0=
08">template</span><span style=3D"color:#660"><></span><span style=3D=
"color:#000"><br></span><span style=3D"color:#008">struct</span><span style=
=3D"color:#000"> </span><span style=3D"color:#606">MySelector</span><span s=
tyle=3D"color:#080"><true></span><span style=3D"color:#000"> </span><=
span style=3D"color:#660">{</span><span style=3D"color:#000"> </span><span =
style=3D"color:#008">typedef</span><span style=3D"color:#000"> </span><span=
style=3D"color:#606">TypeIfTrue</span><span style=3D"color:#000"> type</sp=
an><span style=3D"color:#660">;</span><span style=3D"color:#000"> </span><s=
pan style=3D"color:#660">};</span></div></code></div><div><br></div>But tha=
t's a lot of boilerplate, so C++11 introduced std::conditional.</div></=
div><div><br></div><div><br></div><div><br></div><div>Now instead suppose t=
hat you want to select a type based on the value of (non-boolean) non-type =
template parameter.</div><div>You can either do the same specialisation tri=
ck:</div><div><br></div><div><div style=3D"background-color:rgb(250,250,250=
);border:1px solid rgb(187,187,187);word-wrap:break-word"><code><div><span =
style=3D"color:#008">template</span><span style=3D"color:#080"><int><=
/span><span style=3D"color:#000"><br></span><span style=3D"color:#008">stru=
ct</span><span style=3D"color:#000"> </span><span style=3D"color:#606">MySe=
lector</span><span style=3D"color:rgb(102,102,0);font-family:Arial,Helvetic=
a,sans-serif"><span style=3D"color:#660">;</span><span style=3D"color:#000"=
><br></span></span><span style=3D"color:#000"><br></span><span style=3D"col=
or:#008">template</span><span style=3D"color:#660"><></span><span sty=
le=3D"color:#000"><br></span><span style=3D"color:#008">struct</span><span =
style=3D"color:#000"> </span><span style=3D"color:#606">MySelector</span><s=
pan style=3D"color:#660"><</span><span style=3D"color:#066">0</span><spa=
n style=3D"color:#660">></span><span style=3D"color:#000"> </span><span =
style=3D"color:#660">{</span><span style=3D"color:#000"> </span><span style=
=3D"color:#008">typedef</span><span style=3D"color:#000"> </span><span styl=
e=3D"color:#606">FirstType</span><span style=3D"color:#000"> type</span><sp=
an style=3D"color:#660">;</span><span style=3D"color:#000"> </span><span st=
yle=3D"color:#660">};</span><span style=3D"color:#000"><br><br></span><span=
style=3D"color:#008">template</span><span style=3D"color:#660"><></s=
pan><span style=3D"color:#000"><br></span><span style=3D"color:#008">struct=
</span><span style=3D"color:#000"> </span><span style=3D"color:#606">MySele=
ctor</span><span style=3D"color:#660"><</span><span style=3D"color:#066"=
>1</span><span style=3D"color:#660">></span><span style=3D"color:#000"> =
</span><span style=3D"color:#660">{</span><span style=3D"color:#000"> </spa=
n><span style=3D"color:#008">typedef</span><span style=3D"color:#000"> </sp=
an><span style=3D"color:#606">SecondType</span><span style=3D"color:#000"> =
type</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><b=
r></span><span style=3D"color:#008">template</span><span style=3D"color:#66=
0"><></span><span style=3D"color:#000"><br></span><span style=3D"colo=
r:#008">struct</span><span style=3D"color:#000"> </span><span style=3D"colo=
r:#606">MySelector</span><span style=3D"color:#660"><</span><font color=
=3D"#006666"><span style=3D"color:#066">2</span></font><span style=3D"color=
:#660">></span><span style=3D"color:#000"> </span><span style=3D"color:#=
660">{</span><span style=3D"color:#000"> </span><span style=3D"color:#008">=
typedef</span><span style=3D"color:#000"> </span><span style=3D"color:#606"=
>ThirdType</span><span style=3D"color:#000"> type</span><span style=3D"colo=
r:#660">;</span><span style=3D"color:#000"> </span><span style=3D"color:#66=
0">};</span><span style=3D"color:#000"><br><br></span><span style=3D"color:=
#800">// etc.</span><span style=3D"color:#000"><br></span><span style=3D"co=
lor:#800">// Potentially lots of other cases here...</span></div></code></d=
iv><div><br></div>which is a bit cumbersome. Or you can try to chain std::c=
onditionals:</div><div><br></div><div><div style=3D"background-color:rgb(25=
0,250,250);border:1px solid rgb(187,187,187);word-wrap:break-word"><code><d=
iv><font><span style=3D"color:#008">template</span><span style=3D"color:#66=
0"><</span><span style=3D"color:#008">int</span><span style=3D"color:#00=
0"> i</span><span style=3D"color:#660">></span><span style=3D"color:#000=
"><br></span><span style=3D"color:#008">using</span><span style=3D"color:#0=
00"> </span><span style=3D"color:#606">MyType</span><span style=3D"color:#0=
00"> </span><span style=3D"color:#660">=3D</span><span style=3D"color:#000"=
> std</span><span style=3D"color:#660">::</span><span style=3D"color:#000">=
conditional_t</span><span style=3D"color:#660"><</span><span style=3D"co=
lor:#000">i </span><span style=3D"color:#660">=3D=3D</span><span style=3D"c=
olor:#000"> </span><span style=3D"color:#066">0</span><span style=3D"color:=
#660">,</span><span style=3D"color:#000"> </span><span style=3D"color:#606"=
>FirstType</span><span style=3D"color:#660">,</span><span style=3D"color:#0=
00"><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 std</span><span style=
=3D"color:#660">::</span><span style=3D"color:#000">conditional_t</span><fo=
nt color=3D"#008800"><span style=3D"color:#660"><</span><span><span styl=
e=3D"color:#000">i</span></span><span style=3D"color:#000"> </span><span st=
yle=3D"color:#660">=3D=3D</span><span style=3D"color:#000"> </span><span st=
yle=3D"color:#066">1</span><span style=3D"color:#660">,</span><span style=
=3D"color:#000"> </span><span style=3D"color:#606">SecondType</span><span s=
tyle=3D"color:#660">,</span><span style=3D"color:#000"><br></span></font><s=
pan style=3D"color:#000">=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 =C2=A0 =C2=A0 =C2=A0std</span=
><span style=3D"color:#660">::</span><span style=3D"color:#000">conditional=
_t</span><span style=3D"color:#660"><</span><span style=3D"color:#000">i=
</span><span style=3D"color:#660">=3D=3D</span><span style=3D"color:#000">=
</span><span style=3D"color:#066">2</span><span style=3D"color:#660">,</sp=
an><span style=3D"color:#000"> </span><span style=3D"color:#606">ThirdType<=
/span><span style=3D"color:#660">,</span><span style=3D"color:#000"> </span=
><span style=3D"color:#800">/* potentially lots more stuff here... */</span=
><span style=3D"color:#660">>>>;</span></font></div></code></div><=
div><br></div>which is even worse.</div><div><br></div><div><br></div><div>=
<br></div><div>I propose that a meta_switch type (better name welcome) is a=
dded to <type_traits>, to enable code such as:</div><div><br></div><d=
iv><div style=3D"background-color:rgb(250,250,250);border:1px solid rgb(187=
,187,187);word-wrap:break-word"><code><div><font><span style=3D"color:#008"=
>template</span><span style=3D"color:#660"><</span><span style=3D"color:=
#008">int</span><font color=3D"#000000"><span style=3D"color:#000"> i</span=
><span style=3D"color:#660">></span><span style=3D"color:#000"><br></spa=
n><span style=3D"color:#008">using</span><span style=3D"color:#000"> </span=
><span style=3D"color:#606">MyType</span><span style=3D"color:#000"> </span=
><span style=3D"color:#660">=3D</span><span style=3D"color:#000"> std</span=
><span style=3D"color:#660">::</span><span style=3D"color:#000">meta_switch=
_t</span><span style=3D"color:#660"><</span><span><span style=3D"color:#=
000">i</span><span style=3D"color:#660">,</span><span style=3D"color:#000">=
<br>=C2=A0 =C2=A0 </span><span style=3D"color:#066">0</span><span style=3D"=
color:#660">,</span><span style=3D"color:#000"> </span><span style=3D"color=
:#606">FirstType</span><span style=3D"color:#660">,</span><span style=3D"co=
lor:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#066">1</span><span=
style=3D"color:#660">,</span><span style=3D"color:#000"> </span><span styl=
e=3D"color:#606">SecondType</span><span style=3D"color:#660">,</span><span =
style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#066">2<=
/span><span style=3D"color:#660">,</span><span style=3D"color:#000"> </span=
><span style=3D"color:#606">ThirdType</span><span style=3D"color:#660">,</s=
pan><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"colo=
r:#800">// etc.</span><span style=3D"color:#000"><br></span><span style=3D"=
color:#660">>;</span></span></font></font></div></code></div></div></div=
><br></div></blockquote><div><br>One nitpick, AFAIK you can't have mixe=
d values and types in variadic template parameters (until someone add `usin=
g...` parameters pack that accepts types and values), it probably should lo=
ok like:<br><div style=3D"background-color:rgb(250,250,250);border-color:rg=
b(187,187,187);border-style:solid;border-width:1px"><code><div><span style=
=3D"color:#000">std</span><span style=3D"color:#660">::</span><span style=
=3D"color:#000">meta_switch_t</span><span style=3D"color:#660"><</span><=
span style=3D"color:#000">i</span><span style=3D"color:#660">,</span><code>=
<span style=3D"color:#000"><br>=C2=A0 std</span><span style=3D"color:#660">=
::</span><span style=3D"color:#000">meta_case</span><span style=3D"color:#6=
60"><</span><span style=3D"color:#066">0</span><span style=3D"color:#660=
">,</span><span style=3D"color:#000"> </span><span style=3D"color:#606">Fir=
stType</span><span style=3D"color:#660">></span><span style=3D"color:#00=
0"></span></code><code><span style=3D"color:#000">,<br>=C2=A0 std</span><sp=
an style=3D"color:#660">::</span><span style=3D"color:#000">meta_case</span=
><span style=3D"color:#660"><</span><span style=3D"color:#066">1</span><=
span style=3D"color:#660">,</span><span style=3D"color:#000"> </span><span =
style=3D"color:#606">SecondType</span><span style=3D"color:#660">></span=
><span style=3D"color:#000"></span></code><code><span style=3D"color:#000">=
,<br>=C2=A0 std</span><span style=3D"color:#660">::</span><span style=3D"co=
lor:#000">meta_case</span><span style=3D"color:#660"><</span><span style=
=3D"color:#066">2</span><span style=3D"color:#660">,</span><span style=3D"c=
olor:#000"> </span><span style=3D"color:#606">ThirdType</span><span style=
=3D"color:#660">></span><span style=3D"color:#000"></span></code><span s=
tyle=3D"color:#000"><br></span><span style=3D"color:#660">>;</span><span=
style=3D"color:#000"><br></span></div></code></div><br><br></div></div></b=
lockquote></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/15b1d379-9890-44d6-8759-be9458a4f7fe%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/15b1d379-9890-44d6-8759-be9458a4f7fe=
%40isocpp.org</a>.<br />
------=_Part_21976_795017491.1522232885922--
------=_Part_21975_461845762.1522232885922
Content-Type: text/x-chdr; charset=US-ASCII; name=meta_switch.h
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename=meta_switch.h
X-Attachment-Id: aa1ea8ea-a83f-4033-a6ec-ea654b040d18
Content-ID: <aa1ea8ea-a83f-4033-a6ec-ea654b040d18>
#include <type_traits>
namespace detail {
template<typename T>
struct indirection {
using type = T;
};
}
template<auto, typename...>
struct meta_switch;
template<auto Val, typename T>
struct meta_case { };
template<typename T>
struct meta_default { };
template<auto Val>
struct meta_switch<Val> {
// Base case 1:
// All given cases are exhausted.
static_assert(sizeof(Val) == -1,
"meta_switch evaluation ended without finding a match; "
"consider adding a meta_default case");
};
template<auto Val, typename T>
struct meta_switch<Val, meta_default<T>> {
// Base case 2:
// Reached the end and found a default case. Just use the given type.
using type = T;
};
template<auto Val, typename T, typename... Rest>
struct meta_switch<Val, meta_default<T>, Rest...> {
// Require meta_default to be the last case because it makes it much easier
// to implement (we just need to pick off the default type at the end).
// This is technically redundant because without it there isn't a
// specialisaton that matches a meta_default at anywhere but the end, but
// this allows for nicer diagnostics.
static_assert(sizeof(Val) == -1,
"meta_default must be the last case in a meta_switch");
};
template<auto Val, auto CaseVal, typename CaseT, typename... Rest>
struct meta_switch<Val, meta_case<CaseVal, CaseT>, Rest...> {
// The extra indirection is used to delay evaluation of the other cases
// until they're actually needed.
using type = typename std::conditional_t<Val == CaseVal,
detail::indirection<CaseT>,
meta_switch<Val, Rest...>
>::type;
};
------=_Part_21975_461845762.1522232885922--
.
Author: Edward Catmur <ed@catmur.co.uk>
Date: Wed, 28 Mar 2018 03:28:50 -0700 (PDT)
Raw View
------=_Part_8917_1236612521.1522232930983
Content-Type: multipart/alternative;
boundary="----=_Part_8918_209860562.1522232930983"
------=_Part_8918_209860562.1522232930983
Content-Type: text/plain; charset="UTF-8"
On Tuesday, 27 March 2018 14:57:25 UTC+1, hamza...@me.com wrote:
>
> From what I can tell, the links you've posted seem to be solving a
> different problem. Accessing a parameter pack by index admittedly solves
> the example I posted, however I'm proposing a more generic switch where the
> cases aren't necessarily integers in the sequence 0,1,2,...
>
Boost.MPL has a map (meta)type:
template<int i>
using MyType = typename boost::mpl::at_c
< boost::mpl::map
< boost::mpl::pair<boost::mpl::integral_c<0>, FirstType>
, boost::mpl::pair<boost::mpl::integral_c<1>, SecondType>
, boost::mpl::pair<boost::mpl::integral_c<2>, ThirdType>
// etc.
>
, long(i)
>::type;
I would recommend using hana over MPL though:
template<int i>
using MyType = typename decltype(+hana::make_map(
hana::make_pair(hana::int_c<0>, hana::type_c<FirstType>),
hana::make_pair(hana::int_c<1>, hana::type_c<SecondType>),
hana::make_pair(hana::int_c<2>, hana::type_c<ThirdType>)
)[hana::int_c<i>])::type;
> E.g. they could be arbitrary enum constants:
> template<MyEnum x>
> using MyType = std::meta_switch_t<x,
> MyEnum_SomeValue, int,
> MyEnum_AnotherThing, float,
> // etc
> >;
> where the enum values could be 900 and 28712.
>
> Alternatively you could use it to match negative numbers:
> template<int i>
> using MyType = std::meta_switch_t<I,
> -1, FirstType,
> -2, SecondType,
> // etc.
> >;
>
> I don't think that either of those examples are possible with the
> solutions that you posted.
>
>
> On Tuesday, March 27, 2018 at 2:44:17 PM UTC+1, Larry Evans wrote:
>>
>> On 03/27/2018 07:40 AM, Hamza Sood wrote:
>> > Suppose you want to select a type based on a condition. You can do this
>> > with template specialisations at the language level:
>> [snip]
>>
>> > I propose that a meta_switch type (better name welcome) is added to
>> > <type_traits>, to enable code such as:
>> >
>> > template<int i>
>> > using MyType = std::meta_switch_t<i,
>> > 0, FirstType,
>> > 1, SecondType,
>> > 2, ThirdType,
>> > // etc.
>> >> ;
>> >
>> There's already boost::mpl::at_c:
>>
>> http://www.boost.org/doc/libs/1_61_0/libs/mpl/doc/refmanual/at-c.html
>>
>> which is a little different:
>>
>> template<int i>
>> using MyType = typename boost::mpl::at_c
>> < boost::mpl::vector
>> < FirstType
>> , SecondType
>> , ThirdType
>> // etc.
>> >
>> , long(i)
>> >::type;
>>
>>
>> I also think there's another intrinsic proposal for something
>> similar, but with another syntax and using parameter packs.
>>
>> Please see:
>>
>>
>> https://groups.google.com/a/isocpp.org/forum/#!msg/std-proposals/ajLcDl8GbpA/uAVgEWI5CAAJ
>>
>> -regards,
>> Larry
>>
>>
--
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/b67635dc-056a-4ebb-b2d4-09bdf356859c%40isocpp.org.
------=_Part_8918_209860562.1522232930983
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Tuesday, 27 March 2018 14:57:25 UTC+1, hamza...@me.com =
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">From w=
hat I can tell, the links you've posted seem to be solving a different =
problem. Accessing a parameter pack by index admittedly solves the example =
I posted, however I'm proposing a more generic switch where the cases a=
ren't necessarily integers in the sequence 0,1,2,...</div></blockquote>=
<div><br></div><div>Boost.MPL has a map (meta)type:</div><div><br></div><di=
v class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); bord=
er-color: rgb(187, 187, 187); border-style: solid; border-width: 1px; word-=
wrap: break-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint=
"><span style=3D"color: #008;" class=3D"styled-by-prettify">template</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify"><</span><span =
style=3D"color: #008;" class=3D"styled-by-prettify">int</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> i</span><span style=3D"colo=
r: #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;" c=
lass=3D"styled-by-prettify">using</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=3D"style=
d-by-prettify">MyType</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span style=3D"color: #008;" class=3D"styled-by-prettify">typename</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> boost</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">mpl</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify">at_c <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"> boost</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">::</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify">mpl</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify">map<br>=C2=A0 =C2=A0 =C2=A0</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify"><</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> boost</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify">mpl</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">pai=
r</span><span style=3D"color: #660;" class=3D"styled-by-prettify"><</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify">boost</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">mpl</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify">integral_c</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify"><</span><span style=3D"color: #066;" cla=
ss=3D"styled-by-prettify">0</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">>,</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> </span><span style=3D"color: #606;" class=3D"styled-by-prettif=
y">FirstType</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</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> boost</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify">mpl</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify">pair</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify"><</span><span style=3D"color:=
#000;" class=3D"styled-by-prettify">boost</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">mpl</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify">integral_c</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify"><</span><span style=3D"color: #066;" class=3D"styled-by-prettif=
y">1</span><span style=3D"color: #660;" class=3D"styled-by-prettify">>,<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an style=3D"color: #606;" class=3D"styled-by-prettify">SecondType</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">></span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> boost</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify">mpl</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify">pair</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify"><</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify">boost</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
">mpl</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify">integral_c</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify"><</span><s=
pan style=3D"color: #066;" class=3D"styled-by-prettify">2</span><span style=
=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: #60=
6;" class=3D"styled-by-prettify">ThirdType</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">></span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0</span><span style=3D"col=
or: #800;" class=3D"styled-by-prettify">// etc. </span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =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</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">long</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">i</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">)</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> <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">type</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></div></code></div><div>=C2=A0<br></div><div>I would recommend using han=
a over MPL though:</div><div><br></div><div><div class=3D"prettyprint" styl=
e=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187)=
; border-style: solid; border-width: 1px; word-wrap: break-word;"><code cla=
ss=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color: #008=
;" class=3D"styled-by-prettify">template</span><span style=3D"color: #660;"=
class=3D"styled-by-prettify"><</span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">int</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> i</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">></span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">usi=
ng</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span>=
<span style=3D"color: #606;" class=3D"styled-by-prettify">MyType</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;=
" class=3D"styled-by-prettify">typename</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"=
styled-by-prettify">decltype</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">(+</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify">hana</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">make=
_map</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=
=A0 =C2=A0 =C2=A0 hana</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy">make_pair</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">hana</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify">int_c</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify"><</span><span style=3D=
"color: #066;" class=3D"styled-by-prettify">0</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">>,</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify"> hana</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify">type_c</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify"><</span><span style=3D"color: rgb(102, 0, 102);"><span styl=
e=3D"color: #606;" class=3D"styled-by-prettify">FirstType</span></span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">>),</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =
=C2=A0 hana</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">make_pa=
ir</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify">hana</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify">int_c</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify"><</span><span style=3D"color: #06=
6;" class=3D"styled-by-prettify">1</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">>,</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> hana</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify">type_c</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
"><</span><span style=3D"color: rgb(102, 0, 102);"><span style=3D"color:=
#606;" class=3D"styled-by-prettify">SecondType</span></span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">>),</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 han=
a</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify">make_pair</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify">hana</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify">int_c</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify"><</span><span style=3D"color: #066;" class=
=3D"styled-by-prettify">2</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">>,</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> hana</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">typ=
e_c</span><span style=3D"color: #660;" class=3D"styled-by-prettify"><</s=
pan><span style=3D"color: rgb(102, 0, 102);"><span style=3D"color: #606;" c=
lass=3D"styled-by-prettify">ThirdType</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">></span></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 </span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">)[</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify">hana</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify">int_c</span><span style=3D"color: #080;" class=3D"styled-by-prettify">=
<i></span><span style=3D"color: #660;" class=3D"styled-by-prettify">]=
)::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">type</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span></div=
></code></div><div><br></div></div><div><br></div><div><br></div><blockquot=
e 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><div>E.g=
.. they could be arbitrary enum constants:</div><div><div style=3D"backgroun=
d-color:rgb(250,250,250);border:1px solid rgb(187,187,187);word-wrap:break-=
word"><code><div><span style=3D"color:#008">template</span><span style=3D"c=
olor:#660"><</span><span style=3D"color:#606">MyEnum</span><span style=
=3D"color:#000"> x</span><span style=3D"color:#660">></span><span style=
=3D"color:#000"><br></span><span style=3D"color:#008">using</span><span sty=
le=3D"color:#000"> </span><span style=3D"color:#606">MyType</span><span sty=
le=3D"color:#000"> </span><span style=3D"color:#660">=3D</span><font color=
=3D"#000000"><span style=3D"color:#000"> std</span><span style=3D"color:#66=
0">::</span><span style=3D"color:#000">meta_switch_t</span><span style=3D"c=
olor:#660"><</span><span style=3D"color:#000">x</span><span style=3D"col=
or:#660">,</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span =
style=3D"color:#606">MyEnum_SomeValue</span><span style=3D"color:#660">,</s=
pan><span style=3D"color:#000"> </span><span style=3D"color:#008">int</span=
><span style=3D"color:#660">,</span><span style=3D"color:#000"><br>=C2=A0 =
=C2=A0 </span><span style=3D"color:#606">MyEnum_AnotherThing</span><span st=
yle=3D"color:#660">,</span><span style=3D"color:#000"> </span><span style=
=3D"color:#008">float</span><span style=3D"color:#660">,</span><span style=
=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#800">// etc<=
/span><span style=3D"color:#000"><br></span><span style=3D"color:#660">>=
;</span></font></div></code></div>where the enum values could be 900 and 28=
712.</div><div><br></div><div>Alternatively you could use it to match negat=
ive numbers:</div><div><div style=3D"background-color:rgb(250,250,250);bord=
er:1px solid rgb(187,187,187);word-wrap:break-word"><code><div><font><span =
style=3D"color:#008">template</span><span style=3D"color:#660"><</span><=
span style=3D"color:#008">int</span><span style=3D"color:#000"> i</span><sp=
an style=3D"color:#660">></span><span style=3D"color:#000"><br></span><s=
pan style=3D"color:#008">using</span><span style=3D"color:#000"> </span><sp=
an style=3D"color:#606">MyType</span><span style=3D"color:#000"> </span><sp=
an style=3D"color:#660">=3D</span><span style=3D"color:#000"> std</span><sp=
an style=3D"color:#660">::</span><span style=3D"color:#000">meta_switch_t</=
span><span><span style=3D"color:#660"><</span><span style=3D"color:#000"=
>I</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:#066">1</span><span style=3D"color:#660">,</span><font color=3D"#660066">=
<span style=3D"color:#000"> </span><span style=3D"color:#606">FirstType</sp=
an><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:#066=
">2</span><span style=3D"color:#660">,</span><span style=3D"color:#000"> </=
span><span style=3D"color:#606">SecondType</span><span style=3D"color:#660"=
>,</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D=
"color:#800">// etc.</span><span style=3D"color:#000"><br></span><span styl=
e=3D"color:#660">>;</span></font></span></font></div></code></div><div><=
br></div>I don't think that either of those examples are possible with =
the solutions that you posted.<br><br></div><div><br>On Tuesday, March 27, =
2018 at 2:44:17 PM UTC+1, Larry Evans wrote:<blockquote class=3D"gmail_quot=
e" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-l=
eft:1ex">On 03/27/2018 07:40 AM, Hamza Sood wrote:
<br>> Suppose you want to select a type based on a condition. You can do=
this
<br>> with template specialisations at the language level:
<br>[snip]
<br>
<br>> I propose that a meta_switch type (better name welcome) is added t=
o
<br>> <type_traits>, to enable code such as:
<br>>=20
<br>> template<int i>
<br>> using MyType =3D std::meta_switch_t<i,
<br>> =C2=A0 =C2=A0 =C2=A00, FirstType,
<br>> =C2=A0 =C2=A0 =C2=A01, SecondType,
<br>> =C2=A0 =C2=A0 =C2=A02, ThirdType,
<br>> =C2=A0 =C2=A0 =C2=A0// etc.
<br>>> ;
<br>>=20
<br>There's already boost::mpl::at_c:
<br>
<br><a href=3D"http://www.boost.org/doc/libs/1_61_0/libs/mpl/doc/refmanual/=
at-c.html" rel=3D"nofollow" target=3D"_blank" onmousedown=3D"this.href=3D&#=
39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.boost.org%2Fdoc%2Flibs%2=
F1_61_0%2Flibs%2Fmpl%2Fdoc%2Frefmanual%2Fat-c.html\x26sa\x3dD\x26sntz\x3d1\=
x26usg\x3dAFQjCNF6J-iP4pPJ79g2VuZnI_Od0nAm1w';return true;" onclick=3D"=
this.href=3D'http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.boost.org%=
2Fdoc%2Flibs%2F1_61_0%2Flibs%2Fmpl%2Fdoc%2Frefmanual%2Fat-c.html\x26sa\x3dD=
\x26sntz\x3d1\x26usg\x3dAFQjCNF6J-iP4pPJ79g2VuZnI_Od0nAm1w';return true=
;">http://www.boost.org/doc/libs/<wbr>1_61_0/libs/mpl/doc/refmanual/<wbr>at=
-c.html</a>
<br>
<br>which is a little different:
<br>
<br>template<int i>
<br>using MyType =3D typename boost::mpl::at_c
<br>=C2=A0 =C2=A0< boost::mpl::vector
<br>=C2=A0 =C2=A0 =C2=A0< FirstType
<br>=C2=A0 =C2=A0 =C2=A0, SecondType
<br>=C2=A0 =C2=A0 =C2=A0, ThirdType
<br>=C2=A0 =C2=A0 =C2=A0// etc.
<br>=C2=A0 =C2=A0 =C2=A0>
<br>=C2=A0 =C2=A0, long(i)
<br>=C2=A0 =C2=A0>::type;
<br>
<br>
<br>I also think there's another intrinsic proposal for something
<br>similar, but with another syntax and using parameter packs.
<br>
<br>Please see:
<br>
<br><a href=3D"https://groups.google.com/a/isocpp.org/forum/#!msg/std-propo=
sals/ajLcDl8GbpA/uAVgEWI5CAAJ" rel=3D"nofollow" target=3D"_blank" onmousedo=
wn=3D"this.href=3D'https://groups.google.com/a/isocpp.org/forum/#!msg/s=
td-proposals/ajLcDl8GbpA/uAVgEWI5CAAJ';return true;" onclick=3D"this.hr=
ef=3D'https://groups.google.com/a/isocpp.org/forum/#!msg/std-proposals/=
ajLcDl8GbpA/uAVgEWI5CAAJ';return true;">https://groups.google.com/a/<wb=
r>isocpp.org/forum/#!msg/std-<wbr>proposals/ajLcDl8GbpA/<wbr>uAVgEWI5CAAJ</=
a>
<br>
<br>-regards,
<br>Larry
<br>
<br></blockquote></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/b67635dc-056a-4ebb-b2d4-09bdf356859c%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/b67635dc-056a-4ebb-b2d4-09bdf356859c=
%40isocpp.org</a>.<br />
------=_Part_8918_209860562.1522232930983--
------=_Part_8917_1236612521.1522232930983--
.
Author: Bjorn Reese <breese@mail1.stofanet.dk>
Date: Wed, 28 Mar 2018 13:28:54 +0200
Raw View
On 03/28/18 12:28, Edward Catmur wrote:
> Boost.MPL has a map (meta)type:
> I would recommend using hana over MPL though:
Or in Boost.Mp11:
|
template <int i>
using MyType = mp_map_find
<std::tuple
<std::pair<mp_int<1>, FirstType>,
std::pair<mp_int<2>, SecondType>,
std::pair<mp_int<3>, ThirdType>
>,
mp_int<i>
>;
|
Notice that it can operate on std::tuple and std::pair.
--
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/f9179222-b58b-9204-3b01-15be9cc9a7e1%40mail1.stofanet.dk.
.
Author: hamza_sood@me.com
Date: Wed, 28 Mar 2018 04:53:27 -0700 (PDT)
Raw View
------=_Part_8558_1955698979.1522238007629
Content-Type: multipart/alternative;
boundary="----=_Part_8559_1919497353.1522238007629"
------=_Part_8559_1919497353.1522238007629
Content-Type: text/plain; charset="UTF-8"
Does the fact that it's possible in Boost have any effect on suitability
for the standard? Besides, it's probably simpler to just chain a few
std::conditionals than to add a dependency on Boost.
On Wednesday, March 28, 2018 at 11:28:51 AM UTC+1, Edward Catmur wrote:
>
> On Tuesday, 27 March 2018 14:57:25 UTC+1, hamza...@me.com wrote:
>>
>> From what I can tell, the links you've posted seem to be solving a
>> different problem. Accessing a parameter pack by index admittedly solves
>> the example I posted, however I'm proposing a more generic switch where the
>> cases aren't necessarily integers in the sequence 0,1,2,...
>>
>
> Boost.MPL has a map (meta)type:
>
> template<int i>
> using MyType = typename boost::mpl::at_c
> < boost::mpl::map
> < boost::mpl::pair<boost::mpl::integral_c<0>, FirstType>
> , boost::mpl::pair<boost::mpl::integral_c<1>, SecondType>
> , boost::mpl::pair<boost::mpl::integral_c<2>, ThirdType>
> // etc.
> >
> , long(i)
> >::type;
>
> I would recommend using hana over MPL though:
>
> template<int i>
> using MyType = typename decltype(+hana::make_map(
> hana::make_pair(hana::int_c<0>, hana::type_c<FirstType>),
> hana::make_pair(hana::int_c<1>, hana::type_c<SecondType>),
> hana::make_pair(hana::int_c<2>, hana::type_c<ThirdType>)
> )[hana::int_c<i>])::type;
>
>
>
>
>> E.g. they could be arbitrary enum constants:
>> template<MyEnum x>
>> using MyType = std::meta_switch_t<x,
>> MyEnum_SomeValue, int,
>> MyEnum_AnotherThing, float,
>> // etc
>> >;
>> where the enum values could be 900 and 28712.
>>
>> Alternatively you could use it to match negative numbers:
>> template<int i>
>> using MyType = std::meta_switch_t<I,
>> -1, FirstType,
>> -2, SecondType,
>> // etc.
>> >;
>>
>> I don't think that either of those examples are possible with the
>> solutions that you posted.
>>
>>
>> On Tuesday, March 27, 2018 at 2:44:17 PM UTC+1, Larry Evans wrote:
>>>
>>> On 03/27/2018 07:40 AM, Hamza Sood wrote:
>>> > Suppose you want to select a type based on a condition. You can do
>>> this
>>> > with template specialisations at the language level:
>>> [snip]
>>>
>>> > I propose that a meta_switch type (better name welcome) is added to
>>> > <type_traits>, to enable code such as:
>>> >
>>> > template<int i>
>>> > using MyType = std::meta_switch_t<i,
>>> > 0, FirstType,
>>> > 1, SecondType,
>>> > 2, ThirdType,
>>> > // etc.
>>> >> ;
>>> >
>>> There's already boost::mpl::at_c:
>>>
>>> http://www.boost.org/doc/libs/1_61_0/libs/mpl/doc/refmanual/at-c.html
>>>
>>> which is a little different:
>>>
>>> template<int i>
>>> using MyType = typename boost::mpl::at_c
>>> < boost::mpl::vector
>>> < FirstType
>>> , SecondType
>>> , ThirdType
>>> // etc.
>>> >
>>> , long(i)
>>> >::type;
>>>
>>>
>>> I also think there's another intrinsic proposal for something
>>> similar, but with another syntax and using parameter packs.
>>>
>>> Please see:
>>>
>>>
>>> https://groups.google.com/a/isocpp.org/forum/#!msg/std-proposals/ajLcDl8GbpA/uAVgEWI5CAAJ
>>>
>>> -regards,
>>> Larry
>>>
>>>
--
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/25c7472e-44f0-4f04-bab7-95eadc571e69%40isocpp.org.
------=_Part_8559_1919497353.1522238007629
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Does the fact that it's possible in Boost have any eff=
ect on suitability for the standard? Besides, it's probably simpler to =
just chain a few std::conditionals than to add a dependency on Boost.<div><=
br>On Wednesday, March 28, 2018 at 11:28:51 AM UTC+1, Edward Catmur wrote:<=
blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;bord=
er-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">On Tuesday, 27=
March 2018 14:57:25 UTC+1, <a>hamza...@me.com</a> 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">From what I can tell, the links you=
've posted seem to be solving a different problem. Accessing a paramete=
r pack by index admittedly solves the example I posted, however I'm pro=
posing a more generic switch where the cases aren't necessarily integer=
s in the sequence 0,1,2,...</div></blockquote><div><br></div><div>Boost.MPL=
has a map (meta)type:</div><div><br></div><div style=3D"background-color:r=
gb(250,250,250);border-color:rgb(187,187,187);border-style:solid;border-wid=
th:1px;word-wrap:break-word"><code><div><span style=3D"color:#008">template=
</span><span style=3D"color:#660"><</span><span style=3D"color:#008">int=
</span><span style=3D"color:#000"> i</span><span style=3D"color:#660">><=
/span><span style=3D"color:#000"> <br></span><span style=3D"color:#008">usi=
ng</span><span style=3D"color:#000"> </span><span style=3D"color:#606">MyTy=
pe</span><span style=3D"color:#000"> </span><span style=3D"color:#660">=3D<=
/span><span style=3D"color:#000"> </span><span style=3D"color:#008">typenam=
e</span><span style=3D"color:#000"> boost</span><span style=3D"color:#660">=
::</span><span style=3D"color:#000">mpl</span><span style=3D"color:#660">::=
</span><span style=3D"color:#000">at_c <br>=C2=A0 =C2=A0</span><span style=
=3D"color:#660"><</span><span style=3D"color:#000"> boost</span><span st=
yle=3D"color:#660">::</span><span style=3D"color:#000">mpl</span><span styl=
e=3D"color:#660">::</span><span style=3D"color:#000">map<br>=C2=A0 =C2=A0 =
=C2=A0</span><span style=3D"color:#660"><</span><span style=3D"color:#00=
0"> boost</span><span style=3D"color:#660">::</span><span style=3D"color:#0=
00">mpl</span><span style=3D"color:#660">::</span><span style=3D"color:#000=
">pair</span><span style=3D"color:#660"><</span><span style=3D"color:#00=
0">boost</span><span style=3D"color:#660">::</span><span style=3D"color:#00=
0">mpl</span><span style=3D"color:#660">::</span><span style=3D"color:#000"=
>i<wbr>ntegral_c</span><span style=3D"color:#660"><</span><span style=3D=
"color:#066">0</span><span style=3D"color:#660">>,</span><span style=3D"=
color:#000"> </span><span style=3D"color:#606">FirstType</span><span style=
=3D"color:#660">></span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=
=A0</span><span style=3D"color:#660">,</span><span style=3D"color:#000"> bo=
ost</span><span style=3D"color:#660">::</span><span style=3D"color:#000">mp=
l</span><span style=3D"color:#660">::</span><span style=3D"color:#000">pair=
</span><span style=3D"color:#660"><</span><span style=3D"color:#000">boo=
st</span><span style=3D"color:#660">::</span><span style=3D"color:#000">mpl=
</span><span style=3D"color:#660">::</span><span style=3D"color:#000">i<wbr=
>ntegral_c</span><span style=3D"color:#660"><</span><span style=3D"color=
:#066">1</span><span style=3D"color:#660">>,</span><span style=3D"color:=
#000"> </span><span style=3D"color:#606">SecondType</span><span style=3D"co=
lor:#660">></span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0</s=
pan><span style=3D"color:#660">,</span><span style=3D"color:#000"> boost</s=
pan><span style=3D"color:#660">::</span><span style=3D"color:#000">mpl</spa=
n><span style=3D"color:#660">::</span><span style=3D"color:#000">pair</span=
><span style=3D"color:#660"><</span><span style=3D"color:#000">boost</sp=
an><span style=3D"color:#660">::</span><span style=3D"color:#000">mpl</span=
><span style=3D"color:#660">::</span><span style=3D"color:#000">i<wbr>ntegr=
al_c</span><span style=3D"color:#660"><</span><span style=3D"color:#066"=
>2</span><span style=3D"color:#660">>,</span><span style=3D"color:#000">=
</span><span style=3D"color:#606">ThirdType</span><span style=3D"color:#66=
0">></span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0</span><sp=
an style=3D"color:#800">// etc. </span><span style=3D"color:#000"><br>=C2=
=A0 =C2=A0 =C2=A0</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">long</span><=
span style=3D"color:#660">(</span><span style=3D"color:#000">i</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">ty=
pe</span><span style=3D"color:#660">;</span><span style=3D"color:#000"> </s=
pan></div></code></div><div>=C2=A0<br></div><div>I would recommend using ha=
na over MPL though:</div><div><br></div><div><div style=3D"background-color=
:rgb(250,250,250);border-color:rgb(187,187,187);border-style:solid;border-w=
idth:1px;word-wrap:break-word"><code><div><span style=3D"color:#008">templa=
te</span><span style=3D"color:#660"><</span><span style=3D"color:#008">i=
nt</span><span style=3D"color:#000"> i</span><span style=3D"color:#660">>=
;</span><span style=3D"color:#000"><br></span><span style=3D"color:#008">us=
ing</span><span style=3D"color:#000"> </span><span style=3D"color:#606">MyT=
ype</span><span style=3D"color:#000"> </span><span style=3D"color:#660">=3D=
</span><span style=3D"color:#000"> </span><span style=3D"color:#008">typena=
me</span><span style=3D"color:#000"> </span><span style=3D"color:#008">decl=
type</span><span style=3D"color:#660">(+</span><span style=3D"color:#000">h=
ana</span><span style=3D"color:#660">::</span><span style=3D"color:#000">ma=
ke_map</span><span style=3D"color:#660">(</span><span style=3D"color:#000">=
<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 hana</span><span style=3D"color:#660">::</s=
pan><span style=3D"color:#000">make_pair</span><span style=3D"color:#660">(=
</span><span style=3D"color:#000">hana</span><span style=3D"color:#660">::<=
/span><span style=3D"color:#000">int_c</span><span style=3D"color:#660"><=
;</span><span style=3D"color:#066">0</span><span style=3D"color:#660">><=
wbr>,</span><span style=3D"color:#000"> hana</span><span style=3D"color:#66=
0">::</span><span style=3D"color:#000">type_c</span><span style=3D"color:#6=
60"><</span><span style=3D"color:rgb(102,0,102)"><span style=3D"color:#6=
06">FirstType</span></span><span style=3D"color:#660">>),</span><span st=
yle=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 hana</span><span style=
=3D"color:#660">::</span><span style=3D"color:#000">make_pair</span><span s=
tyle=3D"color:#660">(</span><span style=3D"color:#000">hana</span><span sty=
le=3D"color:#660">::</span><span style=3D"color:#000">int_c</span><span sty=
le=3D"color:#660"><</span><span style=3D"color:#066">1</span><span style=
=3D"color:#660">><wbr>,</span><span style=3D"color:#000"> hana</span><sp=
an style=3D"color:#660">::</span><span style=3D"color:#000">type_c</span><s=
pan style=3D"color:#660"><</span><span style=3D"color:rgb(102,0,102)"><s=
pan style=3D"color:#606">SecondType</span></span><span style=3D"color:#660"=
>>),</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 ha=
na</span><span style=3D"color:#660">::</span><span style=3D"color:#000">mak=
e_pair</span><span style=3D"color:#660">(</span><span style=3D"color:#000">=
hana</span><span style=3D"color:#660">::</span><span style=3D"color:#000">i=
nt_c</span><span style=3D"color:#660"><</span><span style=3D"color:#066"=
>2</span><span style=3D"color:#660">><wbr>,</span><span style=3D"color:#=
000"> hana</span><span style=3D"color:#660">::</span><span style=3D"color:#=
000">type_c</span><span style=3D"color:#660"><</span><span style=3D"colo=
r:rgb(102,0,102)"><span style=3D"color:#606">ThirdType</span><span style=3D=
"color:#660">></span></span><span style=3D"color:#660">)</span><span sty=
le=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#660">)[</s=
pan><span style=3D"color:#000">hana</span><span style=3D"color:#660">::</sp=
an><span style=3D"color:#000">int_c</span><span style=3D"color:#080"><i&=
gt;</span><span style=3D"color:#660">])::</span><span style=3D"color:#000">=
type</span><span style=3D"color:#660">;</span></div></code></div><div><br><=
/div></div><div><br></div><div><br></div><blockquote class=3D"gmail_quote" =
style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left=
:1ex"><div dir=3D"ltr"><div><br></div><div>E.g. they could be arbitrary enu=
m constants:</div><div><div style=3D"background-color:rgb(250,250,250);bord=
er:1px solid rgb(187,187,187);word-wrap:break-word"><code><div><span style=
=3D"color:#008">template</span><span style=3D"color:#660"><</span><span =
style=3D"color:#606">MyEnum</span><span style=3D"color:#000"> x</span><span=
style=3D"color:#660">></span><span style=3D"color:#000"><br></span><spa=
n style=3D"color:#008">using</span><span style=3D"color:#000"> </span><span=
style=3D"color:#606">MyType</span><span style=3D"color:#000"> </span><span=
style=3D"color:#660">=3D</span><font color=3D"#000000"><span style=3D"colo=
r:#000"> std</span><span style=3D"color:#660">::</span><span style=3D"color=
:#000">meta_switch_t</span><span style=3D"color:#660"><</span><span styl=
e=3D"color:#000">x</span><span style=3D"color:#660">,</span><span style=3D"=
color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#606">MyEnum_Some=
Value</span><span style=3D"color:#660">,</span><span style=3D"color:#000"> =
</span><span style=3D"color:#008">int</span><span style=3D"color:#660">,</s=
pan><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"colo=
r:#606">MyEnum_AnotherThing</span><span style=3D"color:#660">,</span><span =
style=3D"color:#000"> </span><span style=3D"color:#008">float</span><span s=
tyle=3D"color:#660">,</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </=
span><span style=3D"color:#800">// etc</span><span style=3D"color:#000"><br=
></span><span style=3D"color:#660">>;</span></font></div></code></div>wh=
ere the enum values could be 900 and 28712.</div><div><br></div><div>Altern=
atively you could use it to match negative numbers:</div><div><div style=3D=
"background-color:rgb(250,250,250);border:1px solid rgb(187,187,187);word-w=
rap:break-word"><code><div><font><span style=3D"color:#008">template</span>=
<span style=3D"color:#660"><</span><span style=3D"color:#008">int</span>=
<span style=3D"color:#000"> i</span><span style=3D"color:#660">></span><=
span style=3D"color:#000"><br></span><span style=3D"color:#008">using</span=
><span style=3D"color:#000"> </span><span style=3D"color:#606">MyType</span=
><span style=3D"color:#000"> </span><span style=3D"color:#660">=3D</span><s=
pan style=3D"color:#000"> std</span><span style=3D"color:#660">::</span><sp=
an style=3D"color:#000">meta_switch_t</span><span><span style=3D"color:#660=
"><</span><span style=3D"color:#000">I</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:#066">1</span><span style=3D"color=
:#660">,</span><font color=3D"#660066"><span style=3D"color:#000"> </span><=
span style=3D"color:#606">FirstType</span><span style=3D"color:#660">,</spa=
n><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:=
#660">-</span><span style=3D"color:#066">2</span><span style=3D"color:#660"=
>,</span><span style=3D"color:#000"> </span><span style=3D"color:#606">Seco=
ndType</span><span style=3D"color:#660">,</span><span style=3D"color:#000">=
<br>=C2=A0 =C2=A0 </span><span style=3D"color:#800">// etc.</span><span sty=
le=3D"color:#000"><br></span><span style=3D"color:#660">>;</span></font>=
</span></font></div></code></div><div><br></div>I don't think that eith=
er of those examples are possible with the solutions that you posted.<br><b=
r></div><div><br>On Tuesday, March 27, 2018 at 2:44:17 PM UTC+1, Larry Evan=
s wrote:<blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8=
ex;border-left:1px #ccc solid;padding-left:1ex">On 03/27/2018 07:40 AM, Ham=
za Sood wrote:
<br>> Suppose you want to select a type based on a condition. You can do=
this
<br>> with template specialisations at the language level:
<br>[snip]
<br>
<br>> I propose that a meta_switch type (better name welcome) is added t=
o
<br>> <type_traits>, to enable code such as:
<br>>=20
<br>> template<int i>
<br>> using MyType =3D std::meta_switch_t<i,
<br>> =C2=A0 =C2=A0 =C2=A00, FirstType,
<br>> =C2=A0 =C2=A0 =C2=A01, SecondType,
<br>> =C2=A0 =C2=A0 =C2=A02, ThirdType,
<br>> =C2=A0 =C2=A0 =C2=A0// etc.
<br>>> ;
<br>>=20
<br>There's already boost::mpl::at_c:
<br>
<br><a href=3D"http://www.boost.org/doc/libs/1_61_0/libs/mpl/doc/refmanual/=
at-c.html" rel=3D"nofollow" target=3D"_blank" onmousedown=3D"this.href=3D&#=
39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.boost.org%2Fdoc%2Flibs%2=
F1_61_0%2Flibs%2Fmpl%2Fdoc%2Frefmanual%2Fat-c.html\x26sa\x3dD\x26sntz\x3d1\=
x26usg\x3dAFQjCNF6J-iP4pPJ79g2VuZnI_Od0nAm1w';return true;" onclick=3D"=
this.href=3D'http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.boost.org%=
2Fdoc%2Flibs%2F1_61_0%2Flibs%2Fmpl%2Fdoc%2Frefmanual%2Fat-c.html\x26sa\x3dD=
\x26sntz\x3d1\x26usg\x3dAFQjCNF6J-iP4pPJ79g2VuZnI_Od0nAm1w';return true=
;">http://www.boost.org/doc/libs/<wbr>1_61_0/libs/mpl/doc/refmanual/<wbr>at=
-c.html</a>
<br>
<br>which is a little different:
<br>
<br>template<int i>
<br>using MyType =3D typename boost::mpl::at_c
<br>=C2=A0 =C2=A0< boost::mpl::vector
<br>=C2=A0 =C2=A0 =C2=A0< FirstType
<br>=C2=A0 =C2=A0 =C2=A0, SecondType
<br>=C2=A0 =C2=A0 =C2=A0, ThirdType
<br>=C2=A0 =C2=A0 =C2=A0// etc.
<br>=C2=A0 =C2=A0 =C2=A0>
<br>=C2=A0 =C2=A0, long(i)
<br>=C2=A0 =C2=A0>::type;
<br>
<br>
<br>I also think there's another intrinsic proposal for something
<br>similar, but with another syntax and using parameter packs.
<br>
<br>Please see:
<br>
<br><a href=3D"https://groups.google.com/a/isocpp.org/forum/#!msg/std-propo=
sals/ajLcDl8GbpA/uAVgEWI5CAAJ" rel=3D"nofollow" target=3D"_blank" onmousedo=
wn=3D"this.href=3D'https://groups.google.com/a/isocpp.org/forum/#!msg/s=
td-proposals/ajLcDl8GbpA/uAVgEWI5CAAJ';return true;" onclick=3D"this.hr=
ef=3D'https://groups.google.com/a/isocpp.org/forum/#!msg/std-proposals/=
ajLcDl8GbpA/uAVgEWI5CAAJ';return true;">https://groups.google.com/a/<wb=
r>isocpp.org/forum/#!msg/std-<wbr>proposals/ajLcDl8GbpA/<wbr>uAVgEWI5CAAJ</=
a>
<br>
<br>-regards,
<br>Larry
<br>
<br></blockquote></div></div></blockquote></div></blockquote></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/25c7472e-44f0-4f04-bab7-95eadc571e69%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/25c7472e-44f0-4f04-bab7-95eadc571e69=
%40isocpp.org</a>.<br />
------=_Part_8559_1919497353.1522238007629--
------=_Part_8558_1955698979.1522238007629--
.
Author: Bjorn Reese <breese@mail1.stofanet.dk>
Date: Wed, 28 Mar 2018 15:56:29 +0200
Raw View
On 03/28/18 13:53, hamza_sood@me.com wrote:
> Does the fact that it's possible in Boost have any effect on suitability
> for the standard? Besides, it's probably simpler to just chain a few
> std::conditionals than to add a dependency on Boost.
You are missing the bigger picture here. Instead of just solving your
particular use-case with a specific construct, we should consider which
meta-programming primitives we are still missing from C++, so that your
use-case can be added easily.
For example, your proposal can be implemented with a one-liner using
templates from Boost.Mp11:
|
template <int C, typename L>
using meta_switch_t = typename mp_map_find<L, mp_int<C>>::second_type;
|
The "switch cases" can be expressed using any type-list of std::pairs.
--
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/af9eceb0-bcb0-f515-e585-31509740add4%40mail1.stofanet.dk.
.
Author: Bjorn Reese <breese@mail1.stofanet.dk>
Date: Wed, 28 Mar 2018 16:07:56 +0200
Raw View
On 03/28/18 15:56, Bjorn Reese wrote:
> For example, your proposal can be implemented with a one-liner using
> templates from Boost.Mp11:
>
> |
> template <int C, typename L>
> using meta_switch_t = typename mp_map_find<L, mp_int<C>>::second_type;
> |
>
> The "switch cases" can be expressed using any type-list of std::pairs.
And we can even remove the dependency on std::pair with
|
template <int C, typename L>
using meta_switch_t = mp_second<mp_map_find<L, mp_int<C>>>;
|
--
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/ca080fe9-e23a-bf28-b175-690b49bc7eee%40mail1.stofanet.dk.
.
Author: hamza_sood@me.com
Date: Wed, 28 Mar 2018 07:15:18 -0700 (PDT)
Raw View
------=_Part_22593_1234294472.1522246518841
Content-Type: multipart/alternative;
boundary="----=_Part_22594_791050621.1522246518841"
------=_Part_22594_791050621.1522246518841
Content-Type: text/plain; charset="UTF-8"
There're a few things in that one-liner that differ from what I posted:
1. Only accepts int.
2. Default case is always void (if I'm reading the Boost docs correctly).
3. Syntax isn't quite as nice for the user.
I get what you're saying about trying to be more general, but I don't
really see this as a building a whole new construct for a specific use
case; it's just a light wrapper over std::conditional to make multiple
conditions easier to write. With your suggestion, it'd be going from
building it on top of one meta-programming primitive (std::conditional) to
another (map_find).
On Wednesday, March 28, 2018 at 2:56:31 PM UTC+1, Bjorn Reese wrote:
>
> On 03/28/18 13:53, hamza...@me.com <javascript:> wrote:
> > Does the fact that it's possible in Boost have any effect on suitability
> > for the standard? Besides, it's probably simpler to just chain a few
> > std::conditionals than to add a dependency on Boost.
>
> You are missing the bigger picture here. Instead of just solving your
> particular use-case with a specific construct, we should consider which
> meta-programming primitives we are still missing from C++, so that your
> use-case can be added easily.
>
> For example, your proposal can be implemented with a one-liner using
> templates from Boost.Mp11:
>
> |
> template <int C, typename L>
> using meta_switch_t = typename mp_map_find<L, mp_int<C>>::second_type;
> |
>
> The "switch cases" can be expressed using any type-list of std::pairs.
>
--
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/edd08e54-060f-48b1-beee-08018d17a863%40isocpp.org.
------=_Part_22594_791050621.1522246518841
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">There're a few things in that one-liner that differ fr=
om what I posted:<div><ol><li>Only accepts int.</li><li>Default case is alw=
ays void (if I'm reading the Boost docs correctly).</li><li>Syntax isn&=
#39;t quite as nice for the user.</li></ol><div>I get what you're sayin=
g about trying to be more general, but I don't really see this as a bui=
lding a whole new construct for a specific use case; it's just a light =
wrapper over std::conditional to make multiple conditions easier to write. =
With your suggestion, it'd be going from building it on top of one meta=
-programming primitive (std::conditional) to another (map_find).</div></div=
><br>On Wednesday, March 28, 2018 at 2:56:31 PM UTC+1, Bjorn Reese wrote:<b=
lockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;borde=
r-left: 1px #ccc solid;padding-left: 1ex;">On 03/28/18 13:53, <a href=3D"ja=
vascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"P8Zq3OatAwAJ" rel=3D"=
nofollow" onmousedown=3D"this.href=3D'javascript:';return true;" on=
click=3D"this.href=3D'javascript:';return true;">hamza...@me.com</a=
> wrote:
<br>> Does the fact that it's possible in Boost have any effect on s=
uitability=20
<br>> for the standard? Besides, it's probably simpler to just chain=
a few=20
<br>> std::conditionals than to add a dependency on Boost.
<br>
<br>You are missing the bigger picture here. Instead of just solving your
<br>particular use-case with a specific construct, we should consider which
<br>meta-programming primitives we are still missing from C++, so that your
<br>use-case can be added easily.
<br>
<br>For example, your proposal can be implemented with a one-liner using
<br>templates from Boost.Mp11:
<br>
<br>|
<br>template <int C, typename L>
<br>using meta_switch_t =3D typename mp_map_find<L, mp_int<C>>:=
:second_type;
<br>|
<br>
<br>The "switch cases" can be expressed using any type-list of st=
d::pairs.
<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/edd08e54-060f-48b1-beee-08018d17a863%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/edd08e54-060f-48b1-beee-08018d17a863=
%40isocpp.org</a>.<br />
------=_Part_22594_791050621.1522246518841--
------=_Part_22593_1234294472.1522246518841--
.
Author: hamza_sood@me.com
Date: Wed, 28 Mar 2018 10:14:45 -0700 (PDT)
Raw View
------=_Part_2633_675189779.1522257285256
Content-Type: multipart/alternative;
boundary="----=_Part_2634_1857727572.1522257285256"
------=_Part_2634_1857727572.1522257285256
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
To clarify: I=E2=80=99m in no way opposed to more meta-programming primitiv=
es. Maps=20
etc. would be awesome. I just think it=E2=80=99s overkill for a simple addi=
tion=20
like this.
On Wednesday, March 28, 2018 at 3:15:18 PM UTC+1, hamza...@me.com wrote:
>
> There're a few things in that one-liner that differ from what I posted:
>
> 1. Only accepts int.
> 2. Default case is always void (if I'm reading the Boost docs=20
> correctly).
> 3. Syntax isn't quite as nice for the user.
>
> I get what you're saying about trying to be more general, but I don't=20
> really see this as a building a whole new construct for a specific use=20
> case; it's just a light wrapper over std::conditional to make multiple=20
> conditions easier to write. With your suggestion, it'd be going from=20
> building it on top of one meta-programming primitive (std::conditional) t=
o=20
> another (map_find).
>
> On Wednesday, March 28, 2018 at 2:56:31 PM UTC+1, Bjorn Reese wrote:
>>
>> On 03/28/18 13:53, hamza...@me.com wrote:=20
>> > Does the fact that it's possible in Boost have any effect on=20
>> suitability=20
>> > for the standard? Besides, it's probably simpler to just chain a few=
=20
>> > std::conditionals than to add a dependency on Boost.=20
>>
>> You are missing the bigger picture here. Instead of just solving your=20
>> particular use-case with a specific construct, we should consider which=
=20
>> meta-programming primitives we are still missing from C++, so that your=
=20
>> use-case can be added easily.=20
>>
>> For example, your proposal can be implemented with a one-liner using=20
>> templates from Boost.Mp11:=20
>>
>> |=20
>> template <int C, typename L>=20
>> using meta_switch_t =3D typename mp_map_find<L, mp_int<C>>::second_type;=
=20
>> |=20
>>
>> The "switch cases" can be expressed using any type-list of std::pairs.=
=20
>>
>
--=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/341759d4-e376-4d9d-b376-5ce9595b3640%40isocpp.or=
g.
------=_Part_2634_1857727572.1522257285256
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">To clarify: I=E2=80=99m in no way opposed to more meta-pro=
gramming primitives. Maps etc. would be awesome. I just think it=E2=80=99s =
overkill for a simple addition like this.<br><br>On Wednesday, March 28, 20=
18 at 3:15:18 PM UTC+1, hamza...@me.com wrote:<blockquote class=3D"gmail_qu=
ote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padd=
ing-left: 1ex;"><div dir=3D"ltr">There're a few things in that one-line=
r that differ from what I posted:<div><ol><li>Only accepts int.</li><li>Def=
ault case is always void (if I'm reading the Boost docs correctly).</li=
><li>Syntax isn't quite as nice for the user.</li></ol><div>I get what =
you're saying about trying to be more general, but I don't really s=
ee this as a building a whole new construct for a specific use case; it'=
;s just a light wrapper over std::conditional to make multiple conditions e=
asier to write. With your suggestion, it'd be going from building it on=
top of one meta-programming primitive (std::conditional) to another (map_f=
ind).</div></div><br>On Wednesday, March 28, 2018 at 2:56:31 PM UTC+1, Bjor=
n Reese wrote:<blockquote class=3D"gmail_quote" style=3D"margin:0;margin-le=
ft:0.8ex;border-left:1px #ccc solid;padding-left:1ex">On 03/28/18 13:53, <a=
rel=3D"nofollow">hamza...@me.com</a> wrote:
<br>> Does the fact that it's possible in Boost have any effect on s=
uitability=20
<br>> for the standard? Besides, it's probably simpler to just chain=
a few=20
<br>> std::conditionals than to add a dependency on Boost.
<br>
<br>You are missing the bigger picture here. Instead of just solving your
<br>particular use-case with a specific construct, we should consider which
<br>meta-programming primitives we are still missing from C++, so that your
<br>use-case can be added easily.
<br>
<br>For example, your proposal can be implemented with a one-liner using
<br>templates from Boost.Mp11:
<br>
<br>|
<br>template <int C, typename L>
<br>using meta_switch_t =3D typename mp_map_find<L, mp_int<C>>:=
:second_type;
<br>|
<br>
<br>The "switch cases" can be expressed using any type-list of st=
d::pairs.
<br></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/341759d4-e376-4d9d-b376-5ce9595b3640%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/341759d4-e376-4d9d-b376-5ce9595b3640=
%40isocpp.org</a>.<br />
------=_Part_2634_1857727572.1522257285256--
------=_Part_2633_675189779.1522257285256--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Wed, 28 Mar 2018 10:44:58 -0700 (PDT)
Raw View
------=_Part_18818_1413278951.1522259098225
Content-Type: multipart/alternative;
boundary="----=_Part_18819_38518496.1522259098225"
------=_Part_18819_38518496.1522259098225
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
On Wednesday, March 28, 2018 at 1:14:45 PM UTC-4, hamza...@me.com wrote:
>
> To clarify: I=E2=80=99m in no way opposed to more meta-programming primit=
ives.=20
> Maps etc. would be awesome. I just think it=E2=80=99s overkill for a simp=
le=20
> addition like this.
>
The problem is that most similar features are just "simple additions like=
=20
this". `std::sort` is a simple addition. But without the overall STL=20
framework around it, it would have a very different interface.
I'm not saying that it's wrong to go for the minimum feature here. But=20
building metaprogramming tools function-by-function like this, rather than=
=20
through a top-down design, will not end well.
--=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/cc9bbdd4-f250-44ba-aa5c-64046bde2e3b%40isocpp.or=
g.
------=_Part_18819_38518496.1522259098225
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Wednesday, March 28, 2018 at 1:14:45 PM UTC-4, hamza...=
@me.com wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-l=
eft: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"=
>To clarify: I=E2=80=99m in no way opposed to more meta-programming primiti=
ves. Maps etc. would be awesome. I just think it=E2=80=99s overkill for a s=
imple addition like this.<br></div></blockquote><div><br>The problem is tha=
t most similar features are just "simple additions like this". `s=
td::sort` is a simple addition. But without the overall STL framework aroun=
d it, it would have a very different interface.<br><br>I'm not saying t=
hat it's wrong to go for the minimum feature here. But building metapro=
gramming tools function-by-function like this, rather than through a top-do=
wn design, will not end well.</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/cc9bbdd4-f250-44ba-aa5c-64046bde2e3b%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/cc9bbdd4-f250-44ba-aa5c-64046bde2e3b=
%40isocpp.org</a>.<br />
------=_Part_18819_38518496.1522259098225--
------=_Part_18818_1413278951.1522259098225--
.
Author: hamza_sood@me.com
Date: Wed, 28 Mar 2018 11:11:58 -0700 (PDT)
Raw View
------=_Part_23660_1778860471.1522260718983
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Yeah, that=E2=80=99s worth keeping in mind. However I don=E2=80=99t think a=
ny higher constructs will end up changing the interface for this unlike the=
std::sort example? I think that whether it works with maps or conditionals=
is just an implementation detail.
Clearly Bjorne and I are in disagreement, it=E2=80=99d be nice to get some =
other opinions on this.
--=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/689ab834-6764-4702-8d16-0e4e108da9f0%40isocpp.or=
g.
------=_Part_23660_1778860471.1522260718983--
.
Author: "Arthur O'Dwyer" <arthur.j.odwyer@gmail.com>
Date: Wed, 28 Mar 2018 13:59:54 -0700
Raw View
--001a114db3c800131f05687f4ac3
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
On Wed, Mar 28, 2018 at 11:11 AM, <hamza_sood@me.com> wrote:
> Yeah, that=E2=80=99s worth keeping in mind. However I don=E2=80=99t think=
any higher
> constructs will end up changing the interface for this unlike the std::so=
rt
> example? I think that whether it works with maps or conditionals is just =
an
> implementation detail.
>
> Clearly Bjorne and I are in disagreement, it=E2=80=99d be nice to get som=
e other
> opinions on this.
>
Probably redundant, but to clarify my position on cost/benefit analysis
here:
- I think the benefit of this proposal is low, because it is only one
utility, in an area that needs lots (see: Hana, MPL, MP11, Brigand); and as
Bjorn/Nicol say, every miscellaneous name that goes into the Standard is
technical debt that makes it harder and harder to propose an actually
useful metaprogramming system (because all the good names are taken, and
because there are so many arcane precedents to comply with).
- I think the benefit of this proposal is low, because the specific design
(type-based metaprogramming, building a chain of std::conditionals) is
likely to perform *worse* than what the user would write by hand.
- I think the benefit of this proposal is low, because the specific design
(type-based metaprogramming) is likely to be *less readable* (although more
concise) than what the user would write by hand.
- I think the benefit of this proposal is low, because anecdotally, I
personally have no use-cases for the proposed feature.
The *cost* is not particularly high, but I just don't see the *benefit*
here to justify moving this helper class from "20 lines of C++ in Hamza's
codebase" to "40 lines of English in the ISO Standard."
=E2=80=93Arthur
--=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/CADvuK0%2B6DWc2YGjQ%2BxKbPfq6DFXYTUNZD0pLwp0GiUp=
CWMifQg%40mail.gmail.com.
--001a114db3c800131f05687f4ac3
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Wed, Mar 28, 2018 at 11:11 AM, <span dir=3D"ltr"><<=
a href=3D"mailto:hamza_sood@me.com" target=3D"_blank">hamza_sood@me.com</a>=
></span> wrote:<br><div class=3D"gmail_extra"><div class=3D"gmail_quote"=
><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border=
-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);=
padding-left:1ex">Yeah, that=E2=80=99s worth keeping in mind. However I don=
=E2=80=99t think any higher constructs will end up changing the interface f=
or this unlike the std::sort example? I think that whether it works with ma=
ps or conditionals is just an implementation detail.<br>
<br>
Clearly Bjorne and I are in disagreement, it=E2=80=99d be nice to get some =
other opinions on this.<br></blockquote><div><br></div><div>Probably redund=
ant, but to clarify my position on cost/benefit analysis here:</div><div>- =
I think the benefit of this proposal is low, because it is only one utility=
, in an area that needs lots (see: Hana, MPL, MP11, Brigand); and as Bjorn/=
Nicol say, every miscellaneous name that goes into the Standard is technica=
l debt that makes it harder and harder to propose an actually useful metapr=
ogramming system (because all the good names are taken, and because there a=
re so many arcane precedents to comply with).</div><div>- I think the benef=
it of this proposal is low, because the specific design (type-based metapro=
gramming, building a chain of std::conditionals) is likely to perform <i>wo=
rse</i> than what the user would write by hand.</div><div><div>- I think th=
e benefit of this proposal is low, because the specific design (type-based =
metaprogramming) is likely to be <i>less readable</i>=C2=A0(although more c=
oncise) than what the user would write by hand.</div></div><div><div>- I th=
ink the benefit of this proposal is low, because anecdotally, I personally =
have no use-cases for the proposed feature.</div></div><div><br></div><div>=
The <i>cost</i> is not particularly high, but I just don't see the <i>b=
enefit</i> here to justify moving this helper class from "20 lines of =
C++ in Hamza's codebase" to "40 lines of English in the ISO S=
tandard."</div><div><br></div><div>=E2=80=93Arthur</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/CADvuK0%2B6DWc2YGjQ%2BxKbPfq6DFXYTUNZ=
D0pLwp0GiUpCWMifQg%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CADvuK0%2B6DW=
c2YGjQ%2BxKbPfq6DFXYTUNZD0pLwp0GiUpCWMifQg%40mail.gmail.com</a>.<br />
--001a114db3c800131f05687f4ac3--
.
Author: hamza_sood@me.com
Date: Thu, 29 Mar 2018 08:53:38 -0700 (PDT)
Raw View
------=_Part_3070_1920590099.1522338818774
Content-Type: multipart/alternative;
boundary="----=_Part_3071_492630974.1522338818776"
------=_Part_3071_492630974.1522338818776
Content-Type: text/plain; charset="UTF-8"
> - I think the benefit of this proposal is low, because it is only one
> utility, in an area that needs lots (see: Hana, MPL, MP11, Brigand); and as
> Bjorn/Nicol say, every miscellaneous name that goes into the Standard is
> technical debt that makes it harder and harder to propose an actually
> useful metaprogramming system (because all the good names are taken, and
> because there are so many arcane precedents to comply with).
>
I can't imagine what else might want to use the name "meta_switch" without
being a meta-programming switch that uses "meta_case" and "meta_default".
If such a thing arises in the future, then it probably has the wrong name.
As for precedents, what *extra* precedents does this bring along exactly?
- I think the benefit of this proposal is low, because the specific design
> (type-based metaprogramming, building a chain of std::conditionals) is
> likely to perform *worse* than what the user would write by hand.
>
I did some quick tests and the number of cases involved needed to exceed
~150 before I could measure any significant change in compilation time
versus the by-hand approach, so I really don't think that's an issue.
- I think the benefit of this proposal is low, because the specific design
> (type-based metaprogramming) is likely to be *less readable* (although
> more concise) than what the user would write by hand.
>
I don't really see how the code you posted:
template<class T> struct wrap {};
template<class T> struct unwrapper;
template<class T> struct unwrapper<wrap<T>> { using type = T; };
template<class T> using unwrap = typename unwrapper<T>::type;
template<int i>
auto helper() {
if constexpr(i == 0) {
return wrap<FirstType>{};
} else if constexpr (i == 1) {
return wrap<SecondType>{};
} else if constexpr (i == 2) {
return wrap<ThirdType>{};
}
}
template<int i> using MyType = unwrap<decltype(helper<i>())>;
is more readable than:
template<int i>
using MyType = meta_switch_t<i,
meta_case<0, FirstType>,
meta_case<1, SecondType>,
meta_case<2, ThirdType>
>;
The latter clearly expresses intent of declaring a type based on the value
of the template parameter. Whereas the former introduces a bunch of seemly
unrelated things (wrappers, unwrappers, a helper function) and is far more
difficult to reason about.
- I think the benefit of this proposal is low, because anecdotally, I
> personally have no use-cases for the proposed feature.
>
Do you have use-cases for meta-maps and the other stuff that this
supposedly gets in the way of?
The *cost* is not particularly high, but I just don't see the *benefit*
> here to justify moving this helper class from "20 lines of C++ in Hamza's
> codebase" to "40 lines of English in the ISO Standard."
>
The benefit is very similar to that of std::conditional. It's not like
you'll be using it constantly, but it's very nice to have on those few
occasions.
--
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/4611dc7b-f8aa-4fc0-a171-2312c0210d22%40isocpp.org.
------=_Part_3071_492630974.1522338818776
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><blockquote class=3D"gmail_quote" style=3D"margin: 0;m=
argin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=
=3D"ltr"><div><div class=3D"gmail_quote"><div>- I think the benefit of this=
proposal is low, because it is only one utility, in an area that needs lot=
s (see: Hana, MPL, MP11, Brigand); and as Bjorn/Nicol say, every miscellane=
ous name that goes into the Standard is technical debt that makes it harder=
and harder to propose an actually useful metaprogramming system (because a=
ll the good names are taken, and because there are so many arcane precedent=
s to comply with).</div></div></div></div></blockquote><div>=C2=A0</div><di=
v>I can't imagine what else might want to use the name "meta_switc=
h" without being a meta-programming switch that uses "meta_case&q=
uot; and "meta_default". If such a thing arises in the future, th=
en it probably has the wrong name. As for precedents, what <i>extra</i> pre=
cedents does this bring along exactly?</div><div><br></div><div><br></div><=
div><br></div><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-l=
eft: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"=
><div><div class=3D"gmail_quote"><div>- I think the benefit of this proposa=
l is low, because the specific design (type-based metaprogramming, building=
a chain of std::conditionals) is likely to perform <i>worse</i> than what =
the user would write by hand.</div></div></div></div></blockquote><div>=C2=
=A0</div><div>I did some quick tests and the number of cases involved neede=
d to exceed ~150 before I could measure any significant change in compilati=
on time versus the by-hand approach, so I really don't think that's=
an issue.</div><div><br></div><div><br></div><div><br></div><blockquote cl=
ass=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px =
#ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div class=3D"gmail_quote">=
<div><div>- I think the benefit of this proposal is low, because the specif=
ic design (type-based metaprogramming) is likely to be <i>less readable</i>=
=C2=A0(although more concise) than what the user would write by hand.</div>=
</div></div></div></blockquote><div>=C2=A0</div><div>I don't really see=
how the code you posted:</div><div><br></div><div><div class=3D"prettyprin=
t" style=3D"background-color: rgb(250, 250, 250); border: 1px solid rgb(187=
, 187, 187); word-wrap: break-word;"><code class=3D"prettyprint"><div class=
=3D"subprettyprint"><div style=3D"font-family: Arial, Helvetica, sans-serif=
;"><span style=3D"color: #008;" class=3D"styled-by-prettify">template</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify"><</span><span=
style=3D"color: #008;" class=3D"styled-by-prettify">class</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> T</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">></span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" clas=
s=3D"styled-by-prettify">struct</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> wrap </span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">{};</span></div><div style=3D"font-family: Arial, Helvetic=
a, sans-serif;"><span style=3D"color: #008;" class=3D"styled-by-prettify">t=
emplate</span><span style=3D"color: #660;" class=3D"styled-by-prettify"><=
;</span><span style=3D"color: #008;" class=3D"styled-by-prettify">class</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> T</span><span=
style=3D"color: #660;" class=3D"styled-by-prettify">></span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #008;" class=3D"styled-by-prettify">struct</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> unwrapper</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">;</span></div><div style=3D"font-family: =
Arial, Helvetica, sans-serif;"><span style=3D"color: #008;" class=3D"styled=
-by-prettify">template</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify"><</span><span style=3D"color: #008;" class=3D"styled-by-pret=
tify">class</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> T</span><span style=3D"color: #660;" class=3D"styled-by-prettify">></s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span=
style=3D"color: #008;" class=3D"styled-by-prettify">struct</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> unwrapper</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify"><</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify">wrap</span><span style=3D"color:=
#660;" class=3D"styled-by-prettify"><</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify">T</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">>></span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"style=
d-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">usi=
ng</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> type </=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> T</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;"=
class=3D"styled-by-prettify">};</span></div><div style=3D"font-family: Ari=
al, Helvetica, sans-serif;"><span style=3D"color: #008;" class=3D"styled-by=
-prettify">template</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify"><</span><span style=3D"color: #008;" class=3D"styled-by-prettif=
y">class</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> T=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">></span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span st=
yle=3D"color: #008;" class=3D"styled-by-prettify">using</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> unwrap </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;=
" class=3D"styled-by-prettify">typename</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> unwrapper</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify"><</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">T</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">>::</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify">type</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">;</span></div><div style=3D"font-family: Arial, Helvetica, sans-serif;=
"><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span></di=
v><div style=3D"font-family: Arial, Helvetica, sans-serif;"><span style=3D"=
color: #008;" class=3D"styled-by-prettify">template</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify"><</span><span style=3D"color: #=
008;" class=3D"styled-by-prettify">int</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> i</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">></span></div><div style=3D"font-family: Arial, Helv=
etica, sans-serif;"><span style=3D"color: #008;" class=3D"styled-by-prettif=
y">auto</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> he=
lper</span><span style=3D"color: #660;" class=3D"styled-by-prettify">()</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">{</span></div><div styl=
e=3D"font-family: Arial, Helvetica, sans-serif;"><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> =C2=A0 =C2=A0 </span><span style=3D"color:=
#008;" class=3D"styled-by-prettify">if</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"=
styled-by-prettify">constexpr</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify">i </span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">=3D=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> <=
/span><span style=3D"color: #066;" class=3D"styled-by-prettify">0</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></div><div style=3D"font-fami=
ly: Arial, Helvetica, sans-serif;"><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> =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"> wrap</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify"><</span><span style=3D"color: #606;" class=
=3D"styled-by-prettify">FirstType</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">>{};</span></div><div style=3D"font-family: Aria=
l, Helvetica, sans-serif;"><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> =C2=A0 =C2=A0 </span><span style=3D"color: #660;" class=3D"style=
d-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">els=
e</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><=
span style=3D"color: #008;" class=3D"styled-by-prettify">if</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"col=
or: #008;" class=3D"styled-by-prettify">constexpr</span><span style=3D"colo=
r: #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">i </span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">=3D=3D</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span style=3D"color: #066;" class=3D"styled-by-prettify">=
1</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></div><div style=3D=
"font-family: Arial, Helvetica, sans-serif;"><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> =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-prettify"> wrap</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify"><</span><span style=3D"color: #606=
;" class=3D"styled-by-prettify">SecondType</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">>{};</span></div><div style=3D"font-fami=
ly: Arial, Helvetica, sans-serif;"><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> =C2=A0 =C2=A0 </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">}</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-pret=
tify">else</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">if</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span sty=
le=3D"color: #008;" class=3D"styled-by-prettify">constexpr</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">i </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">=3D=3D</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> </span><span style=3D"color: #066;" class=3D"styled-by=
-prettify">2</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></div><d=
iv style=3D"font-family: Arial, Helvetica, sans-serif;"><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> =C2=A0 =C2=A0 =C2=A0 =C2=A0 </span>=
<span style=3D"color: #008;" class=3D"styled-by-prettify">return</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> wrap</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify"><</span><span style=3D"=
color: #606;" class=3D"styled-by-prettify">ThirdType</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">>{};</span></div><div style=3D=
"font-family: Arial, Helvetica, sans-serif;"><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> =C2=A0 =C2=A0 </span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">}</span></div><div style=3D"font-family: A=
rial, Helvetica, sans-serif;"><span style=3D"color: #660;" class=3D"styled-=
by-prettify">}</span></div><div style=3D"font-family: Arial, Helvetica, san=
s-serif;"><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></s=
pan></div><div style=3D"font-family: Arial, Helvetica, sans-serif;"><span s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">template</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify"><</span><span style=3D"=
color: #008;" class=3D"styled-by-prettify">int</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> i</span><span style=3D"color: #660;" c=
lass=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">using</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify"=
>MyType</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> unwrap</span><span=
style=3D"color: #660;" class=3D"styled-by-prettify"><</span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">decltype</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify">helper</span><span style=3D"color: #0=
80;" class=3D"styled-by-prettify"><i></span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">())>;</span></div></div></code></div><d=
iv><br></div>is more readable than:</div><div><br></div><div><div class=3D"=
prettyprint" style=3D"background-color: rgb(250, 250, 250); border: 1px sol=
id rgb(187, 187, 187); word-wrap: break-word;"><code class=3D"prettyprint">=
<div class=3D"subprettyprint"><font><span style=3D"color: #008;" class=3D"s=
tyled-by-prettify">template</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify"><</span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">int</span><font color=3D"#000000"><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> i</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-pr=
ettify">using</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">MyType=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> meta_switch_t</span><span=
style=3D"color: #660;" class=3D"styled-by-prettify"><</span><span style=
=3D"caret-color: rgb(102, 0, 102);"><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify">i</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 meta_case</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify"><</span><span style=3D"color: #066;" class=3D"styled-b=
y-prettify">0</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: #606;" class=3D"styled-by-prettify">FirstType</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 met=
a_case</span><span style=3D"color: #660;" class=3D"styled-by-prettify"><=
</span><span style=3D"color: #066;" class=3D"styled-by-prettify">1</span><s=
pan 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=
: #606;" class=3D"styled-by-prettify">SecondType</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">>,</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 meta_case</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify"><</span><span style=3D=
"color: #066;" class=3D"styled-by-prettify">2</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: #606;" class=3D"sty=
led-by-prettify">ThirdType</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">></span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br></span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">>;</span></span></font></font></div></code></div><div><br></div>The =
latter clearly expresses intent of declaring a type based on the value of t=
he template parameter. Whereas the former introduces a bunch of seemly unre=
lated things (wrappers, unwrappers, a helper function) and is far more diff=
icult to reason about.<br><br><br></div><div><br></div><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 class=3D"gmail_quote"><div><=
div>- I think the benefit of this proposal is low, because anecdotally, I p=
ersonally have no use-cases for the proposed feature.</div></div></div></di=
v></blockquote><div><br></div><div>Do you have use-cases for meta-maps and =
the other stuff that this supposedly gets in the way of?</div><div><br></di=
v><div><br></div><div><br></div><blockquote class=3D"gmail_quote" style=3D"=
margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;=
"><div dir=3D"ltr"><div class=3D"gmail_quote"><div></div><div>The <i>cost</=
i> is not particularly high, but I just don't see the <i>benefit</i> he=
re to justify moving this helper class from "20 lines of C++ in Hamza&=
#39;s codebase" to "40 lines of English in the ISO Standard."=
;</div></div></div></blockquote><div><br></div><div>The benefit is very sim=
ilar to that of std::conditional. It's not like you'll be using it =
constantly, but it's very nice to have on those few occasions.</div></d=
iv>
<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/4611dc7b-f8aa-4fc0-a171-2312c0210d22%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/4611dc7b-f8aa-4fc0-a171-2312c0210d22=
%40isocpp.org</a>.<br />
------=_Part_3071_492630974.1522338818776--
------=_Part_3070_1920590099.1522338818774--
.
Author: Edward Catmur <ed@catmur.co.uk>
Date: Thu, 29 Mar 2018 11:09:02 -0700 (PDT)
Raw View
------=_Part_3453_806152814.1522346942523
Content-Type: multipart/alternative;
boundary="----=_Part_3454_92337352.1522346942525"
------=_Part_3454_92337352.1522346942525
Content-Type: text/plain; charset="UTF-8"
On Thursday, 29 March 2018 16:53:38 UTC+1, hamza...@me.com wrote:
>
>
> - I think the benefit of this proposal is low, because it is only one
>> utility, in an area that needs lots (see: Hana, MPL, MP11, Brigand); and as
>> Bjorn/Nicol say, every miscellaneous name that goes into the Standard is
>> technical debt that makes it harder and harder to propose an actually
>> useful metaprogramming system (because all the good names are taken, and
>> because there are so many arcane precedents to comply with).
>>
>
> I can't imagine what else might want to use the name "meta_switch" without
> being a meta-programming switch that uses "meta_case" and "meta_default".
> If such a thing arises in the future, then it probably has the wrong name.
> As for precedents, what *extra* precedents does this bring along exactly?
>
In this case, "meta_" as a prefix (effectively a namespace) for
metaprogramming. This is inconsistent when we are not using this prefix
elsewhere in the metaprogramming library.
> - I think the benefit of this proposal is low, because the specific design
>> (type-based metaprogramming, building a chain of std::conditionals) is
>> likely to perform *worse* than what the user would write by hand.
>>
>
> I did some quick tests and the number of cases involved needed to exceed
> ~150 before I could measure any significant change in compilation time
> versus the by-hand approach, so I really don't think that's an issue.
>
>
>
> - I think the benefit of this proposal is low, because the specific design
>> (type-based metaprogramming) is likely to be *less readable* (although
>> more concise) than what the user would write by hand.
>>
>
> I don't really see how the code you posted:
>
> template<class T> struct wrap {};
> template<class T> struct unwrapper;
> template<class T> struct unwrapper<wrap<T>> { using type = T; };
> template<class T> using unwrap = typename unwrapper<T>::type;
>
> template<int i>
> auto helper() {
> if constexpr(i == 0) {
> return wrap<FirstType>{};
> } else if constexpr (i == 1) {
> return wrap<SecondType>{};
> } else if constexpr (i == 2) {
> return wrap<ThirdType>{};
> }
> }
>
> template<int i> using MyType = unwrap<decltype(helper<i>())>;
>
> is more readable than:
>
> template<int i>
> using MyType = meta_switch_t<i,
> meta_case<0, FirstType>,
> meta_case<1, SecondType>,
> meta_case<2, ThirdType>
> >;
>
> The latter clearly expresses intent of declaring a type based on the value
> of the template parameter. Whereas the former introduces a bunch of seemly
> unrelated things (wrappers, unwrappers, a helper function) and is far more
> difficult to reason about.
>
Since we're targeting C++20, we can reasonably assume that an identity
metafunction (P0887) will be available, removing the need for wrap/unwrap,
and that lambdas in unevaluated contexts (P0315) will be allowed, removing
the need for a helper function:
template<int i>
using MyType = typename decltype([]{
if constexpr(i == 0) return identity<int>{};
else if constexpr (i == 1) return identity<char>{};
else if constexpr (i == 2) return identity<float>{};
}())::type;
Perhaps this is still less clear than a dedicated metafunction; but on the
other hand there's less library code here to understand.
There's also the option of using tuple (where the cases are integral and
contiguous), or overload (P0051).
> - I think the benefit of this proposal is low, because anecdotally, I
>> personally have no use-cases for the proposed feature.
>>
>
> Do you have use-cases for meta-maps and the other stuff that this
> supposedly gets in the way of?
>
>
>
> The *cost* is not particularly high, but I just don't see the *benefit*
>> here to justify moving this helper class from "20 lines of C++ in Hamza's
>> codebase" to "40 lines of English in the ISO Standard."
>>
>
> The benefit is very similar to that of std::conditional. It's not like
> you'll be using it constantly, but it's very nice to have on those few
> occasions.
>
std::conditional is essential to metaprogramming and is difficult and
arcane to emulate, especially in C++11. A type switch is a lot less
essential.
--
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/e29798f6-2e2a-4816-bc17-677ba5238702%40isocpp.org.
------=_Part_3454_92337352.1522346942525
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Thursday, 29 March 2018 16:53:38 UTC+1, hamza..=
..@me.com 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"lt=
r"><br><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"><div><div c=
lass=3D"gmail_quote"><div>- I think the benefit of this proposal is low, be=
cause it is only one utility, in an area that needs lots (see: Hana, MPL, M=
P11, Brigand); and as Bjorn/Nicol say, every miscellaneous name that goes i=
nto the Standard is technical debt that makes it harder and harder to propo=
se an actually useful metaprogramming system (because all the good names ar=
e taken, and because there are so many arcane precedents to comply with).</=
div></div></div></div></blockquote><div>=C2=A0</div><div>I can't imagin=
e what else might want to use the name "meta_switch" without bein=
g a meta-programming switch that uses "meta_case" and "meta_=
default". If such a thing arises in the future, then it probably has t=
he wrong name. As for precedents, what <i>extra</i> precedents does this br=
ing along exactly?</div></div></blockquote><div><br></div><div>In this case=
, "meta_" as a prefix (effectively a namespace) for metaprogrammi=
ng. This is inconsistent when we are not using this prefix elsewhere in the=
metaprogramming library.</div><div>=C2=A0</div><blockquote class=3D"gmail_=
quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;pa=
dding-left: 1ex;"><div dir=3D"ltr"><div></div><blockquote class=3D"gmail_qu=
ote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding=
-left:1ex"><div dir=3D"ltr"><div><div class=3D"gmail_quote"><div>- I think =
the benefit of this proposal is low, because the specific design (type-base=
d metaprogramming, building a chain of std::conditionals) is likely to perf=
orm <i>worse</i> than what the user would write by hand.</div></div></div><=
/div></blockquote><div>=C2=A0</div><div>I did some quick tests and the numb=
er of cases involved needed to exceed ~150 before I could measure any signi=
ficant change in compilation time versus the by-hand approach, so I really =
don't think that's an issue.</div><div><br></div><div><br></div><di=
v><br></div><blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left=
:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div c=
lass=3D"gmail_quote"><div><div>- I think the benefit of this proposal is lo=
w, because the specific design (type-based metaprogramming) is likely to be=
<i>less readable</i>=C2=A0(although more concise) than what the user would=
write by hand.</div></div></div></div></blockquote><div>=C2=A0</div><div>I=
don't really see how the code you posted:</div><div><br></div><div><di=
v style=3D"background-color:rgb(250,250,250);border:1px solid rgb(187,187,1=
87);word-wrap:break-word"><code><div><div style=3D"font-family:Arial,Helvet=
ica,sans-serif"><span style=3D"color:#008">template</span><span style=3D"co=
lor:#660"><</span><span style=3D"color:#008">class</span><span style=3D"=
color:#000"> T</span><span style=3D"color:#660">></span><span style=3D"c=
olor:#000"> </span><span style=3D"color:#008">struct</span><span style=3D"c=
olor:#000"> wrap </span><span style=3D"color:#660">{};</span></div><div sty=
le=3D"font-family:Arial,Helvetica,sans-serif"><span style=3D"color:#008">te=
mplate</span><span style=3D"color:#660"><</span><span style=3D"color:#00=
8">class</span><span style=3D"color:#000"> T</span><span style=3D"color:#66=
0">></span><span style=3D"color:#000"> </span><span style=3D"color:#008"=
>struct</span><span style=3D"color:#000"> unwrapper</span><span style=3D"co=
lor:#660">;</span></div><div style=3D"font-family:Arial,Helvetica,sans-seri=
f"><span style=3D"color:#008">template</span><span style=3D"color:#660"><=
;</span><span style=3D"color:#008">class</span><span style=3D"color:#000"> =
T</span><span style=3D"color:#660">></span><span style=3D"color:#000"> <=
/span><span style=3D"color:#008">struct</span><span style=3D"color:#000"> u=
nwrapper</span><span style=3D"color:#660"><</span><span style=3D"color:#=
000">wrap</span><span style=3D"color:#660"><</span><span style=3D"color:=
#000">T</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"> </span><span style=3D"color:#008">using</span><span style=3D"color:#000=
"> type </span><span style=3D"color:#660">=3D</span><span style=3D"color:#0=
00"> T</span><span style=3D"color:#660">;</span><span style=3D"color:#000">=
</span><span style=3D"color:#660">};</span></div><div style=3D"font-family=
:Arial,Helvetica,sans-serif"><span style=3D"color:#008">template</span><spa=
n style=3D"color:#660"><</span><span style=3D"color:#008">class</span><s=
pan style=3D"color:#000"> T</span><span style=3D"color:#660">></span><sp=
an style=3D"color:#000"> </span><span style=3D"color:#008">using</span><spa=
n style=3D"color:#000"> unwrap </span><span style=3D"color:#660">=3D</span>=
<span style=3D"color:#000"> </span><span style=3D"color:#008">typename</spa=
n><span style=3D"color:#000"> unwrapper</span><span style=3D"color:#660">&l=
t;</span><span style=3D"color:#000">T</span><span style=3D"color:#660">>=
::</span><span style=3D"color:#000">type</span><span style=3D"color:#660">;=
</span></div><div style=3D"font-family:Arial,Helvetica,sans-serif"><span st=
yle=3D"color:#000"><br></span></div><div style=3D"font-family:Arial,Helveti=
ca,sans-serif"><span style=3D"color:#008">template</span><span style=3D"col=
or:#660"><</span><span style=3D"color:#008">int</span><span style=3D"col=
or:#000"> i</span><span style=3D"color:#660">></span></div><div style=3D=
"font-family:Arial,Helvetica,sans-serif"><span style=3D"color:#008">auto</s=
pan><span style=3D"color:#000"> helper</span><span style=3D"color:#660">()<=
/span><span style=3D"color:#000"> </span><span style=3D"color:#660">{</span=
></div><div style=3D"font-family:Arial,Helvetica,sans-serif"><span style=3D=
"color:#000"> =C2=A0 =C2=A0 </span><span style=3D"color:#008">if</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#008">constexpr</span><=
span style=3D"color:#660">(</span><span style=3D"color:#000">i </span><span=
style=3D"color:#660">=3D=3D</span><span style=3D"color:#000"> </span><span=
style=3D"color:#066">0</span><span style=3D"color:#660">)</span><span styl=
e=3D"color:#000"> </span><span style=3D"color:#660">{</span></div><div styl=
e=3D"font-family:Arial,Helvetica,sans-serif"><span style=3D"color:#000"> =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#008">return</span>=
<span style=3D"color:#000"> wrap</span><span style=3D"color:#660"><</spa=
n><span style=3D"color:#606">FirstType</span><span style=3D"color:#660">>=
;{};</span></div><div style=3D"font-family:Arial,Helvetica,sans-serif"><spa=
n style=3D"color:#000"> =C2=A0 =C2=A0 </span><span style=3D"color:#660">}</=
span><span style=3D"color:#000"> </span><span style=3D"color:#008">else</sp=
an><span style=3D"color:#000"> </span><span style=3D"color:#008">if</span><=
span style=3D"color:#000"> </span><span style=3D"color:#008">constexpr</spa=
n><span style=3D"color:#000"> </span><span style=3D"color:#660">(</span><sp=
an style=3D"color:#000">i </span><span style=3D"color:#660">=3D=3D</span><s=
pan style=3D"color:#000"> </span><span style=3D"color:#066">1</span><span s=
tyle=3D"color:#660">)</span><span style=3D"color:#000"> </span><span style=
=3D"color:#660">{</span></div><div style=3D"font-family:Arial,Helvetica,san=
s-serif"><span style=3D"color:#000"> =C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><sp=
an style=3D"color:#008">return</span><span style=3D"color:#000"> wrap</span=
><span style=3D"color:#660"><</span><span style=3D"color:#606">SecondTyp=
e</span><span style=3D"color:#660">>{};</span></div><div style=3D"font-f=
amily:Arial,Helvetica,sans-serif"><span style=3D"color:#000"> =C2=A0 =C2=A0=
</span><span style=3D"color:#660">}</span><span style=3D"color:#000"> </sp=
an><span style=3D"color:#008">else</span><span style=3D"color:#000"> </span=
><span style=3D"color:#008">if</span><span style=3D"color:#000"> </span><sp=
an style=3D"color:#008">constexpr</span><span style=3D"color:#000"> </span>=
<span style=3D"color:#660">(</span><span style=3D"color:#000">i </span><spa=
n style=3D"color:#660">=3D=3D</span><span style=3D"color:#000"> </span><spa=
n style=3D"color:#066">2</span><span style=3D"color:#660">)</span><span sty=
le=3D"color:#000"> </span><span style=3D"color:#660">{</span></div><div sty=
le=3D"font-family:Arial,Helvetica,sans-serif"><span style=3D"color:#000"> =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#008">return</span>=
<span style=3D"color:#000"> wrap</span><span style=3D"color:#660"><</spa=
n><span style=3D"color:#606">ThirdType</span><span style=3D"color:#660">>=
;{};</span></div><div style=3D"font-family:Arial,Helvetica,sans-serif"><spa=
n style=3D"color:#000"> =C2=A0 =C2=A0 </span><span style=3D"color:#660">}</=
span></div><div style=3D"font-family:Arial,Helvetica,sans-serif"><span styl=
e=3D"color:#660">}</span></div><div style=3D"font-family:Arial,Helvetica,sa=
ns-serif"><span style=3D"color:#000"><br></span></div><div style=3D"font-fa=
mily:Arial,Helvetica,sans-serif"><span style=3D"color:#008">template</span>=
<span style=3D"color:#660"><</span><span style=3D"color:#008">int</span>=
<span style=3D"color:#000"> i</span><span style=3D"color:#660">></span><=
span style=3D"color:#000"> </span><span style=3D"color:#008">using</span><s=
pan style=3D"color:#000"> </span><span style=3D"color:#606">MyType</span><s=
pan style=3D"color:#000"> </span><span style=3D"color:#660">=3D</span><span=
style=3D"color:#000"> unwrap</span><span style=3D"color:#660"><</span><=
span style=3D"color:#008">decltype</span><span style=3D"color:#660">(</span=
><span style=3D"color:#000">helper</span><span style=3D"color:#080"><i&g=
t;</span><span style=3D"color:#660">())>;</span></div></div></code></div=
><div><br></div>is more readable than:</div><div><br></div><div><div style=
=3D"background-color:rgb(250,250,250);border:1px solid rgb(187,187,187);wor=
d-wrap:break-word"><code><div><font><span style=3D"color:#008">template</sp=
an><span style=3D"color:#660"><</span><span style=3D"color:#008">int</sp=
an><font color=3D"#000000"><span style=3D"color:#000"> i</span><span style=
=3D"color:#660">></span><span style=3D"color:#000"><br></span><span styl=
e=3D"color:#008">using</span><span style=3D"color:#000"> </span><span style=
=3D"color:#606">MyType</span><span style=3D"color:#000"> </span><span style=
=3D"color:#660">=3D</span><span style=3D"color:#000"> meta_switch_t</span><=
span style=3D"color:#660"><</span><span><span style=3D"color:#000">i</sp=
an><span style=3D"color:#660">,</span><span style=3D"color:#000"><br>=C2=A0=
=C2=A0 meta_case</span><span style=3D"color:#660"><</span><span style=
=3D"color:#066">0</span><span style=3D"color:#660">,</span><span style=3D"c=
olor:#000"> </span><span style=3D"color:#606">FirstType</span><span style=
=3D"color:#660">>,</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 me=
ta_case</span><span style=3D"color:#660"><</span><span style=3D"color:#0=
66">1</span><span style=3D"color:#660">,</span><span style=3D"color:#000"> =
</span><span style=3D"color:#606">SecondType</span><span style=3D"color:#66=
0">>,</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 meta_case</span=
><span style=3D"color:#660"><</span><span style=3D"color:#066">2</span><=
span style=3D"color:#660">,</span><span style=3D"color:#000"> </span><span =
style=3D"color:#606">ThirdType</span><span style=3D"color:#660">></span>=
<span style=3D"color:#000"><br></span><span style=3D"color:#660">>;</spa=
n></span></font></font></div></code></div><div><br></div>The latter clearly=
expresses intent of declaring a type based on the value of the template pa=
rameter. Whereas the former introduces a bunch of seemly unrelated things (=
wrappers, unwrappers, a helper function) and is far more difficult to reaso=
n about.<br></div></div></blockquote><div><br></div><div>Since we're ta=
rgeting C++20, we can reasonably assume that an identity metafunction (P088=
7) will be available, removing the need for wrap/unwrap, and that lambdas i=
n unevaluated contexts (P0315) will be allowed, removing the need for a hel=
per function:</div><div><br></div><div><div style=3D"color: #000000;backgro=
und-color: #fffffe;font-family: Consolas, " liberation=3D"" mono",=3D"" cou=
rier,=3D"" monospace;font-weight:=3D"" normal;font-size:=3D"" 12.5411327999=
99998px;line-height:=3D"" 17px;white-space:=3D"" pre;"=3D""><div class=3D"p=
rettyprint" style=3D"background-color: rgb(250, 250, 250); border-color: rg=
b(187, 187, 187); border-style: solid; border-width: 1px; word-wrap: break-=
word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">template</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify"><</span><span style=3D"co=
lor: #008;" class=3D"styled-by-prettify">int</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> i</span><span style=3D"color: #660;" cla=
ss=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">using</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">=
MyType</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">typename</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #008;" class=3D"styled-by-prettify">decltype</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">([]{</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify"><br>=C2=A0 </span><span style=3D"color: #008;=
" class=3D"styled-by-prettify">if</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">constexpr</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify">i </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D=
=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span style=3D"color: #066;" class=3D"styled-by-prettify">0</span><span st=
yle=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: #008=
;" class=3D"styled-by-prettify">return</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> identity</span><span style=3D"color: #080;" cl=
ass=3D"styled-by-prettify"><int></span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">{};</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"><br>=C2=A0 </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">else</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-p=
rettify">if</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">constexp=
r</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify">i </span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">=3D=3D</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #066;" cl=
ass=3D"styled-by-prettify">1</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">)</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">=
return</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> ide=
ntity</span><span style=3D"color: #080;" class=3D"styled-by-prettify"><c=
har></span><span style=3D"color: #660;" class=3D"styled-by-prettify">{};=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0=
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">else</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">if</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #0=
08;" class=3D"styled-by-prettify">constexpr</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">i </span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">=3D=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> </span><span style=3D"color: #066;" class=3D"styled-by-prettify">2</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">)</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">return</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> identity</span><span style=3D"color:=
#080;" class=3D"styled-by-prettify"><float></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: #660;" cl=
ass=3D"styled-by-prettify">}())::</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">type</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">;</span></div></code></div><div><br></div><div><span styl=
e=3D"color: #0000ff;"></span></div></div></div><div>Perhaps this is still l=
ess clear than a dedicated metafunction; but on the other hand there's =
less library code here to understand.</div><div><br></div><div>There's =
also the option of using tuple (where the cases are integral and contiguous=
), or overload (P0051).</div><div>=C2=A0</div><blockquote class=3D"gmail_qu=
ote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padd=
ing-left: 1ex;"><div dir=3D"ltr"><blockquote class=3D"gmail_quote" style=3D=
"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><d=
iv dir=3D"ltr"><div class=3D"gmail_quote"><div><div>- I think the benefit o=
f this proposal is low, because anecdotally, I personally have no use-cases=
for the proposed feature.</div></div></div></div></blockquote><div><br></d=
iv><div>Do you have use-cases for meta-maps and the other stuff that this s=
upposedly gets in the way of?</div><div><br></div><div><br></div><div><br><=
/div><blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;=
border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div class=3D=
"gmail_quote"><div></div><div>The <i>cost</i> is not particularly high, but=
I just don't see the <i>benefit</i> here to justify moving this helper=
class from "20 lines of C++ in Hamza's codebase" to "40=
lines of English in the ISO Standard."</div></div></div></blockquote>=
<div><br></div><div>The benefit is very similar to that of std::conditional=
.. It's not like you'll be using it constantly, but it's very ni=
ce to have on those few occasions.</div></div></blockquote><div><br></div><=
div>std::conditional is essential to metaprogramming and is difficult and a=
rcane to emulate, especially in C++11. A type switch is a lot less essentia=
l.</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/e29798f6-2e2a-4816-bc17-677ba5238702%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/e29798f6-2e2a-4816-bc17-677ba5238702=
%40isocpp.org</a>.<br />
------=_Part_3454_92337352.1522346942525--
------=_Part_3453_806152814.1522346942523--
.
Author: hamza_sood@me.com
Date: Thu, 29 Mar 2018 12:03:59 -0700 (PDT)
Raw View
------=_Part_3599_42048533.1522350239482
Content-Type: multipart/alternative;
boundary="----=_Part_3600_72250651.1522350239483"
------=_Part_3600_72250651.1522350239483
Content-Type: text/plain; charset="UTF-8"
> In this case, "meta_" as a prefix (effectively a namespace) for
> metaprogramming. This is inconsistent when we are not using this prefix
> elsewhere in the metaprogramming library.
>
>
Yeah, the name is really bad. Happy to hear any alternatives.
Since we're targeting C++20, we can reasonably assume that an identity
> metafunction (P0887) will be available, removing the need for wrap/unwrap,
> and that lambdas in unevaluated contexts (P0315) will be allowed, removing
> the need for a helper function:
>
> template<int i>
> using MyType = typename decltype([]{
> if constexpr(i == 0) return identity<int>{};
> else if constexpr (i == 1) return identity<char>{};
> else if constexpr (i == 2) return identity<float>{};
> }())::type;
>
> Perhaps this is still less clear than a dedicated metafunction; but on the
> other hand there's less library code here to understand.
>
> There's also the option of using tuple (where the cases are integral and
> contiguous), or overload (P0051).
>
That does look a lot better. However by that logic, couldn't you argue that
we don't need std::conditional?
template<bool flag>
using MyType = typename decltype([]{
if constexpr (flag) return identity<int>{};
else return identity<float>{};
}())::type
std::conditional is essential to metaprogramming and is difficult and
> arcane to emulate, especially in C++11. A type switch is a lot less
> essential.
>
Sure, it's definitely far from essential. What're your thoughts on its
usefulness? It's very difficult to come up with a motivating example that
isn't incredibly specific (which is true for a lot of meta-programming
stuff).
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/d48673ff-90f5-4bab-b2a3-65205e4b6ee3%40isocpp.org.
------=_Part_3600_72250651.1522350239483
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><blockquote class=3D"gmail_quote" style=3D"margin: 0;m=
argin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=
=3D"ltr"><div>In this case, "meta_" as a prefix (effectively a na=
mespace) for metaprogramming. This is inconsistent when we are not using th=
is prefix elsewhere in the metaprogramming library.</div><div>=C2=A0</div><=
/div></blockquote><div>=C2=A0</div><div>Yeah, the name is really bad. Happy=
to hear any alternatives.</div><div><br></div><div><br></div><div><br></di=
v><div><br></div><blockquote class=3D"gmail_quote" style=3D"margin: 0;margi=
n-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"l=
tr"><div>Since we're targeting C++20, we can reasonably assume that an =
identity metafunction (P0887) will be available, removing the need for wrap=
/unwrap, and that lambdas in unevaluated contexts (P0315) will be allowed, =
removing the need for a helper function:</div><div><br></div><div><div><div=
style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,187);b=
order-style:solid;border-width:1px;word-wrap:break-word"><code><div><span s=
tyle=3D"color:#008">template</span><span style=3D"color:#660"><</span><s=
pan style=3D"color:#008">int</span><span style=3D"color:#000"> i</span><spa=
n style=3D"color:#660">></span><span style=3D"color:#000"><br></span><sp=
an style=3D"color:#008">using</span><span style=3D"color:#000"> </span><spa=
n style=3D"color:#606">MyType</span><span style=3D"color:#000"> </span><spa=
n style=3D"color:#660">=3D</span><span style=3D"color:#000"> </span><span s=
tyle=3D"color:#008">typename</span><span style=3D"color:#000"> </span><span=
style=3D"color:#008">decltype</span><span style=3D"color:#660">([]{</span>=
<span style=3D"color:#000"><br>=C2=A0 </span><span style=3D"color:#008">if<=
/span><span style=3D"color:#000"> </span><span style=3D"color:#008">constex=
pr</span><span style=3D"color:#660">(</span><span style=3D"color:#000">i </=
span><span style=3D"color:#660">=3D=3D</span><span style=3D"color:#000"> </=
span><span style=3D"color:#066">0</span><span style=3D"color:#660">)</span>=
<span style=3D"color:#000"> </span><span style=3D"color:#008">return</span>=
<span style=3D"color:#000"> identity</span><span style=3D"color:#080"><i=
nt></span><span style=3D"color:#660">{};</span><span style=3D"color:#000=
"><br>=C2=A0 </span><span style=3D"color:#008">else</span><span style=3D"co=
lor:#000"> </span><span style=3D"color:#008">if</span><span style=3D"color:=
#000"> </span><span style=3D"color:#008">constexpr</span><span style=3D"col=
or:#000"> </span><span style=3D"color:#660">(</span><span style=3D"color:#0=
00">i </span><span style=3D"color:#660">=3D=3D</span><span style=3D"color:#=
000"> </span><span style=3D"color:#066">1</span><span style=3D"color:#660">=
)</span><span style=3D"color:#000"> </span><span style=3D"color:#008">retur=
n</span><span style=3D"color:#000"> identity</span><span style=3D"color:#08=
0"><char></span><span style=3D"color:#660">{};</span><span style=3D"c=
olor:#000"><br>=C2=A0 </span><span style=3D"color:#008">else</span><span st=
yle=3D"color:#000"> </span><span style=3D"color:#008">if</span><span style=
=3D"color:#000"> </span><span style=3D"color:#008">constexpr</span><span st=
yle=3D"color:#000"> </span><span style=3D"color:#660">(</span><span style=
=3D"color:#000">i </span><span style=3D"color:#660">=3D=3D</span><span styl=
e=3D"color:#000"> </span><span style=3D"color:#066">2</span><span style=3D"=
color:#660">)</span><span style=3D"color:#000"> </span><span style=3D"color=
:#008">return</span><span style=3D"color:#000"> identity</span><span style=
=3D"color:#080"><float></span><span style=3D"color:#660">{};</span><s=
pan style=3D"color:#000"><br></span><span style=3D"color:#660">}())::</span=
><span style=3D"color:#000">type</span><span style=3D"color:#660">;</span><=
/div></code></div><div><br></div><div><span style=3D"color:#0000ff"></span>=
</div></div></div><div>Perhaps this is still less clear than a dedicated me=
tafunction; but on the other hand there's less library code here to und=
erstand.</div><div><br></div><div>There's also the option of using tupl=
e (where the cases are integral and contiguous), or overload (P0051).</div>=
</div></blockquote><div>=C2=A0</div><div>That does look a lot better. Howev=
er by that logic, couldn't you argue that we don't need std::condit=
ional?</div><div><div class=3D"prettyprint" style=3D"background-color: rgb(=
250, 250, 250); border: 1px solid rgb(187, 187, 187); word-wrap: break-word=
;"><code class=3D"prettyprint"><div class=3D"subprettyprint" style=3D"caret=
-color: rgb(102, 0, 102);"><font color=3D"#660066"><span style=3D"color: #0=
08;" class=3D"styled-by-prettify">template</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify"><</span><span style=3D"color: #008;" cla=
ss=3D"styled-by-prettify">bool</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> flag</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">></span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br></span><span style=3D"color: #008;" class=3D"styled-by-prettif=
y">using</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> <=
/span><span style=3D"color: #606;" class=3D"styled-by-prettify">MyType</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #=
008;" class=3D"styled-by-prettify">typename</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">decltype</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">([]{</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br>=C2=A0 </span><span style=3D"color: #008;" class=3D"s=
tyled-by-prettify">if</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify=
">constexpr</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">flag</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: #0=
08;" class=3D"styled-by-prettify">return</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify"> identity</span><span style=3D"color: #080;" =
class=3D"styled-by-prettify"><int></span><span style=3D"color: #660;"=
class=3D"styled-by-prettify">{};</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br>=C2=A0 </span><span style=3D"color: #008;" clas=
s=3D"styled-by-prettify">else</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-=
prettify">return</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> identity</span><span style=3D"color: #080;" class=3D"styled-by-prett=
ify"><float></span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">{};</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">type</spa=
n></font></div></code></div><br><br></div><div><br></div><div><br></div><bl=
ockquote 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>std::condit=
ional is essential to metaprogramming and is difficult and arcane to emulat=
e, especially in C++11. A type switch is a lot less essential.</div></div><=
/blockquote><div><br></div><div>Sure, it's definitely far from essentia=
l. What're your thoughts on its usefulness? It's very difficult to =
come up with a motivating example that isn't incredibly specific (which=
is true for a lot of meta-programming stuff).</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/d48673ff-90f5-4bab-b2a3-65205e4b6ee3%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/d48673ff-90f5-4bab-b2a3-65205e4b6ee3=
%40isocpp.org</a>.<br />
------=_Part_3600_72250651.1522350239483--
------=_Part_3599_42048533.1522350239482--
.
Author: =?UTF-8?Q?Micha=C5=82_Dominiak?= <griwes@griwes.info>
Date: Thu, 29 Mar 2018 19:50:24 +0000
Raw View
--001a114dd4d0dedbe50568926fa2
Content-Type: text/plain; charset="UTF-8"
On Thu, Mar 29, 2018, 9:04 PM <hamza_sood@me.com> wrote:
>
> In this case, "meta_" as a prefix (effectively a namespace) for
>> metaprogramming. This is inconsistent when we are not using this prefix
>> elsewhere in the metaprogramming library.
>>
>>
>
> Yeah, the name is really bad. Happy to hear any alternatives.
>
>
>
>
> Since we're targeting C++20, we can reasonably assume that an identity
>> metafunction (P0887) will be available, removing the need for wrap/unwrap,
>> and that lambdas in unevaluated contexts (P0315) will be allowed, removing
>> the need for a helper function:
>>
>> template<int i>
>> using MyType = typename decltype([]{
>> if constexpr(i == 0) return identity<int>{};
>> else if constexpr (i == 1) return identity<char>{};
>> else if constexpr (i == 2) return identity<float>{};
>> }())::type;
>>
>> Perhaps this is still less clear than a dedicated metafunction; but on
>> the other hand there's less library code here to understand.
>>
>> There's also the option of using tuple (where the cases are integral and
>> contiguous), or overload (P0051).
>>
>
> That does look a lot better. However by that logic, couldn't you argue
> that we don't need std::conditional?
> template<bool flag>
>
> using MyType = typename decltype([]{
>
> if constexpr (flag) return identity<int>{};
> else return identity<float>{};
> }())::type
>
Your argument is invalid, since you are comparing apples and oranges -
std::conditional has been there since C++11.
>
> std::conditional is essential to metaprogramming and is difficult and
>> arcane to emulate, especially in C++11. A type switch is a lot less
>> essential.
>>
>
> Sure, it's definitely far from essential. What're your thoughts on its
> usefulness? It's very difficult to come up with a motivating example that
> isn't incredibly specific (which is true for a lot of meta-programming
> stuff).
>
> --
> You received this message because you are subscribed to the Google Groups
> "ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to std-proposals+unsubscribe@isocpp.org.
> To post to this group, send email to std-proposals@isocpp.org.
> To view this discussion on the web visit
> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/d48673ff-90f5-4bab-b2a3-65205e4b6ee3%40isocpp.org
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/d48673ff-90f5-4bab-b2a3-65205e4b6ee3%40isocpp.org?utm_medium=email&utm_source=footer>
> .
>
--
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/CAPCFJdQozg-v9%2B%2BQuB4nbhPPuxx3UX36rQtsr%2BJZPt0PX8Eqcg%40mail.gmail.com.
--001a114dd4d0dedbe50568926fa2
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<br><br><div class=3D"gmail_quote"><div dir=3D"ltr">On Thu, Mar 29, 2018, 9=
:04 PM <<a href=3D"mailto:hamza_sood@me.com">hamza_sood@me.com</a>> =
wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8e=
x;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><br><blockq=
uote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:=
1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div>In this case, "=
meta_" as a prefix (effectively a namespace) for metaprogramming. This=
is inconsistent when we are not using this prefix elsewhere in the metapro=
gramming library.</div><div>=C2=A0</div></div></blockquote><div>=C2=A0</div=
></div><div dir=3D"ltr"><div>Yeah, the name is really bad. Happy to hear an=
y alternatives.</div></div><div dir=3D"ltr"><div><br></div><div><br></div><=
div><br></div><div><br></div><blockquote class=3D"gmail_quote" style=3D"mar=
gin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div d=
ir=3D"ltr"><div>Since we're targeting C++20, we can reasonably assume t=
hat an identity metafunction (P0887) will be available, removing the need f=
or wrap/unwrap, and that lambdas in unevaluated contexts (P0315) will be al=
lowed, removing the need for a helper function:</div><div><br></div><div><d=
iv><div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187=
,187);border-style:solid;border-width:1px;word-wrap:break-word"><code><div>=
<span style=3D"color:#008">template</span><span style=3D"color:#660"><</=
span><span style=3D"color:#008">int</span><span style=3D"color:#000"> i</sp=
an><span style=3D"color:#660">></span><span style=3D"color:#000"><br></s=
pan><span style=3D"color:#008">using</span><span style=3D"color:#000"> </sp=
an><span style=3D"color:#606">MyType</span><span style=3D"color:#000"> </sp=
an><span style=3D"color:#660">=3D</span><span style=3D"color:#000"> </span>=
<span style=3D"color:#008">typename</span><span style=3D"color:#000"> </spa=
n><span style=3D"color:#008">decltype</span><span style=3D"color:#660">([]{=
</span><span style=3D"color:#000"><br>=C2=A0 </span><span style=3D"color:#0=
08">if</span><span style=3D"color:#000"> </span><span style=3D"color:#008">=
constexpr</span><span style=3D"color:#660">(</span><span style=3D"color:#00=
0">i </span><span style=3D"color:#660">=3D=3D</span><span style=3D"color:#0=
00"> </span><span style=3D"color:#066">0</span><span style=3D"color:#660">)=
</span><span style=3D"color:#000"> </span><span style=3D"color:#008">return=
</span><span style=3D"color:#000"> identity</span><span style=3D"color:#080=
"><int></span><span style=3D"color:#660">{};</span><span style=3D"col=
or:#000"><br>=C2=A0 </span><span style=3D"color:#008">else</span><span styl=
e=3D"color:#000"> </span><span style=3D"color:#008">if</span><span style=3D=
"color:#000"> </span><span style=3D"color:#008">constexpr</span><span style=
=3D"color:#000"> </span><span style=3D"color:#660">(</span><span style=3D"c=
olor:#000">i </span><span style=3D"color:#660">=3D=3D</span><span style=3D"=
color:#000"> </span><span style=3D"color:#066">1</span><span style=3D"color=
:#660">)</span><span style=3D"color:#000"> </span><span style=3D"color:#008=
">return</span><span style=3D"color:#000"> identity</span><span style=3D"co=
lor:#080"><char></span><span style=3D"color:#660">{};</span><span sty=
le=3D"color:#000"><br>=C2=A0 </span><span style=3D"color:#008">else</span><=
span style=3D"color:#000"> </span><span style=3D"color:#008">if</span><span=
style=3D"color:#000"> </span><span style=3D"color:#008">constexpr</span><s=
pan style=3D"color:#000"> </span><span style=3D"color:#660">(</span><span s=
tyle=3D"color:#000">i </span><span style=3D"color:#660">=3D=3D</span><span =
style=3D"color:#000"> </span><span style=3D"color:#066">2</span><span style=
=3D"color:#660">)</span><span style=3D"color:#000"> </span><span style=3D"c=
olor:#008">return</span><span style=3D"color:#000"> identity</span><span st=
yle=3D"color:#080"><float></span><span style=3D"color:#660">{};</span=
><span style=3D"color:#000"><br></span><span style=3D"color:#660">}())::</s=
pan><span style=3D"color:#000">type</span><span style=3D"color:#660">;</spa=
n></div></code></div><div><br></div><div><span style=3D"color:#0000ff"></sp=
an></div></div></div><div>Perhaps this is still less clear than a dedicated=
metafunction; but on the other hand there's less library code here to =
understand.</div><div><br></div><div>There's also the option of using t=
uple (where the cases are integral and contiguous), or overload (P0051).</d=
iv></div></blockquote><div>=C2=A0</div></div><div dir=3D"ltr"><div>That doe=
s look a lot better. However by that logic, couldn't you argue that we =
don't need std::conditional?</div><div><div class=3D"m_8124809658938814=
543prettyprint" style=3D"background-color:rgb(250,250,250);border:1px solid=
rgb(187,187,187);word-wrap:break-word"><code class=3D"m_812480965893881454=
3prettyprint"><div class=3D"m_8124809658938814543subprettyprint"><font colo=
r=3D"#660066"><span style=3D"color:#008" class=3D"m_8124809658938814543styl=
ed-by-prettify">template</span><span style=3D"color:#660" class=3D"m_812480=
9658938814543styled-by-prettify"><</span><span style=3D"color:#008" clas=
s=3D"m_8124809658938814543styled-by-prettify">bool</span><span style=3D"col=
or:#000" class=3D"m_8124809658938814543styled-by-prettify"> flag</span><spa=
n style=3D"color:#660" class=3D"m_8124809658938814543styled-by-prettify">&g=
t;</span></font></div></code></div></div></div><div dir=3D"ltr"><div><div c=
lass=3D"m_8124809658938814543prettyprint" style=3D"background-color:rgb(250=
,250,250);border:1px solid rgb(187,187,187);word-wrap:break-word"><code cla=
ss=3D"m_8124809658938814543prettyprint"><div class=3D"m_8124809658938814543=
subprettyprint"><font color=3D"#660066"><span style=3D"color:#000" class=3D=
"m_8124809658938814543styled-by-prettify"><br></span><span style=3D"color:#=
008" class=3D"m_8124809658938814543styled-by-prettify">using</span><span st=
yle=3D"color:#000" class=3D"m_8124809658938814543styled-by-prettify"> </spa=
n><span style=3D"color:#606" class=3D"m_8124809658938814543styled-by-pretti=
fy">MyType</span><span style=3D"color:#000" class=3D"m_8124809658938814543s=
tyled-by-prettify"> </span><span style=3D"color:#660" class=3D"m_8124809658=
938814543styled-by-prettify">=3D</span><span style=3D"color:#000" class=3D"=
m_8124809658938814543styled-by-prettify"> </span><span style=3D"color:#008"=
class=3D"m_8124809658938814543styled-by-prettify">typename</span><span sty=
le=3D"color:#000" class=3D"m_8124809658938814543styled-by-prettify"> </span=
><span style=3D"color:#008" class=3D"m_8124809658938814543styled-by-prettif=
y">decltype</span><span style=3D"color:#660" class=3D"m_8124809658938814543=
styled-by-prettify">([]{</span></font></div></code></div></div></div><div d=
ir=3D"ltr"><div><div class=3D"m_8124809658938814543prettyprint" style=3D"ba=
ckground-color:rgb(250,250,250);border:1px solid rgb(187,187,187);word-wrap=
:break-word"><code class=3D"m_8124809658938814543prettyprint"><div class=3D=
"m_8124809658938814543subprettyprint"><font color=3D"#660066"><span style=
=3D"color:#000" class=3D"m_8124809658938814543styled-by-prettify"><br>=C2=
=A0 </span><span style=3D"color:#008" class=3D"m_8124809658938814543styled-=
by-prettify">if</span><span style=3D"color:#000" class=3D"m_812480965893881=
4543styled-by-prettify"> </span><span style=3D"color:#008" class=3D"m_81248=
09658938814543styled-by-prettify">constexpr</span><span style=3D"color:#000=
" class=3D"m_8124809658938814543styled-by-prettify"> </span><span style=3D"=
color:#660" class=3D"m_8124809658938814543styled-by-prettify">(</span><span=
style=3D"color:#000" class=3D"m_8124809658938814543styled-by-prettify">fla=
g</span><span style=3D"color:#660" class=3D"m_8124809658938814543styled-by-=
prettify">)</span><span style=3D"color:#000" class=3D"m_8124809658938814543=
styled-by-prettify"> </span><span style=3D"color:#008" class=3D"m_812480965=
8938814543styled-by-prettify">return</span><span style=3D"color:#000" class=
=3D"m_8124809658938814543styled-by-prettify"> identity</span><span style=3D=
"color:#080" class=3D"m_8124809658938814543styled-by-prettify"><int><=
/span><span style=3D"color:#660" class=3D"m_8124809658938814543styled-by-pr=
ettify">{};</span><span style=3D"color:#000" class=3D"m_8124809658938814543=
styled-by-prettify"><br>=C2=A0 </span><span style=3D"color:#008" class=3D"m=
_8124809658938814543styled-by-prettify">else</span><span style=3D"color:#00=
0" class=3D"m_8124809658938814543styled-by-prettify"> </span><span style=3D=
"color:#008" class=3D"m_8124809658938814543styled-by-prettify">return</span=
><span style=3D"color:#000" class=3D"m_8124809658938814543styled-by-prettif=
y"> identity</span><span style=3D"color:#080" class=3D"m_812480965893881454=
3styled-by-prettify"><float></span><span style=3D"color:#660" class=
=3D"m_8124809658938814543styled-by-prettify">{};</span><span style=3D"color=
:#000" class=3D"m_8124809658938814543styled-by-prettify"><br></span><span s=
tyle=3D"color:#660" class=3D"m_8124809658938814543styled-by-prettify">}()):=
:</span><span style=3D"color:#000" class=3D"m_8124809658938814543styled-by-=
prettify">type</span></font></div></code></div></div><div></div></div></blo=
ckquote></div><div><br></div><div><br></div><div>Your argument is invalid, =
since you are comparing apples and oranges - std::conditional has been ther=
e since C++11.</div><div><br></div><div class=3D"gmail_quote"><blockquote c=
lass=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;=
padding-left:1ex"><div dir=3D"ltr"><div><br></div></div><div dir=3D"ltr"><d=
iv><br></div><blockquote class=3D"gmail_quote" style=3D"margin:0;margin-lef=
t:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div>=
std::conditional is essential to metaprogramming and is difficult and arcan=
e to emulate, especially in C++11. A type switch is a lot less essential.</=
div></div></blockquote><div><br></div></div><div dir=3D"ltr"><div>Sure, it&=
#39;s definitely far from essential. What're your thoughts on its usefu=
lness? It's very difficult to come up with a motivating example that is=
n't incredibly specific (which is true for a lot of meta-programming st=
uff).</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" target=3D"_=
blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">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/d48673ff-90f5-4bab-b2a3-65205e4b6ee3%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" target=3D"_blank">=
https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/d48673ff-90f5-=
4bab-b2a3-65205e4b6ee3%40isocpp.org</a>.<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/CAPCFJdQozg-v9%2B%2BQuB4nbhPPuxx3UX36=
rQtsr%2BJZPt0PX8Eqcg%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfoote=
r">https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAPCFJdQozg=
-v9%2B%2BQuB4nbhPPuxx3UX36rQtsr%2BJZPt0PX8Eqcg%40mail.gmail.com</a>.<br />
--001a114dd4d0dedbe50568926fa2--
.
Author: "'Edward Catmur' via ISO C++ Standard - Future Proposals" <std-proposals@isocpp.org>
Date: Thu, 29 Mar 2018 19:57:42 +0000
Raw View
--001a114c184cfad06605689289ae
Content-Type: text/plain; charset="UTF-8"
On Thu, 29 Mar 2018, 20:04 , <hamza_sood@me.com> wrote:
>
> In this case, "meta_" as a prefix (effectively a namespace) for
>> metaprogramming. This is inconsistent when we are not using this prefix
>> elsewhere in the metaprogramming library.
>>
>>
>
> Yeah, the name is really bad. Happy to hear any alternatives.
>
>
>
>
> Since we're targeting C++20, we can reasonably assume that an identity
>> metafunction (P0887) will be available, removing the need for wrap/unwrap,
>> and that lambdas in unevaluated contexts (P0315) will be allowed, removing
>> the need for a helper function:
>>
>> template<int i>
>> using MyType = typename decltype([]{
>> if constexpr(i == 0) return identity<int>{};
>> else if constexpr (i == 1) return identity<char>{};
>> else if constexpr (i == 2) return identity<float>{};
>> }())::type;
>>
>> Perhaps this is still less clear than a dedicated metafunction; but on
>> the other hand there's less library code here to understand.
>>
>> There's also the option of using tuple (where the cases are integral and
>> contiguous), or overload (P0051).
>>
>
> That does look a lot better. However by that logic, couldn't you argue
> that we don't need std::conditional?
> template<bool flag>
> using MyType = typename decltype([]{
> if constexpr (flag) return identity<int>{};
> else return identity<float>{};
> }())::type
>
Well, yes! We didn't have if constexpr back then, nor return type deduction
in ordinary functions.
At the same time, a meta switch would have been clunkier in the library of
the time as we didn't have auto template parameters so one would have to
repeatedly specify the integral type.
> std::conditional is essential to metaprogramming and is difficult and
>> arcane to emulate, especially in C++11. A type switch is a lot less
>> essential.
>>
>
> Sure, it's definitely far from essential. What're your thoughts on its
> usefulness? It's very difficult to come up with a motivating example that
> isn't incredibly specific (which is true for a lot of meta-programming
> stuff).
>
The answer is to come up with plenty of specific examples. Look in open
source code for heavily nested conditionals, or use of MPL maps etc, that
could be improved by the use of a meta switch facility.
--
> You received this message because you are subscribed to a topic in the
> Google Groups "ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/a/isocpp.org/d/topic/std-proposals/NReFie_9Zy4/unsubscribe
> .
> To unsubscribe from this group and all its topics, 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/d48673ff-90f5-4bab-b2a3-65205e4b6ee3%40isocpp.org
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/d48673ff-90f5-4bab-b2a3-65205e4b6ee3%40isocpp.org?utm_medium=email&utm_source=footer>
> .
>
--
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/CAJnLdOY8MDzE6s0oZ0gNKUG0%2BzQgLLn9pVgyGVjTO1XMxsNvzA%40mail.gmail.com.
--001a114c184cfad06605689289ae
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"auto"><div><br><br><div class=3D"gmail_quote"><div dir=3D"ltr">=
On Thu, 29 Mar 2018, 20:04 , <<a href=3D"mailto:hamza_sood@me.com" targe=
t=3D"_blank" rel=3D"noreferrer">hamza_sood@me.com</a>> wrote:<br></div><=
blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px=
#ccc solid;padding-left:1ex"><div dir=3D"ltr"><br><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"><div>In this case, "meta_" as a =
prefix (effectively a namespace) for metaprogramming. This is inconsistent =
when we are not using this prefix elsewhere in the metaprogramming library.=
</div><div>=C2=A0</div></div></blockquote><div>=C2=A0</div><div>Yeah, the n=
ame is really bad. Happy to hear any alternatives.</div><div><br></div><div=
><br></div><div><br></div><div><br></div><blockquote class=3D"gmail_quote" =
style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left=
:1ex"><div dir=3D"ltr"><div>Since we're targeting C++20, we can reasona=
bly assume that an identity metafunction (P0887) will be available, removin=
g the need for wrap/unwrap, and that lambdas in unevaluated contexts (P0315=
) will be allowed, removing the need for a helper function:</div><div><br><=
/div><div><div><div style=3D"background-color:rgb(250,250,250);border-color=
:rgb(187,187,187);border-style:solid;border-width:1px;word-wrap:break-word"=
><code><div><span style=3D"color:#008">template</span><span style=3D"color:=
#660"><</span><span style=3D"color:#008">int</span><span style=3D"color:=
#000"> i</span><span style=3D"color:#660">></span><span style=3D"color:#=
000"><br></span><span style=3D"color:#008">using</span><span style=3D"color=
:#000"> </span><span style=3D"color:#606">MyType</span><span style=3D"color=
:#000"> </span><span style=3D"color:#660">=3D</span><span style=3D"color:#0=
00"> </span><span style=3D"color:#008">typename</span><span style=3D"color:=
#000"> </span><span style=3D"color:#008">decltype</span><span style=3D"colo=
r:#660">([]{</span><span style=3D"color:#000"><br>=C2=A0 </span><span style=
=3D"color:#008">if</span><span style=3D"color:#000"> </span><span style=3D"=
color:#008">constexpr</span><span style=3D"color:#660">(</span><span style=
=3D"color:#000">i </span><span style=3D"color:#660">=3D=3D</span><span styl=
e=3D"color:#000"> </span><span style=3D"color:#066">0</span><span style=3D"=
color:#660">)</span><span style=3D"color:#000"> </span><span style=3D"color=
:#008">return</span><span style=3D"color:#000"> identity</span><span style=
=3D"color:#080"><int></span><span style=3D"color:#660">{};</span><spa=
n style=3D"color:#000"><br>=C2=A0 </span><span style=3D"color:#008">else</s=
pan><span style=3D"color:#000"> </span><span style=3D"color:#008">if</span>=
<span style=3D"color:#000"> </span><span style=3D"color:#008">constexpr</sp=
an><span style=3D"color:#000"> </span><span style=3D"color:#660">(</span><s=
pan style=3D"color:#000">i </span><span style=3D"color:#660">=3D=3D</span><=
span style=3D"color:#000"> </span><span style=3D"color:#066">1</span><span =
style=3D"color:#660">)</span><span style=3D"color:#000"> </span><span style=
=3D"color:#008">return</span><span style=3D"color:#000"> identity</span><sp=
an style=3D"color:#080"><char></span><span style=3D"color:#660">{};</=
span><span style=3D"color:#000"><br>=C2=A0 </span><span style=3D"color:#008=
">else</span><span style=3D"color:#000"> </span><span style=3D"color:#008">=
if</span><span style=3D"color:#000"> </span><span style=3D"color:#008">cons=
texpr</span><span style=3D"color:#000"> </span><span style=3D"color:#660">(=
</span><span style=3D"color:#000">i </span><span style=3D"color:#660">=3D=
=3D</span><span style=3D"color:#000"> </span><span style=3D"color:#066">2</=
span><span style=3D"color:#660">)</span><span style=3D"color:#000"> </span>=
<span style=3D"color:#008">return</span><span style=3D"color:#000"> identit=
y</span><span style=3D"color:#080"><float></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">type</span><span style=3D"co=
lor:#660">;</span></div></code></div><div><br></div><div><span style=3D"col=
or:#0000ff"></span></div></div></div><div>Perhaps this is still less clear =
than a dedicated metafunction; but on the other hand there's less libra=
ry code here to understand.</div><div><br></div><div>There's also the o=
ption of using tuple (where the cases are integral and contiguous), or over=
load (P0051).</div></div></blockquote><div>=C2=A0</div><div>That does look =
a lot better. However by that logic, couldn't you argue that we don'=
;t need std::conditional?</div><div><div class=3D"m_520478396758981582m_-83=
18622788192328572prettyprint" style=3D"background-color:rgb(250,250,250);bo=
rder:1px solid rgb(187,187,187);word-wrap:break-word"><code class=3D"m_5204=
78396758981582m_-8318622788192328572prettyprint"><div class=3D"m_5204783967=
58981582m_-8318622788192328572subprettyprint"><font color=3D"#660066"><span=
style=3D"color:#008" class=3D"m_520478396758981582m_-8318622788192328572st=
yled-by-prettify">template</span><span style=3D"color:#660" class=3D"m_5204=
78396758981582m_-8318622788192328572styled-by-prettify"><</span><span st=
yle=3D"color:#008" class=3D"m_520478396758981582m_-8318622788192328572style=
d-by-prettify">bool</span><span style=3D"color:#000" class=3D"m_52047839675=
8981582m_-8318622788192328572styled-by-prettify"> flag</span><span style=3D=
"color:#660" class=3D"m_520478396758981582m_-8318622788192328572styled-by-p=
rettify">></span><span style=3D"color:#000" class=3D"m_52047839675898158=
2m_-8318622788192328572styled-by-prettify"><br></span><span style=3D"color:=
#008" class=3D"m_520478396758981582m_-8318622788192328572styled-by-prettify=
">using</span><span style=3D"color:#000" class=3D"m_520478396758981582m_-83=
18622788192328572styled-by-prettify"> </span><span style=3D"color:#606" cla=
ss=3D"m_520478396758981582m_-8318622788192328572styled-by-prettify">MyType<=
/span><span style=3D"color:#000" class=3D"m_520478396758981582m_-8318622788=
192328572styled-by-prettify"> </span><span style=3D"color:#660" class=3D"m_=
520478396758981582m_-8318622788192328572styled-by-prettify">=3D</span><span=
style=3D"color:#000" class=3D"m_520478396758981582m_-8318622788192328572st=
yled-by-prettify"> </span><span style=3D"color:#008" class=3D"m_52047839675=
8981582m_-8318622788192328572styled-by-prettify">typename</span><span style=
=3D"color:#000" class=3D"m_520478396758981582m_-8318622788192328572styled-b=
y-prettify"> </span><span style=3D"color:#008" class=3D"m_52047839675898158=
2m_-8318622788192328572styled-by-prettify">decltype</span><span style=3D"co=
lor:#660" class=3D"m_520478396758981582m_-8318622788192328572styled-by-pret=
tify">([]{</span><span style=3D"color:#000" class=3D"m_520478396758981582m_=
-8318622788192328572styled-by-prettify"><br>=C2=A0 </span><span style=3D"co=
lor:#008" class=3D"m_520478396758981582m_-8318622788192328572styled-by-pret=
tify">if</span><span style=3D"color:#000" class=3D"m_520478396758981582m_-8=
318622788192328572styled-by-prettify"> </span><span style=3D"color:#008" cl=
ass=3D"m_520478396758981582m_-8318622788192328572styled-by-prettify">conste=
xpr</span><span style=3D"color:#000" class=3D"m_520478396758981582m_-831862=
2788192328572styled-by-prettify"> </span><span style=3D"color:#660" class=
=3D"m_520478396758981582m_-8318622788192328572styled-by-prettify">(</span><=
span style=3D"color:#000" class=3D"m_520478396758981582m_-83186227881923285=
72styled-by-prettify">flag</span><span style=3D"color:#660" class=3D"m_5204=
78396758981582m_-8318622788192328572styled-by-prettify">)</span><span style=
=3D"color:#000" class=3D"m_520478396758981582m_-8318622788192328572styled-b=
y-prettify"> </span><span style=3D"color:#008" class=3D"m_52047839675898158=
2m_-8318622788192328572styled-by-prettify">return</span><span style=3D"colo=
r:#000" class=3D"m_520478396758981582m_-8318622788192328572styled-by-pretti=
fy"> identity</span><span style=3D"color:#080" class=3D"m_52047839675898158=
2m_-8318622788192328572styled-by-prettify"><int></span><span style=3D=
"color:#660" class=3D"m_520478396758981582m_-8318622788192328572styled-by-p=
rettify">{};</span><span style=3D"color:#000" class=3D"m_520478396758981582=
m_-8318622788192328572styled-by-prettify"><br>=C2=A0 </span><span style=3D"=
color:#008" class=3D"m_520478396758981582m_-8318622788192328572styled-by-pr=
ettify">else</span><span style=3D"color:#000" class=3D"m_520478396758981582=
m_-8318622788192328572styled-by-prettify"> </span><span style=3D"color:#008=
" class=3D"m_520478396758981582m_-8318622788192328572styled-by-prettify">re=
turn</span><span style=3D"color:#000" class=3D"m_520478396758981582m_-83186=
22788192328572styled-by-prettify"> identity</span><span style=3D"color:#080=
" class=3D"m_520478396758981582m_-8318622788192328572styled-by-prettify">&l=
t;float></span><span style=3D"color:#660" class=3D"m_520478396758981582m=
_-8318622788192328572styled-by-prettify">{};</span><span style=3D"color:#00=
0" class=3D"m_520478396758981582m_-8318622788192328572styled-by-prettify"><=
br></span><span style=3D"color:#660" class=3D"m_520478396758981582m_-831862=
2788192328572styled-by-prettify">}())::</span><span style=3D"color:#000" cl=
ass=3D"m_520478396758981582m_-8318622788192328572styled-by-prettify">type</=
span></font></div></code></div></div></div></blockquote></div></div><div di=
r=3D"auto"><br></div><div dir=3D"auto">Well, yes! We didn't have if con=
stexpr back then, nor return type deduction in ordinary functions.</div><di=
v dir=3D"auto"><br></div><div dir=3D"auto">At the same time, a meta switch =
would have been clunkier in the library of the time as we didn't have a=
uto template parameters so one would have to repeatedly specify the integra=
l type.</div><div dir=3D"auto"><br></div><div dir=3D"auto"><div class=3D"gm=
ail_quote"><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;bor=
der-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div><br></div><=
blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border=
-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div>std::condition=
al is essential to metaprogramming and is difficult and arcane to emulate, =
especially in C++11. A type switch is a lot less essential.</div></div></bl=
ockquote><div><br></div><div>Sure, it's definitely far from essential. =
What're your thoughts on its usefulness? It's very difficult to com=
e up with a motivating example that isn't incredibly specific (which is=
true for a lot of meta-programming stuff).</div></div></blockquote></div><=
/div><div dir=3D"auto"><br></div><div dir=3D"auto">The answer is to come up=
with plenty of specific examples. Look in open source code for heavily nes=
ted conditionals, or use of MPL maps etc, that could be improved by the use=
of a meta switch facility.=C2=A0</div><div dir=3D"auto"><br></div><div dir=
=3D"auto"><div class=3D"gmail_quote"><blockquote class=3D"gmail_quote" styl=
e=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<p></p>
-- <br>
You received this message because you are subscribed to a topic in the Goog=
le Groups "ISO C++ Standard - Future Proposals" group.<br>
To unsubscribe from this topic, visit <a href=3D"https://groups.google.com/=
a/isocpp.org/d/topic/std-proposals/NReFie_9Zy4/unsubscribe" rel=3D"noreferr=
er noreferrer" target=3D"_blank">https://groups.google.com/a/isocpp.org/d/t=
opic/std-proposals/NReFie_9Zy4/unsubscribe</a>.<br>
To unsubscribe from this group and all its topics, send an email to <a href=
=3D"mailto:std-proposals+unsubscribe@isocpp.org" rel=3D"noreferrer noreferr=
er" target=3D"_blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" rel=3D"noreferrer noreferrer" target=3D"_blank">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/d48673ff-90f5-4bab-b2a3-65205e4b6ee3%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" rel=3D"noreferrer =
noreferrer" target=3D"_blank">https://groups.google.com/a/isocpp.org/d/msgi=
d/std-proposals/d48673ff-90f5-4bab-b2a3-65205e4b6ee3%40isocpp.org</a>.<br>
</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/CAJnLdOY8MDzE6s0oZ0gNKUG0%2BzQgLLn9pV=
gyGVjTO1XMxsNvzA%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">h=
ttps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAJnLdOY8MDzE6s=
0oZ0gNKUG0%2BzQgLLn9pVgyGVjTO1XMxsNvzA%40mail.gmail.com</a>.<br />
--001a114c184cfad06605689289ae--
.
Author: hamza_sood@me.com
Date: Fri, 30 Mar 2018 04:00:29 -0700 (PDT)
Raw View
------=_Part_5593_379138090.1522407629502
Content-Type: multipart/alternative;
boundary="----=_Part_5594_1122173770.1522407629502"
------=_Part_5594_1122173770.1522407629502
Content-Type: text/plain; charset="UTF-8"
On Thursday, March 29, 2018 at 8:57:55 PM UTC+1, Edward Catmur wrote:
>
> The answer is to come up with plenty of specific examples. Look in open
> source code for heavily nested conditionals, or use of MPL maps etc, that
> could be improved by the use of a meta switch facility.
>
Good idea, thanks. I had a go at searching open source software but I
didn't have much luck (searching for code on Google with "site:github.com"
doesn't work particularly well). So instead I went with Stack Overflow and
blogs because I can search those in plain English. I realise that those
carry less weight than actual open-source software that has real world
usage, but it at least shows that other people have had a need for
something like this at some point.
Using sizeof to determine a suitable type:
https://stackoverflow.com/questions/28699281/is-there-anything-like-a-templatized-case-statement
http://avidinsight.uk/2015/10/using-cpp-templates-for-size-based-type-selection/
https://stackoverflow.com/questions/7038797/automatically-pick-a-variable-type-big-enough-to-hold-a-specified-number
https://stackoverflow.com/questions/4239632/how-would-one-write-a-meta-if-else-if-in-c/4240275#4240275
Mapping an enum value to a type (I'd imagine this is the most common
use-case):
https://stackoverflow.com/questions/11201428/generic-switch-statement-to-initialize-derived-types
https://stackoverflow.com/questions/41415265/map-enum-value-to-a-type-in-c
https://stackoverflow.com/questions/42593311/map-enum-value-to-template-argument-in-c
https://stackoverflow.com/questions/45252290/compile-time-class-template-selection-by-enum-template-parameter
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/6c5a9427-8923-41da-9069-d2a2c69a6098%40isocpp.org.
------=_Part_5594_1122173770.1522407629502
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Thursday, March 29, 2018 at 8:57:55 PM UTC+1, Edward Ca=
tmur 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"auto"><=
div dir=3D"auto">The answer is to come up with plenty of specific examples.=
Look in open source code for heavily nested conditionals, or use of MPL ma=
ps etc, that could be improved by the use of a meta switch facility.</div><=
/div></blockquote><div><br></div><div>Good idea, thanks. I had a go at sear=
ching open source software but I didn't have much luck (searching for c=
ode on Google with "site:github.com" doesn't work particularl=
y well). So instead I went with Stack Overflow and blogs because I can sear=
ch those in plain English. I realise that those carry less weight than actu=
al open-source software that has real world usage, but it at least shows th=
at other people have had a need for something like this at some point.</div=
><div><br></div><div>Using sizeof to determine a suitable type:</div><div><=
a href=3D"https://stackoverflow.com/questions/28699281/is-there-anything-li=
ke-a-templatized-case-statement">https://stackoverflow.com/questions/286992=
81/is-there-anything-like-a-templatized-case-statement</a><br></div><div><a=
href=3D"http://avidinsight.uk/2015/10/using-cpp-templates-for-size-based-t=
ype-selection/">http://avidinsight.uk/2015/10/using-cpp-templates-for-size-=
based-type-selection/</a><br></div><div><a href=3D"https://stackoverflow.co=
m/questions/7038797/automatically-pick-a-variable-type-big-enough-to-hold-a=
-specified-number">https://stackoverflow.com/questions/7038797/automaticall=
y-pick-a-variable-type-big-enough-to-hold-a-specified-number</a><br></div><=
div><a href=3D"https://stackoverflow.com/questions/4239632/how-would-one-wr=
ite-a-meta-if-else-if-in-c/4240275#4240275">https://stackoverflow.com/quest=
ions/4239632/how-would-one-write-a-meta-if-else-if-in-c/4240275#4240275</a>=
<br></div><div><br></div><div>Mapping an enum value to a type (I'd imag=
ine this is the most common use-case):</div><div><a href=3D"https://stackov=
erflow.com/questions/11201428/generic-switch-statement-to-initialize-derive=
d-types">https://stackoverflow.com/questions/11201428/generic-switch-statem=
ent-to-initialize-derived-types</a><br></div><div><a href=3D"https://stacko=
verflow.com/questions/41415265/map-enum-value-to-a-type-in-c">https://stack=
overflow.com/questions/41415265/map-enum-value-to-a-type-in-c</a><br></div>=
<div><a href=3D"https://stackoverflow.com/questions/42593311/map-enum-value=
-to-template-argument-in-c">https://stackoverflow.com/questions/42593311/ma=
p-enum-value-to-template-argument-in-c</a><br></div><div><a href=3D"https:/=
/stackoverflow.com/questions/45252290/compile-time-class-template-selection=
-by-enum-template-parameter">https://stackoverflow.com/questions/45252290/c=
ompile-time-class-template-selection-by-enum-template-parameter</a></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/6c5a9427-8923-41da-9069-d2a2c69a6098%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/6c5a9427-8923-41da-9069-d2a2c69a6098=
%40isocpp.org</a>.<br />
------=_Part_5594_1122173770.1522407629502--
------=_Part_5593_379138090.1522407629502--
.