Topic: constexpr also in switch() and even in for().


Author: Frank Klemm <frank.klemm.2808@gmail.com>
Date: Wed, 12 Dec 2018 14:09:21 -0800 (PST)
Raw View
------=_Part_82_1929055291.1544652561759
Content-Type: multipart/alternative;
 boundary="----=_Part_83_179840788.1544652561760"

------=_Part_83_179840788.1544652561760
Content-Type: text/plain; charset="UTF-8"



The *switch* instruction, as a multi-way *if* instruction, should be
similar to the *if* instruction.

When possible differences should be avoided.


So in C++17 *if* and *switch* got the same extention as the *for*-instruction,
so *if* and *switch* is similar:


    *for **(**int **i = 0; i < 4; i++) { ... }          *
*// old, part of C++99 or even older*

    *if* *(**bool **b = feof()) { ... }                 *
*// part of C++17*

    *switch **(**int **c = getchar()) { ... }           **// part of C++17,
similar to if(), great!*


But the constexpr extention is only availabe for the if instruction:


    *if constexpr **(compile_time_expression) { ... }  *
*// especially necessary when using static_assert()*


but not


    *switch constexpr **(compile_time_expression) { ... }  **// not
available, do use endless if/else if-cascades ...*


It would be nice to have this extention in C++20.


--------------------------------------------------------------------------------------------------------------------------------------------


For the (classic) *for* loop the following syntax would be nice:


    *for **(**const **int **i = 0; i < 4; i++) { ... }         **// 'i'
cannot be modified outside the for() header and cannot be used as non-const
reference*


For the (classic) *for* loop the following syntax would be nice:

This syntax should not allow code like:


    *for **(**const **int **i = 0; i < 4; i++) {*


*if (i == 2) *

*              i = 1;*

*    }*


Interesting, in the new for *:*-loop this is allowed:











*#include <iostream>#include <vector>using std::cout;int main (){    const
std::vector<int> V = { 1, 2, 4, 8, 16, 32 };    *




*for (int n : V)    {                  // standard        cout << n << '
';    }    cout << '\n';        **for (*






*int n : V)    {        if (n == 8)                       // hoppla, may be
not intended            n = 88888888;        cout << n << ' ';    }    cout
<< '\n';        **for (**const *





*int n : V) {        //if (n == 8)                     // n is protected,
although not a constant        //    n = 88888888;        cout << n << '
';    }    cout << '\n';*


        *for (*




*int n = 1; n <= 32; n *= 2) {    // standard        cout << n << ' ';
}    cout << '\n';    **for (*
*int n = 1; n <= 32; n *= 2) {        *






*if (n == 8)                       // hoppla, may be not intended
    n = 88888888;        cout << n << ' ';    }    cout << '\n';        //
not allowed, n cannot be protected    **for (/*const*/ *






*int n = 1; n <= 32; n *= 2) {        cout << n << ' ';    }    cout <<
'\n';        return 0;}*


--------------------------------------------------------------------------------------------------------------------------------------------


Last: constexpr for *for *loops


    *for **(**constexpr **int **i = 0; i < 4; i++) { ... }     **// the
sequence of i cannot be modified outside the for() and is known during
compile time: 0, 1, 2 and 3*


It is similar to:


*    { **constexpr **int **i = 0; ... }*

*    { **constexpr **int **i = 1; ... }*

*    { **constexpr **int **i = 2; ... }*

*    { **constexpr **int **i = 3; ... }*


You can also write code like:

    *for **(**constexpr **int **i = 0; i < 4; i++) {*

*        static_assert (i >= 0 && i < 4);*


*        if (12 % (i+1)) *

*            ...do silly stuff ...*

*        else*


*            ...do useful stuff...*


*    }*


--
Frank Klemm

--
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/18750262-f0ab-4330-ab08-29004735c6bb%40isocpp.org.

------=_Part_83_179840788.1544652561760
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><p>The <b>switch</b> instruction, as a multi-way <b>if</b>=
 instruction, should be similar to the <b>if</b> instruction. <br></p><p>Wh=
en possible differences should be avoided.<br></p><p><br></p><p>So in C++17=
 <b>if</b> and <b>switch</b> got the same extention as the <b>for</b>-instr=
uction, so <b>if</b> and <b>switch</b> is similar:<br></p><p><br></p><p><b>=
<span style=3D"font-family:&quot;Courier New&quot;">=C2=A0=C2=A0=C2=A0 </sp=
an></b><b><span style=3D"font-family:&quot;Courier New&quot;;color:#3366FF"=
>for
</span></b><b><span style=3D"font-family:&quot;Courier New&quot;">(</span><=
/b><b><span style=3D"font-family:&quot;Courier New&quot;;color:#CC33CC">int=
 </span></b><b><span style=3D"font-family:&quot;Courier New&quot;">i =3D 0;=
 i &lt; 4; i++) { ... } =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0 =C2=A0
</span></b><b><span style=3D"font-family:&quot;Courier New&quot;;color:#009=
900">// old, part of C++99 or even older<br></span></b></p>
<p><b><span style=3D"font-family:&quot;Courier New&quot;">=C2=A0=C2=A0=C2=
=A0 </span></b><b><span style=3D"font-family:&quot;Courier New&quot;;color:=
#3366FF">if</span></b><b><span style=3D"font-family:&quot;Courier New&quot;=
;color:#3366FF">
</span></b><b><span style=3D"font-family:&quot;Courier New&quot;">(</span><=
/b><b><span style=3D"font-family:&quot;Courier New&quot;;color:#CC33CC">boo=
l
</span></b><b><span style=3D"font-family:&quot;Courier New&quot;">b =3D <i>=
feof</i>()) { ... } =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0 =C2=A0=C2=A0 =
=C2=A0
</span></b><b><span style=3D"font-family:&quot;Courier New&quot;;color:#009=
900">// part of C++17<br></span></b></p>
<p></p><p><b><span style=3D"font-family:&quot;Courier New&quot;">=C2=A0=C2=
=A0=C2=A0 </span></b><b><span style=3D"font-family:&quot;Courier New&quot;;=
color:#3366FF">switch
</span></b><b><span style=3D"font-family:&quot;Courier New&quot;">(</span><=
/b><b><span style=3D"font-family:&quot;Courier New&quot;;color:#CC33CC">int
</span></b><b><span style=3D"font-family:&quot;Courier New&quot;">c =3D <i>=
getchar</i>()) { ... } =C2=A0 =C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0
</span></b><b><span style=3D"font-family:&quot;Courier New&quot;;color:#009=
900">// part of C++17, similar to if(), great!</span></b></p>
<p><br></p><p>But the constexpr extention is only availabe for the if instr=
uction:</p><p><br></p><p><b><span style=3D"font-family:&quot;Courier New&qu=
ot;">=C2=A0=C2=A0=C2=A0 </span></b><b><span style=3D"font-family:&quot;Cour=
ier New&quot;;color:#3366FF">if constexpr
</span></b><b><span style=3D"font-family:&quot;Courier New&quot;">(<i>compi=
le_time_expression</i>) { ... }=C2=A0
</span></b><b><span style=3D"font-family:&quot;Courier New&quot;;color:#009=
900">// especially necessary when using static_assert()<br></span></b></p><=
p><br></p><p>but not<br></p><p><br></p><p><b><span style=3D"font-family:&qu=
ot;Courier New&quot;">=C2=A0=C2=A0=C2=A0 </span></b><b><span style=3D"font-=
family:&quot;Courier New&quot;;color:#3366FF">switch constexpr
</span></b><b><span style=3D"font-family:&quot;Courier New&quot;">(<i>compi=
le_time_expression</i>) { ... }=C2=A0
</span></b><b><span style=3D"font-family:&quot;Courier New&quot;;color:#009=
900">// not available, do use endless if/else if-cascades ...</span></b></p=
><p><span style=3D"font-family: arial, sans-serif;"><span style=3D"color: r=
gb(0, 153, 0);"><br></span></span></p><p><span style=3D"font-family: arial,=
 sans-serif;">It would be nice to have this extention in C++20.</span></p><=
p><span style=3D"font-family: arial, sans-serif;"><span style=3D"color: rgb=
(0, 0, 0);"><br></span></span></p><p><span style=3D"font-family: arial, san=
s-serif;"><span style=3D"color: rgb(0, 0, 0);">----------------------------=
---------------------------------------------------------------------------=
-------------------------------------</span></span></p><p><span style=3D"fo=
nt-family: arial, sans-serif;"><span style=3D"color: rgb(0, 0, 0);"><br></s=
pan></span></p><p><span style=3D"font-family: arial, sans-serif;"><span sty=
le=3D"color: rgb(0, 0, 0);">For the (classic) <b>for</b> loop the following=
 syntax would be nice:<br></span></span></p><p><span style=3D"font-family: =
arial, sans-serif;"><span style=3D"color: rgb(0, 0, 0);"></span></span></p>=
<p><br></p><p><b><span style=3D"font-family:&quot;Courier New&quot;">=C2=A0=
=C2=A0=C2=A0 </span></b><b><span style=3D"font-family:&quot;Courier New&quo=
t;;color:#3366FF">for
</span></b><b><span style=3D"font-family:&quot;Courier New&quot;">(</span><=
/b><b><span style=3D"font-family:&quot;Courier New&quot;;color:#3366FF">con=
st
</span></b><b><span style=3D"font-family:&quot;Courier New&quot;;color:#CC3=
3CC">int </span></b><b><span style=3D"font-family:&quot;Courier New&quot;">=
i =3D 0; i &lt; 4; i++) { ... } =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0
</span></b><b><span style=3D"font-family:&quot;Courier New&quot;;color:#009=
900">// </span><span style=3D"font-family:&quot;Courier New&quot;;color:#00=
9900"><i>&#39;i&#39;</i></span><span style=3D"font-family:&quot;Courier New=
&quot;;color:#009900"> cannot be modified outside the for() header and cann=
ot be used as non-const reference</span></b></p><p><b><span style=3D"font-f=
amily:&quot;Courier New&quot;;color:#009900"><br></span></b></p><p><span st=
yle=3D"font-family: arial, sans-serif;"><span style=3D"color: rgb(0, 0, 0);=
">For the (classic) <b>for</b> loop the following syntax would be nice:<br>=
</span></span></p><p><span style=3D"font-family: arial, sans-serif;"><span =
style=3D"color: rgb(0, 0, 0);"></span></span></p><p>This syntax should not =
allow code like:</p><p><br></p><p><b><span style=3D"font-family:&quot;Couri=
er New&quot;">=C2=A0=C2=A0=C2=A0 </span></b><b><span style=3D"font-family:&=
quot;Courier New&quot;;color:#3366FF">for
</span></b><b><span style=3D"font-family:&quot;Courier New&quot;">(</span><=
/b><b><span style=3D"font-family:&quot;Courier New&quot;;color:#3366FF">con=
st
</span></b><b><span style=3D"font-family:&quot;Courier New&quot;;color:#CC3=
3CC">int </span></b><b><span style=3D"font-family:&quot;Courier New&quot;">=
i =3D 0; i &lt; 4; i++) {</span></b></p><p><b><span style=3D"font-family:&q=
uot;Courier New&quot;">=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 </span><=
/b><b><span style=3D"font-family:&quot;Courier New&quot;"><b><span style=3D=
"font-family:&quot;Courier New&quot;;color:#3366FF">if <span style=3D"color=
: rgb(0, 0, 0);">(i =3D=3D 2) <br></span></span></b></span></b></p><p><span=
 style=3D"color: rgb(0, 0, 0);"><b><span style=3D"font-family:&quot;Courier=
 New&quot;"><b><span style=3D"font-family: &quot;Courier New&quot;;">=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 i =
=3D 1;</span></b></span></b></span><br><b><span style=3D"font-family:&quot;=
Courier New&quot;"><b><span style=3D"font-family:&quot;Courier New&quot;;co=
lor:#3366FF"><b><span style=3D"font-family:&quot;Courier New&quot;;color:#C=
C33CC"></span></b></span></b></span></b></p><p><b><span style=3D"font-famil=
y:&quot;Courier New&quot;">=C2=A0=C2=A0=C2=A0 }</span></b></p><p><br></p><p=
>Interesting, in the new for <b>:</b>-loop this is allowed:<br></p><p><br><=
/p><p><span style=3D"font-family: courier new, monospace;"><b><span style=
=3D"color: rgb(204, 0, 0);">#include &lt;iostream&gt;<br>#include &lt;vecto=
r&gt;</span><br><br>using std::cout;<br><br>int main ()<br>{<br>=C2=A0=C2=
=A0=C2=A0 const std::vector&lt;int&gt; V =3D { 1, 2, 4, 8, 16, 32 };<br><br=
>=C2=A0=C2=A0=C2=A0 </b></span><span style=3D"font-family: courier new, mon=
ospace;"><b><b><span style=3D"font-family:&quot;Courier New&quot;;color:#33=
66FF">for</span></b> (int n : V)=C2=A0=C2=A0=C2=A0 {=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <span style=3D"color: rgb(106, 168, 79);"=
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 // standard</span><br>=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0 cout &lt;&lt; n &lt;&lt; &#39; &#39;;<br>=C2=A0=C2=A0=C2=
=A0 }<br>=C2=A0=C2=A0=C2=A0 cout &lt;&lt; &#39;\n&#39;;<br>=C2=A0=C2=A0=C2=
=A0 <br>=C2=A0=C2=A0=C2=A0 </b></span><span style=3D"font-family: courier n=
ew, monospace;"><b><b><span style=3D"font-family:&quot;Courier New&quot;;co=
lor:#3366FF">for</span></b> (</b></span><span style=3D"font-family: courier=
 new, monospace;"><b><b><span style=3D"font-family:&quot;Courier New&quot;;=
color:#CC33CC">int</span></b> n : V)=C2=A0=C2=A0=C2=A0 {<br>=C2=A0=C2=A0=C2=
=A0 =C2=A0=C2=A0=C2=A0 if (n =3D=3D 8)=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 <span st=
yle=3D"color: rgb(106, 168, 79);">// hoppla, may be not intended</span><br>=
=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 n =3D 88888888;<br=
>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 cout &lt;&lt; n &lt;&lt; &#39; =
&#39;;<br>=C2=A0=C2=A0=C2=A0 }<br>=C2=A0=C2=A0=C2=A0 cout &lt;&lt; &#39;\n&=
#39;;<br>=C2=A0=C2=A0=C2=A0 <br>=C2=A0=C2=A0=C2=A0 </b></span><span style=
=3D"font-family: courier new, monospace;"><b><b><span style=3D"font-family:=
&quot;Courier New&quot;;color:#3366FF">for</span></b> (</b></span><span sty=
le=3D"font-family: courier new, monospace;"><b><b><span style=3D"font-famil=
y:&quot;Courier New&quot;;color:#3366FF">const </span></b></b></span><span =
style=3D"font-family: courier new, monospace;"><b><b><span style=3D"font-fa=
mily:&quot;Courier New&quot;;color:#3366FF"><b><span style=3D"font-family:&=
quot;Courier New&quot;;color:#CC33CC">int</span></b></span></b> n : V) {<br=
>=C2=A0=C2=A0=C2=A0 <span style=3D"color: rgb(106, 168, 79);">=C2=A0=C2=A0=
=C2=A0 //if (n =3D=3D 8)=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 // n is protected, although not a=
 constant<br>=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 //=C2=A0=C2=A0=C2=A0 n =
=3D 88888888;</span><br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 cout &lt=
;&lt; n &lt;&lt; &#39; &#39;;<br>=C2=A0=C2=A0=C2=A0 }<br>=C2=A0=C2=A0=C2=A0=
 cout &lt;&lt; &#39;\n&#39;;<br></b></span></p><p><span style=3D"font-famil=
y: courier new, monospace;"><b>=C2=A0=C2=A0=C2=A0 <br>=C2=A0=C2=A0=C2=A0 </=
b></span><span style=3D"font-family: courier new, monospace;"><b><b><span s=
tyle=3D"font-family:&quot;Courier New&quot;;color:#3366FF">for</span></b> (=
</b></span><span style=3D"font-family: courier new, monospace;"><b><b><span=
 style=3D"font-family:&quot;Courier New&quot;;color:#CC33CC">int</span></b>=
 n =3D 1; n &lt;=3D 32; n *=3D 2) {=C2=A0=C2=A0=C2=A0 <span style=3D"color:=
 rgb(56, 118, 29);"><span style=3D"color: rgb(106, 168, 79);">// standard</=
span></span><br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 cout &lt;&lt; n =
&lt;&lt; &#39; &#39;;<br>=C2=A0=C2=A0=C2=A0 }<br>=C2=A0=C2=A0=C2=A0 cout &l=
t;&lt; &#39;\n&#39;;<br><br>=C2=A0=C2=A0=C2=A0 </b></span><span style=3D"fo=
nt-family: courier new, monospace;"><b><b><span style=3D"font-family:&quot;=
Courier New&quot;;color:#3366FF">for</span></b> (</b></span><span style=3D"=
font-family: courier new, monospace;"><b><b><span style=3D"font-family:&quo=
t;Courier New&quot;;color:#CC33CC">int</span></b> n =3D 1; n &lt;=3D 32; n =
*=3D 2) {<br>=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 </b></span><span style=
=3D"font-family: courier new, monospace;"><b><b><span style=3D"font-family:=
&quot;Courier New&quot;"><b><span style=3D"font-family:&quot;Courier New&qu=
ot;;color:#3366FF">if</span></b></span></b> (n =3D=3D 8)=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 <span style=3D"color: rgb(106, 168,=
 79);">// hoppla, may be not intended</span><br>=C2=A0=C2=A0=C2=A0 =C2=A0=
=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 n =3D 88888888;<br>=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0 cout &lt;&lt; n &lt;&lt; &#39; &#39;;<br>=C2=A0=C2=A0=C2=
=A0 }<br>=C2=A0=C2=A0=C2=A0 cout &lt;&lt; &#39;\n&#39;;<br>=C2=A0=C2=A0=C2=
=A0 <br>=C2=A0=C2=A0=C2=A0 <span style=3D"color: rgb(106, 168, 79);">// not=
 allowed, n cannot be protected</span><br>=C2=A0=C2=A0=C2=A0 </b></span><sp=
an style=3D"font-family: courier new, monospace;"><b><b><span style=3D"font=
-family:&quot;Courier New&quot;;color:#3366FF">for</span></b> (<span style=
=3D"color: rgb(106, 168, 79);">/*const*/</span> </b></span><span style=3D"f=
ont-family: courier new, monospace;"><b><b><span style=3D"font-family:&quot=
;Courier New&quot;;color:#CC33CC">int</span></b> n =3D 1; n &lt;=3D 32; n *=
=3D 2) {<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 cout &lt;&lt; n &lt;=
&lt; &#39; &#39;;<br>=C2=A0=C2=A0=C2=A0 }<br>=C2=A0=C2=A0=C2=A0 cout &lt;&l=
t; &#39;\n&#39;;<br>=C2=A0=C2=A0=C2=A0 <br>=C2=A0=C2=A0=C2=A0 return 0;<br>=
}<br></b></span><b><span style=3D"font-family:&quot;Courier New&quot;"></sp=
an></b><b><span style=3D"font-family:&quot;Courier New&quot;;color:#009900"=
></span></b></p><p><br></p><p><span style=3D"font-family: arial, sans-serif=
;"><span style=3D"color: rgb(0, 0, 0);">-----------------------------------=
---------------------------------------------------------------------------=
------------------------------</span></span></p><p><span style=3D"font-fami=
ly: arial, sans-serif;"><span style=3D"color: rgb(0, 0, 0);"><br></span></s=
pan></p><p><span style=3D"font-family: arial, sans-serif;"><span style=3D"c=
olor: rgb(0, 0, 0);">Last: constexpr for <b>for </b>loops<br></span></span>=
</p><p><span style=3D"font-family: arial, sans-serif;"><span style=3D"color=
: rgb(0, 0, 0);"></span></span></p><p><b><span style=3D"font-family:&quot;C=
ourier New&quot;;color:#009900"></span></b></p><p><b><span style=3D"font-fa=
mily:&quot;Courier New&quot;;color:#009900"></span></b></p><p><b><span styl=
e=3D"font-family:&quot;Courier New&quot;;color:#009900"></span></b></p><p><=
b><span style=3D"font-family:&quot;Courier New&quot;;color:#009900"><br></s=
pan></b></p><p><b><span style=3D"font-family:&quot;Courier New&quot;;color:=
#009900"></span></b></p><b><span style=3D"font-family:&quot;Courier New&quo=
t;">=C2=A0=C2=A0=C2=A0 </span></b><b><span style=3D"font-family:&quot;Couri=
er New&quot;;color:#3366FF">for
</span></b><b><span style=3D"font-family:&quot;Courier New&quot;">(</span><=
/b><b><span style=3D"font-family:&quot;Courier New&quot;;color:#3366FF">con=
stexpr
</span></b><b><span style=3D"font-family:&quot;Courier New&quot;;color:#CC3=
3CC">int </span></b><b><span style=3D"font-family:&quot;Courier New&quot;">=
i =3D 0; i &lt; 4; i++) { ... } =C2=A0=C2=A0=C2=A0
</span></b><b><span style=3D"font-family:&quot;Courier New&quot;;color:#009=
900">// the sequence of i cannot be modified outside the for() and is known=
 during compile time: 0, 1, 2 and 3</span></b>
<p><br></p><p>It is similar to:</p><p><br></p><p><b><span style=3D"font-fam=
ily:&quot;Courier New&quot;">=C2=A0=C2=A0=C2=A0 { </span></b><b><span style=
=3D"font-family:&quot;Courier New&quot;"></span></b><b><span style=3D"font-=
family:&quot;Courier New&quot;;color:#3366FF">constexpr
</span></b><b><span style=3D"font-family:&quot;Courier New&quot;;color:#CC3=
3CC">int </span></b><b><span style=3D"font-family:&quot;Courier New&quot;">=
i =3D 0; ... }</span></b><b><span style=3D"font-family:&quot;Courier New&qu=
ot;;color:#009900"></span></b>
</p><p><b><span style=3D"font-family:&quot;Courier New&quot;">=C2=A0=C2=A0=
=C2=A0 { </span></b><b><span style=3D"font-family:&quot;Courier New&quot;">=
</span></b><b><span style=3D"font-family:&quot;Courier New&quot;;color:#336=
6FF">constexpr
</span></b><b><span style=3D"font-family:&quot;Courier New&quot;;color:#CC3=
3CC">int </span></b><b><span style=3D"font-family:&quot;Courier New&quot;">=
i =3D 1; ... }</span></b><b><span style=3D"font-family:&quot;Courier New&qu=
ot;;color:#009900"></span></b>
</p><p><b><span style=3D"font-family:&quot;Courier New&quot;">=C2=A0=C2=A0=
=C2=A0 { </span></b><b><span style=3D"font-family:&quot;Courier New&quot;">=
</span></b><b><span style=3D"font-family:&quot;Courier New&quot;;color:#336=
6FF">constexpr
</span></b><b><span style=3D"font-family:&quot;Courier New&quot;;color:#CC3=
3CC">int </span></b><b><span style=3D"font-family:&quot;Courier New&quot;">=
i =3D 2; ... }</span></b><b><span style=3D"font-family:&quot;Courier New&qu=
ot;;color:#009900"></span></b>
</p><p><b><span style=3D"font-family:&quot;Courier New&quot;">=C2=A0=C2=A0=
=C2=A0 { </span></b><b><span style=3D"font-family:&quot;Courier New&quot;">=
</span></b><b><span style=3D"font-family:&quot;Courier New&quot;;color:#336=
6FF">constexpr
</span></b><b><span style=3D"font-family:&quot;Courier New&quot;;color:#CC3=
3CC">int </span></b><b><span style=3D"font-family:&quot;Courier New&quot;">=
i =3D 3; ... }</span></b><b><span style=3D"font-family:&quot;Courier New&qu=
ot;;color:#009900"></span></b>
</p><p></p><p><br></p><p>You can also write code like:<br></p><br><p><b><sp=
an style=3D"font-family:&quot;Courier New&quot;">=C2=A0=C2=A0=C2=A0 </span>=
</b><b><span style=3D"font-family:&quot;Courier New&quot;;color:#3366FF">fo=
r
</span></b><b><span style=3D"font-family:&quot;Courier New&quot;">(</span><=
/b><b><span style=3D"font-family:&quot;Courier New&quot;;color:#3366FF">con=
stexpr
</span></b><b><span style=3D"font-family:&quot;Courier New&quot;;color:#CC3=
3CC">int </span></b><b><span style=3D"font-family:&quot;Courier New&quot;">=
i =3D 0; i &lt; 4; i++) {</span></b></p><p><b><span style=3D"font-family:&q=
uot;Courier New&quot;">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <span sty=
le=3D"color: rgb(0, 0, 255);">static_assert</span> (i &gt;=3D 0 &amp;&amp; =
i &lt; 4);</span></b></p><p><b><span style=3D"font-family:&quot;Courier New=
&quot;">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <span style=3D"color: rg=
b(0, 0, 255);">if</span> (12 % (i+1)) <br></span></b></p><p><b><span style=
=3D"font-family:&quot;Courier New&quot;">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ...do silly stuff ...</span></b></p><p><s=
pan style=3D"color: rgb(0, 0, 255);"><b><span style=3D"font-family:&quot;Co=
urier New&quot;">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 else</span></b>=
</span></p><p><b><span style=3D"font-family:&quot;Courier New&quot;">=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ...do useful s=
tuff...<br></span></b></p><p><b><span style=3D"font-family:&quot;Courier Ne=
w&quot;">=C2=A0=C2=A0=C2=A0 }<br></span></b></p><p><b><span style=3D"font-f=
amily:&quot;Courier New&quot;"></span></b><b><span style=3D"font-family:&qu=
ot;Courier New&quot;;color:#009900"></span></b>
</p><p></p><p><span style=3D"font-family: arial, sans-serif;"><br></span></=
p><span style=3D"font-family: arial, sans-serif;">
</span><p class=3D"MsoNormal"><span style=3D"font-family: arial, sans-serif=
;">--</span>=20
</p><span style=3D"font-family: arial, sans-serif;">
Frank Klemm</span></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/18750262-f0ab-4330-ab08-29004735c6bb%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/18750262-f0ab-4330-ab08-29004735c6bb=
%40isocpp.org</a>.<br />

------=_Part_83_179840788.1544652561760--

------=_Part_82_1929055291.1544652561759--

.


Author: Victor Dyachenko <victor.dyachenko@gmail.com>
Date: Wed, 12 Dec 2018 23:11:48 -0800 (PST)
Raw View
------=_Part_172_275698806.1544685108967
Content-Type: multipart/alternative;
 boundary="----=_Part_173_1128665471.1544685108967"

------=_Part_173_1128665471.1544685108967
Content-Type: text/plain; charset="UTF-8"

See http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2018/p1306r0.pdf

--
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/0a8ee61d-47c7-4b1e-b28b-1254a34eb920%40isocpp.org.

------=_Part_173_1128665471.1544685108967
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">See http://www.open-std.org/JTC1/SC22/WG21/docs/papers/201=
8/p1306r0.pdf<br></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/0a8ee61d-47c7-4b1e-b28b-1254a34eb920%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/0a8ee61d-47c7-4b1e-b28b-1254a34eb920=
%40isocpp.org</a>.<br />

------=_Part_173_1128665471.1544685108967--

------=_Part_172_275698806.1544685108967--

.


Author: inkwizytoryankes@gmail.com
Date: Thu, 13 Dec 2018 15:46:52 -0800 (PST)
Raw View
------=_Part_626_1204096333.1544744813037
Content-Type: multipart/alternative;
 boundary="----=_Part_627_1966045292.1544744813038"

------=_Part_627_1966045292.1544744813038
Content-Type: text/plain; charset="UTF-8"



On Wednesday, December 12, 2018 at 11:09:21 PM UTC+1, Frank Klemm wrote:
>
> The *switch* instruction, as a multi-way *if* instruction, should be
> similar to the *if* instruction.
>
> When possible differences should be avoided.
>
>
> So in C++17 *if* and *switch* got the same extention as the *for*-instruction,
> so *if* and *switch* is similar:
>
>
>     *for **(**int **i = 0; i < 4; i++) { ... }          *
> *// old, part of C++99 or even older*
>
>     *if* *(**bool **b = feof()) { ... }                 *
> *// part of C++17*
>
>     *switch **(**int **c = getchar()) { ... }           **// part of
> C++17, similar to if(), great!*
>
>
> But the constexpr extention is only availabe for the if instruction:
>
>
>     *if constexpr **(compile_time_expression) { ... }  *
> *// especially necessary when using static_assert()*
>
>
> but not
>
>
>     *switch constexpr **(compile_time_expression) { ... }  **// not
> available, do use endless if/else if-cascades ...*
>
>
> It would be nice to have this extention in C++20.
>

How exactly  `switch constexpr` will work? Consider this code:

switch constexpr (x)
{
    case 1:
    while(z)
    {
        case 2:;
    }
    if (y)
    {
        default:;
    }
}

How it will help in that case?

--
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/ce9ea71e-f5e9-4ee1-9e2e-26af0a0bf8e1%40isocpp.org.

------=_Part_627_1966045292.1544744813038
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>On Wednesday, December 12, 2018 at 11:09:21 PM UTC=
+1, Frank Klemm 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"><p>The <b>switch</b> instruction, as a multi-way <b>if</b> instruc=
tion, should be similar to the <b>if</b> instruction. <br></p><p>When possi=
ble differences should be avoided.<br></p><p><br></p><p>So in C++17 <b>if</=
b> and <b>switch</b> got the same extention as the <b>for</b>-instruction, =
so <b>if</b> and <b>switch</b> is similar:<br></p><p><br></p><p><b><span st=
yle=3D"font-family:&quot;Courier New&quot;">=C2=A0=C2=A0=C2=A0 </span></b><=
b><span style=3D"font-family:&quot;Courier New&quot;;color:#3366ff">for
</span></b><b><span style=3D"font-family:&quot;Courier New&quot;">(</span><=
/b><b><span style=3D"font-family:&quot;Courier New&quot;;color:#cc33cc">int=
 </span></b><b><span style=3D"font-family:&quot;Courier New&quot;">i =3D 0;=
 i &lt; 4; i++) { ... } =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0 =C2=A0
</span></b><b><span style=3D"font-family:&quot;Courier New&quot;;color:#009=
900">// old, part of C++99 or even older<br></span></b></p>
<p><b><span style=3D"font-family:&quot;Courier New&quot;">=C2=A0=C2=A0=C2=
=A0 </span></b><b><span style=3D"font-family:&quot;Courier New&quot;;color:=
#3366ff">if</span></b><b><span style=3D"font-family:&quot;Courier New&quot;=
;color:#3366ff">
</span></b><b><span style=3D"font-family:&quot;Courier New&quot;">(</span><=
/b><b><span style=3D"font-family:&quot;Courier New&quot;;color:#cc33cc">boo=
l
</span></b><b><span style=3D"font-family:&quot;Courier New&quot;">b =3D <i>=
feof</i>()) { ... } =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0 =C2=A0=C2=A0 =
=C2=A0
</span></b><b><span style=3D"font-family:&quot;Courier New&quot;;color:#009=
900">// part of C++17<br></span></b></p>
<p></p><p><b><span style=3D"font-family:&quot;Courier New&quot;">=C2=A0=C2=
=A0=C2=A0 </span></b><b><span style=3D"font-family:&quot;Courier New&quot;;=
color:#3366ff">switch
</span></b><b><span style=3D"font-family:&quot;Courier New&quot;">(</span><=
/b><b><span style=3D"font-family:&quot;Courier New&quot;;color:#cc33cc">int
</span></b><b><span style=3D"font-family:&quot;Courier New&quot;">c =3D <i>=
getchar</i>()) { ... } =C2=A0 =C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0
</span></b><b><span style=3D"font-family:&quot;Courier New&quot;;color:#009=
900">// part of C++17, similar to if(), great!</span></b></p>
<p><br></p><p>But the constexpr extention is only availabe for the if instr=
uction:</p><p><br></p><p><b><span style=3D"font-family:&quot;Courier New&qu=
ot;">=C2=A0=C2=A0=C2=A0 </span></b><b><span style=3D"font-family:&quot;Cour=
ier New&quot;;color:#3366ff">if constexpr
</span></b><b><span style=3D"font-family:&quot;Courier New&quot;">(<i>compi=
le_time_expression</i>) { ... }=C2=A0
</span></b><b><span style=3D"font-family:&quot;Courier New&quot;;color:#009=
900">// especially necessary when using static_assert()<br></span></b></p><=
p><br></p><p>but not<br></p><p><br></p><p><b><span style=3D"font-family:&qu=
ot;Courier New&quot;">=C2=A0=C2=A0=C2=A0 </span></b><b><span style=3D"font-=
family:&quot;Courier New&quot;;color:#3366ff">switch constexpr
</span></b><b><span style=3D"font-family:&quot;Courier New&quot;">(<i>compi=
le_time_expression</i>) { ... }=C2=A0
</span></b><b><span style=3D"font-family:&quot;Courier New&quot;;color:#009=
900">// not available, do use endless if/else if-cascades ...</span></b></p=
><p><span style=3D"font-family:arial,sans-serif"><span style=3D"color:rgb(0=
,153,0)"><br></span></span></p><p><span style=3D"font-family:arial,sans-ser=
if">It would be nice to have this extention in C++20.</span></p></div></blo=
ckquote><div><br></div><div>How exactly=C2=A0 `switch constexpr` will work?=
 Consider this code:</div><div><br></div><div><div style=3D"background-colo=
r: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style: soli=
d; border-width: 1px; overflow-wrap: break-word;" class=3D"prettyprint"><co=
de class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color=
: #008;" class=3D"styled-by-prettify">switch</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" clas=
s=3D"styled-by-prettify">constexpr</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">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"color: #660;" class=3D"styled-by-prettify">{</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><s=
pan style=3D"color: #008;" class=3D"styled-by-prettify">case</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"co=
lor: #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"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008=
;" class=3D"styled-by-prettify">while</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify">z</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">)</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-pr=
ettify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D=
"styled-by-prettify">case</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> </span><span style=3D"color: #066;" class=3D"styled-by-pret=
tify">2</span><span style=3D"color: #660;" class=3D"styled-by-prettify">:;<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =
=C2=A0 </span><span style=3D"color: #660;" class=3D"styled-by-prettify">}</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =
=C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-prettify">if<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">y</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color:=
 #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span st=
yle=3D"color: #008;" class=3D"styled-by-prettify">default</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">:;</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">}</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br></span></div></code></div><br>How it will help =
in that case?<br></div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/ce9ea71e-f5e9-4ee1-9e2e-26af0a0bf8e1%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/ce9ea71e-f5e9-4ee1-9e2e-26af0a0bf8e1=
%40isocpp.org</a>.<br />

------=_Part_627_1966045292.1544744813038--

------=_Part_626_1204096333.1544744813037--

.


Author: Alberto Barbati <albertobarbati@gmail.com>
Date: Fri, 14 Dec 2018 01:20:28 -0800 (PST)
Raw View
------=_Part_684_675424228.1544779228798
Content-Type: multipart/alternative;
 boundary="----=_Part_685_365109050.1544779228798"

------=_Part_685_365109050.1544779228798
Content-Type: text/plain; charset="UTF-8"

Hi Frank,

I believe you are missing the point of "if constexpr". The real usefulness
of "if constexpr" is that it makes the branch that is not selected a
"discarded statement" so that it doesn't trigger compilation errors if it
is ill-formed after template parameters substitution. In the case of the
for statement, that usefulness simply isn't there, because there's only one
statement to consider, so either it is ill-formed for all iterations or
none of them. The idea of having the iteration variable constexpr is
intriguing, but I'm not totally sure that it has a real usefulness,
especially after the introduction of consteval functions. The switch
statement is a bit more complicated, as its structure is too "flexible",
with jumps at labels that may not respect scopes. Because of that a switch
is *not* equivalent to a cascade of if-statements at least in the general
case.

Anyway, your proposal indicates a possibile solution but doesn't describe a
real problem that the proposal is trying to solve. I am afraid but "It
would be nice to have this..." is not a satisfactory description of real
problem.

Alberto


--
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/4fe7ab83-be8f-4f62-a1a4-72b39fb540d3%40isocpp.org.

------=_Part_685_365109050.1544779228798
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>Hi Frank,</div><div><br></div><div>I believe you are =
missing the point of &quot;if constexpr&quot;. The real usefulness of &quot=
;if constexpr&quot; is that it makes the branch that is not selected a &quo=
t;discarded statement&quot; so that it doesn&#39;t trigger compilation erro=
rs if it is ill-formed after template parameters substitution. In the case =
of the for statement, that usefulness simply isn&#39;t there, because there=
&#39;s only one statement to consider, so either it is ill-formed for all i=
terations or none of them. The idea of having the iteration variable conste=
xpr is intriguing, but I&#39;m not totally sure that it has a real usefulne=
ss, especially after the introduction of consteval functions. The switch st=
atement is a bit more complicated, as its structure is too &quot;flexible&q=
uot;, with jumps at labels that may not respect scopes. Because of that a s=
witch is *not* equivalent to a cascade of if-statements at least in the gen=
eral case.</div><div><br></div><div>Anyway, your proposal indicates a possi=
bile solution but doesn&#39;t describe a real problem that the proposal is =
trying to solve. I am afraid but &quot;<span style=3D"font-family:arial,san=
s-serif">It would be nice to have this...&quot; is not a satisfactory descr=
iption of real problem.<br></span></div><div><span style=3D"font-family:ari=
al,sans-serif"><br></span></div><div><span style=3D"font-family:arial,sans-=
serif">Alberto<br></span></div><br><br></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/4fe7ab83-be8f-4f62-a1a4-72b39fb540d3%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/4fe7ab83-be8f-4f62-a1a4-72b39fb540d3=
%40isocpp.org</a>.<br />

------=_Part_685_365109050.1544779228798--

------=_Part_684_675424228.1544779228798--

.


Author: Richard Hodges <hodges.r@gmail.com>
Date: Fri, 14 Dec 2018 17:32:22 +0700
Raw View
--000000000000fc6c9e057cf8f215
Content-Type: text/plain; charset="UTF-8"

On Fri, 14 Dec 2018 at 16:20, Alberto Barbati <albertobarbati@gmail.com>
wrote:

> Hi Frank,
>
> I believe you are missing the point of "if constexpr". The real usefulness
> of "if constexpr" is that it makes the branch that is not selected a
> "discarded statement" so that it doesn't trigger compilation errors if it
> is ill-formed after template parameters substitution. In the case of the
> for statement, that usefulness simply isn't there, because there's only one
> statement to consider, so either it is ill-formed for all iterations or
> none of them. The idea of having the iteration variable constexpr is
> intriguing, but I'm not totally sure that it has a real usefulness,
> especially after the introduction of consteval functions. The switch
> statement is a bit more complicated, as its structure is too "flexible",
> with jumps at labels that may not respect scopes. Because of that a switch
> is *not* equivalent to a cascade of if-statements at least in the general
> case.
>
> Anyway, your proposal indicates a possibile solution but doesn't describe
> a real problem that the proposal is trying to solve. I am afraid but "It
> would be nice to have this..." is not a satisfactory description of real
> problem.
>

I think the use case and problem domain are quite well understood. consider
runtime-to-compile-time state dispatcher:

    auto disp = dispatcher
    {
        foo,
        bar,
        baz,
        [] { foo(); bar(); },
        [] { foo(); bar(); baz(); },
    };

    disp(4);  // execute foo(), bar(), baz()

(see the full working horror show here:
https://coliru.stacked-crooked.com/a/1cab88f58a218b02)

It would be very convenient (and much more readable) to be able to write:

for constexpr (std::size_t = 0 ; i < std::tuple_size_v(decltype(disp))
; ++i)
{
  if (i == which)                // if there is a match...
  {
    std::get<i>(disp)();         // ... dispatch the function. i is
constexpr
    break;                       // ... and exit the search early
  }
}
else
{
  // none of the iterations issued a break;
  throw std::invalid_argument("index too large: "s + std::to_string(which);
}

The advantages become more pronounced with the new hypothetical approach
when we consider that the dispatch is no longer limited to one argument or
return type. It can be easy selected on the basis of the (constexpr) value
of i.


> Alberto
>
>
> --
> 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/4fe7ab83-be8f-4f62-a1a4-72b39fb540d3%40isocpp.org
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/4fe7ab83-be8f-4f62-a1a4-72b39fb540d3%40isocpp.org?utm_medium=email&utm_source=footer>
> .
>


--
Richard Hodges
hodges.r@gmail.com
office: +442032898513
home: +376841522
mobile: +376380212 (this will be *expensive* outside Andorra!)
skype: madmongo
facebook: hodges.r

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

--000000000000fc6c9e057cf8f215
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><br><br><div class=3D"gm=
ail_quote"><div dir=3D"ltr">On Fri, 14 Dec 2018 at 16:20, Alberto Barbati &=
lt;<a href=3D"mailto:albertobarbati@gmail.com">albertobarbati@gmail.com</a>=
&gt; wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px =
0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div=
 dir=3D"ltr"><div>Hi Frank,</div><div><br></div><div>I believe you are miss=
ing the point of &quot;if constexpr&quot;. The real usefulness of &quot;if =
constexpr&quot; is that it makes the branch that is not selected a &quot;di=
scarded statement&quot; so that it doesn&#39;t trigger compilation errors i=
f it is ill-formed after template parameters substitution. In the case of t=
he for statement, that usefulness simply isn&#39;t there, because there&#39=
;s only one statement to consider, so either it is ill-formed for all itera=
tions or none of them. The idea of having the iteration variable constexpr =
is intriguing, but I&#39;m not totally sure that it has a real usefulness, =
especially after the introduction of consteval functions. The switch statem=
ent is a bit more complicated, as its structure is too &quot;flexible&quot;=
, with jumps at labels that may not respect scopes. Because of that a switc=
h is *not* equivalent to a cascade of if-statements at least in the general=
 case.</div><div><br></div><div>Anyway, your proposal indicates a possibile=
 solution but doesn&#39;t describe a real problem that the proposal is tryi=
ng to solve. I am afraid but &quot;<span style=3D"font-family:arial,sans-se=
rif">It would be nice to have this...&quot; is not a satisfactory descripti=
on of real problem.<br></span></div></div></blockquote><div><br></div><div>=
I think the use case and problem domain are quite well understood. consider=
 runtime-to-compile-time state dispatcher:</div><div><br></div><div><div><f=
ont face=3D"monospace, monospace">=C2=A0 =C2=A0 auto disp =3D dispatcher</f=
ont></div><div><font face=3D"monospace, monospace">=C2=A0 =C2=A0 {</font></=
div><div><font face=3D"monospace, monospace">=C2=A0 =C2=A0 =C2=A0 =C2=A0 fo=
o,</font></div><div><font face=3D"monospace, monospace">=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 bar,</font></div><div><font face=3D"monospace, monospace">=C2=A0=
 =C2=A0 =C2=A0 =C2=A0 baz,</font></div><div><font face=3D"monospace, monosp=
ace">=C2=A0 =C2=A0 =C2=A0 =C2=A0 [] { foo(); bar(); },</font></div><div><fo=
nt face=3D"monospace, monospace">=C2=A0 =C2=A0 =C2=A0 =C2=A0 [] { foo(); ba=
r(); baz(); },</font></div><div><font face=3D"monospace, monospace">=C2=A0 =
=C2=A0 };</font></div><div><font face=3D"monospace, monospace"><br></font><=
/div><div><span style=3D"font-family:monospace,monospace">=C2=A0 =C2=A0 dis=
p(4);=C2=A0 // execute foo(), bar(), baz()</span><br></div></div><div><br><=
/div><div>(see the full working horror show here:=C2=A0<a href=3D"https://c=
oliru.stacked-crooked.com/a/1cab88f58a218b02">https://coliru.stacked-crooke=
d.com/a/1cab88f58a218b02</a>)</div><div><br></div><div>It would be very con=
venient (and much more readable) to be able to write:</div><div><br></div><=
div><span style=3D"font-family:monospace,monospace">for constexpr (std::siz=
e_t =3D 0 ; i &lt; std::tuple_size_v(decltype(disp)) ;=C2=A0++i)</span><br>=
</div><div><font face=3D"monospace, monospace">{</font></div><div><font fac=
e=3D"monospace, monospace">=C2=A0 if (i =3D=3D which)=C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 // if there is a match...</font></div><d=
iv><font face=3D"monospace, monospace">=C2=A0 {</font></div><div><font face=
=3D"monospace, monospace">=C2=A0 =C2=A0 std::get&lt;i&gt;(disp)();=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0// ... dispatch the function. i is constexpr</fo=
nt></div><div><font face=3D"monospace, monospace">=C2=A0 =C2=A0 break;=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0// ... and exit the search early</font></div><div><font face=3D"monos=
pace, monospace">=C2=A0 }</font></div><div><font face=3D"monospace, monospa=
ce">}</font></div><div><font face=3D"monospace, monospace">else</font></div=
><div><font face=3D"monospace, monospace">{</font></div><div><font face=3D"=
monospace, monospace">=C2=A0 // none of the iterations issued a break;</fon=
t></div><div><span style=3D"font-family:monospace,monospace">=C2=A0 throw s=
td::invalid_argument(&quot;index too large: &quot;s=C2=A0+ std::to_string(w=
hich);</span><br></div><div><font face=3D"monospace, monospace">}</font></d=
iv><div>=C2=A0</div><div>The advantages become more pronounced with the new=
 hypothetical approach when we consider that the dispatch is no longer limi=
ted to one argument or return type. It can be easy selected on the basis of=
 the (constexpr) value of i.</div><div><br></div><blockquote class=3D"gmail=
_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204=
,204);padding-left:1ex"><div dir=3D"ltr"><div><span style=3D"font-family:ar=
ial,sans-serif"></span></div><div><span style=3D"font-family:arial,sans-ser=
if"><br></span></div><div><span style=3D"font-family:arial,sans-serif">Albe=
rto<br></span></div><br><br></div>

<p></p>

-- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org" 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/4fe7ab83-be8f-4f62-a1a4-72b39fb540d3%=
40isocpp.org?utm_medium=3Demail&amp;utm_source=3Dfooter" target=3D"_blank">=
https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/4fe7ab83-be8f-=
4f62-a1a4-72b39fb540d3%40isocpp.org</a>.<br>
</blockquote></div><br clear=3D"all"><div><br></div>-- <br><div dir=3D"ltr"=
 class=3D"gmail_signature"><div dir=3D"ltr">Richard Hodges<div><a href=3D"m=
ailto:hodges.r@gmail.com" target=3D"_blank">hodges.r@gmail.com</a></div><di=
v>office: +442032898513</div><div>home: +376841522</div><div>mobile:=C2=A0+=
376380212 (this will be *expensive* outside Andorra!)</div><div>skype: madm=
ongo</div><div>facebook: hodges.r</div><div><br></div></div></div></div></d=
iv></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CALvx3hbM2dPOgHh%3D2NvjhoC2kuv9doA9xW=
dVKJ2cT_upipRKfw%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">h=
ttps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CALvx3hbM2dPOgH=
h%3D2NvjhoC2kuv9doA9xWdVKJ2cT_upipRKfw%40mail.gmail.com</a>.<br />

--000000000000fc6c9e057cf8f215--

.


Author: Alberto Barbati <albertobarbati@gmail.com>
Date: Fri, 14 Dec 2018 03:33:23 -0800 (PST)
Raw View
------=_Part_769_1033389472.1544787204083
Content-Type: multipart/alternative;
 boundary="----=_Part_770_2052636479.1544787204083"

------=_Part_770_2052636479.1544787204083
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable


Il giorno venerd=C3=AC 14 dicembre 2018 11:32:36 UTC+1, Richard Hodges ha=
=20
scritto:
>
>
>     auto disp =3D dispatcher
>     {
>         foo,
>         bar,
>         baz,
>         [] { foo(); bar(); },
>         [] { foo(); bar(); baz(); },
>     };
>
>     disp(4);  // execute foo(), bar(), baz()
>
> (see the full working horror show here:=20
> https://coliru.stacked-crooked.com/a/1cab88f58a218b02)
>
> It would be very convenient (and much more readable) to be able to write:
>
> for constexpr (std::size_t =3D 0 ; i < std::tuple_size_v(decltype(disp))=
=20
> ; ++i)
> {
>   if (i =3D=3D which)                // if there is a match...
>   {
>     std::get<i>(disp)();         // ... dispatch the function. i is=20
> constexpr
>     break;                       // ... and exit the search early
>   }
> }
> else
> {
>   // none of the iterations issued a break;
>   throw std::invalid_argument("index too large: "s + std::to_string(which=
);
> }
> =20
> The advantages become more pronounced with the new hypothetical approach=
=20
> when we consider that the dispatch is no longer limited to one argument o=
r=20
> return type. It can be easy selected on the basis of the (constexpr) valu=
e=20
> of i.
>
>
I agree that this makes a valid and compelling use case for the=20
for-statement. However, in this particular case I believe the problem could=
=20
also be addressed with a library function able to iterate on the various=20
elements of a tuple. For example:

  /*std::*/for_each_tuple_element(disp, [which](size_t i, auto f)
    {
      if (i =3D=3D which) f();
    });

I believe such a function could be written using an approach similar to one=
=20
used in your link and might be worth considering for standardization.

--=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/564ef691-3176-47f9-bf98-c5917c03b3d8%40isocpp.or=
g.

------=_Part_770_2052636479.1544787204083
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br>Il giorno venerd=C3=AC 14 dicembre 2018 11:32:36 UTC+1=
, Richard Hodges ha scritto:<blockquote class=3D"gmail_quote" style=3D"marg=
in: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><d=
iv dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div class=3D"gmail_quote"=
><br><div><div><font face=3D"monospace, monospace">=C2=A0 =C2=A0 auto disp =
=3D dispatcher</font></div><div><font face=3D"monospace, monospace">=C2=A0 =
=C2=A0 {</font></div><div><font face=3D"monospace, monospace">=C2=A0 =C2=A0=
 =C2=A0 =C2=A0 foo,</font></div><div><font face=3D"monospace, monospace">=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 bar,</font></div><div><font face=3D"monospace, =
monospace">=C2=A0 =C2=A0 =C2=A0 =C2=A0 baz,</font></div><div><font face=3D"=
monospace, monospace">=C2=A0 =C2=A0 =C2=A0 =C2=A0 [] { foo(); bar(); },</fo=
nt></div><div><font face=3D"monospace, monospace">=C2=A0 =C2=A0 =C2=A0 =C2=
=A0 [] { foo(); bar(); baz(); },</font></div><div><font face=3D"monospace, =
monospace">=C2=A0 =C2=A0 };</font></div><div><font face=3D"monospace, monos=
pace"><br></font></div><div><span style=3D"font-family:monospace,monospace"=
>=C2=A0 =C2=A0 disp(4);=C2=A0 // execute foo(), bar(), baz()</span><br></di=
v></div><div><br></div><div>(see the full working horror show here:=C2=A0<a=
 href=3D"https://coliru.stacked-crooked.com/a/1cab88f58a218b02" target=3D"_=
blank" rel=3D"nofollow" onmousedown=3D"this.href=3D&#39;https://www.google.=
com/url?q\x3dhttps%3A%2F%2Fcoliru.stacked-crooked.com%2Fa%2F1cab88f58a218b0=
2\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH6NR3MNa2vC0-OpBdONerFRE8MMg&#39;=
;return true;" onclick=3D"this.href=3D&#39;https://www.google.com/url?q\x3d=
https%3A%2F%2Fcoliru.stacked-crooked.com%2Fa%2F1cab88f58a218b02\x26sa\x3dD\=
x26sntz\x3d1\x26usg\x3dAFQjCNH6NR3MNa2vC0-OpBdONerFRE8MMg&#39;;return true;=
">https://coliru.stacked-<wbr>crooked.com/a/1cab88f58a218b02</a><wbr>)</div=
><div><br></div><div>It would be very convenient (and much more readable) t=
o be able to write:</div><div><br></div><div><span style=3D"font-family:mon=
ospace,monospace">for constexpr (std::size_t =3D 0 ; i &lt; std::tuple_size=
_v(decltype(<wbr>disp)) ;=C2=A0++i)</span><br></div><div><font face=3D"mono=
space, monospace">{</font></div><div><font face=3D"monospace, monospace">=
=C2=A0 if (i =3D=3D which)=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 // if there is a match...</font></div><div><font face=3D"monospace, =
monospace">=C2=A0 {</font></div><div><font face=3D"monospace, monospace">=
=C2=A0 =C2=A0 std::get&lt;i&gt;(disp)();=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0/=
/ ... dispatch the function. i is constexpr</font></div><div><font face=3D"=
monospace, monospace">=C2=A0 =C2=A0 break;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0// ... and exit the sea=
rch early</font></div><div><font face=3D"monospace, monospace">=C2=A0 }</fo=
nt></div><div><font face=3D"monospace, monospace">}</font></div><div><font =
face=3D"monospace, monospace">else</font></div><div><font face=3D"monospace=
, monospace">{</font></div><div><font face=3D"monospace, monospace">=C2=A0 =
// none of the iterations issued a break;</font></div><div><span style=3D"f=
ont-family:monospace,monospace">=C2=A0 throw std::invalid_argument(&quot;in=
dex too large: &quot;s=C2=A0+ std::to_string(which);</span><br></div><div><=
font face=3D"monospace, monospace">}</font></div><div>=C2=A0</div><div>The =
advantages become more pronounced with the new hypothetical approach when w=
e consider that the dispatch is no longer limited to one argument or return=
 type. It can be easy selected on the basis of the (constexpr) value of i.<=
/div><div><br></div></div></div></div></div></blockquote><div><br></div><di=
v>I agree that this makes a valid and compelling use case for the for-state=
ment. However, in this particular case I believe the problem could also be =
addressed with a library function able to iterate on the various elements o=
f a tuple. For example:</div><div><br></div><div><div style=3D"background-c=
olor: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style: s=
olid; border-width: 1px; overflow-wrap: break-word;" class=3D"prettyprint">=
<code class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify">=C2=A0 </span><span style=3D"color=
: #800;" class=3D"styled-by-prettify">/*std::*/</span><span style=3D"color:=
 #000;" class=3D"styled-by-prettify">for_each_tuple_element</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify">disp</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">[</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify">which</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">](</span><span style=3D"color: #000;" class=3D"styled-by-prettify">size_t=
 i</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span sty=
le=3D"color: #008;" class=3D"styled-by-prettify">auto</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> f</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 </span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 </span><span style=3D"col=
or: #008;" class=3D"styled-by-prettify">if</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify">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"> which</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> f</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">();</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">});</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br></span></div></code>=
</div><span style=3D"font-family:monospace,monospace"><br></span><span styl=
e=3D"font-family: arial, sans-serif;">I believe such a function could be wr=
itten using an approach similar to one used in your link and might be worth=
 considering for standardization.</span><span style=3D"font-family:monospac=
e,monospace"><br></span></div><div><span style=3D"font-family:monospace,mon=
ospace"><br></span></div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/564ef691-3176-47f9-bf98-c5917c03b3d8%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/564ef691-3176-47f9-bf98-c5917c03b3d8=
%40isocpp.org</a>.<br />

------=_Part_770_2052636479.1544787204083--

------=_Part_769_1033389472.1544787204083--

.


Author: Richard Hodges <hodges.r@gmail.com>
Date: Fri, 14 Dec 2018 17:06:33 +0100
Raw View
--000000000000546245057cfd9e21
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

On Fri, 14 Dec 2018, 12:33 Alberto Barbati <albertobarbati@gmail.com wrote:

>
> Il giorno venerd=C3=AC 14 dicembre 2018 11:32:36 UTC+1, Richard Hodges ha
> scritto:
>>
>>
>>     auto disp =3D dispatcher
>>     {
>>         foo,
>>         bar,
>>         baz,
>>         [] { foo(); bar(); },
>>         [] { foo(); bar(); baz(); },
>>     };
>>
>>     disp(4);  // execute foo(), bar(), baz()
>>
>> (see the full working horror show here:
>> https://coliru.stacked-crooked.com/a/1cab88f58a218b02)
>>
>> It would be very convenient (and much more readable) to be able to write=
:
>>
>> for constexpr (std::size_t =3D 0 ; i < std::tuple_size_v(decltype(disp))
>> ; ++i)
>> {
>>   if (i =3D=3D which)                // if there is a match...
>>   {
>>     std::get<i>(disp)();         // ... dispatch the function. i is
>> constexpr
>>     break;                       // ... and exit the search early
>>   }
>> }
>> else
>> {
>>   // none of the iterations issued a break;
>>   throw std::invalid_argument("index too large: "s +
>> std::to_string(which);
>> }
>>
>> The advantages become more pronounced with the new hypothetical approach
>> when we consider that the dispatch is no longer limited to one argument =
or
>> return type. It can be easy selected on the basis of the (constexpr) val=
ue
>> of i.
>>
>>
> I agree that this makes a valid and compelling use case for the
> for-statement. However, in this particular case I believe the problem cou=
ld
> also be addressed with a library function able to iterate on the various
> elements of a tuple. For example:
>
>   /*std::*/for_each_tuple_element(disp, [which](size_t i, auto f)
>     {
>       if (i =3D=3D which) f();
>     });
>
> I believe such a function could be written using an approach similar to
> one used in your link and might be worth considering for standardization.
>

Such a function can be implemented by wrapping an expansion of std::invoke
in a lambda called by std::apply. The problems are:

1. It does not detect the no-match case.
2. Return types have to be the same/compatible
3. ** It's not easy to read **

Compile time stuff needs to be childs play to be useful, and c++ is almost
there.

There's no reason why compile time meta programs should look any different
to runtime programs.


>
> --
> 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/564ef691-317=
6-47f9-bf98-c5917c03b3d8%40isocpp.org
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/564ef691-31=
76-47f9-bf98-c5917c03b3d8%40isocpp.org?utm_medium=3Demail&utm_source=3Dfoot=
er>
> .
>

--=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/CALvx3hZJ-S_Ai4BzuCUCKTc72R3oSpfLoJ%3DYpFsPsUKst=
2CS%2BQ%40mail.gmail.com.

--000000000000546245057cfd9e21
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 Fri, 14 Dec 2018, 12:33 Alberto Barbati &lt;<a href=3D"mailto:albertobar=
bati@gmail.com">albertobarbati@gmail.com</a> wrote:<br></div><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"><br>Il giorno venerd=C3=AC 14 dicembre 20=
18 11:32:36 UTC+1, Richard Hodges ha scritto:<blockquote class=3D"gmail_quo=
te" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-=
left:1ex"><div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div class=3D"=
gmail_quote"><br><div><div><font face=3D"monospace, monospace">=C2=A0 =C2=
=A0 auto disp =3D dispatcher</font></div><div><font face=3D"monospace, mono=
space">=C2=A0 =C2=A0 {</font></div><div><font face=3D"monospace, monospace"=
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 foo,</font></div><div><font face=3D"monospace,=
 monospace">=C2=A0 =C2=A0 =C2=A0 =C2=A0 bar,</font></div><div><font face=3D=
"monospace, monospace">=C2=A0 =C2=A0 =C2=A0 =C2=A0 baz,</font></div><div><f=
ont face=3D"monospace, monospace">=C2=A0 =C2=A0 =C2=A0 =C2=A0 [] { foo(); b=
ar(); },</font></div><div><font face=3D"monospace, monospace">=C2=A0 =C2=A0=
 =C2=A0 =C2=A0 [] { foo(); bar(); baz(); },</font></div><div><font face=3D"=
monospace, monospace">=C2=A0 =C2=A0 };</font></div><div><font face=3D"monos=
pace, monospace"><br></font></div><div><span style=3D"font-family:monospace=
,monospace">=C2=A0 =C2=A0 disp(4);=C2=A0 // execute foo(), bar(), baz()</sp=
an><br></div></div><div><br></div><div>(see the full working horror show he=
re:=C2=A0<a href=3D"https://coliru.stacked-crooked.com/a/1cab88f58a218b02" =
rel=3D"nofollow noreferrer" target=3D"_blank">https://coliru.stacked-crooke=
d.com/a/1cab88f58a218b02</a>)</div><div><br></div><div>It would be very con=
venient (and much more readable) to be able to write:</div><div><br></div><=
div><span style=3D"font-family:monospace,monospace">for constexpr (std::siz=
e_t =3D 0 ; i &lt; std::tuple_size_v(decltype(disp)) ;=C2=A0++i)</span><br>=
</div><div><font face=3D"monospace, monospace">{</font></div><div><font fac=
e=3D"monospace, monospace">=C2=A0 if (i =3D=3D which)=C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 // if there is a match...</font></div><d=
iv><font face=3D"monospace, monospace">=C2=A0 {</font></div><div><font face=
=3D"monospace, monospace">=C2=A0 =C2=A0 std::get&lt;i&gt;(disp)();=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0// ... dispatch the function. i is constexpr</fo=
nt></div><div><font face=3D"monospace, monospace">=C2=A0 =C2=A0 break;=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0// ... and exit the search early</font></div><div><font face=3D"monos=
pace, monospace">=C2=A0 }</font></div><div><font face=3D"monospace, monospa=
ce">}</font></div><div><font face=3D"monospace, monospace">else</font></div=
><div><font face=3D"monospace, monospace">{</font></div><div><font face=3D"=
monospace, monospace">=C2=A0 // none of the iterations issued a break;</fon=
t></div><div><span style=3D"font-family:monospace,monospace">=C2=A0 throw s=
td::invalid_argument(&quot;index too large: &quot;s=C2=A0+ std::to_string(w=
hich);</span><br></div><div><font face=3D"monospace, monospace">}</font></d=
iv><div>=C2=A0</div><div>The advantages become more pronounced with the new=
 hypothetical approach when we consider that the dispatch is no longer limi=
ted to one argument or return type. It can be easy selected on the basis of=
 the (constexpr) value of i.</div><div><br></div></div></div></div></div></=
blockquote><div><br></div><div>I agree that this makes a valid and compelli=
ng use case for the for-statement. However, in this particular case I belie=
ve the problem could also be addressed with a library function able to iter=
ate on the various elements of a tuple. For example:</div><div><br></div><d=
iv><div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187=
,187);border-style:solid;border-width:1px" class=3D"m_-3087687008519716955p=
rettyprint"><code class=3D"m_-3087687008519716955prettyprint"><div class=3D=
"m_-3087687008519716955subprettyprint"><span style=3D"color:#000" class=3D"=
m_-3087687008519716955styled-by-prettify">=C2=A0 </span><span style=3D"colo=
r:#800" class=3D"m_-3087687008519716955styled-by-prettify">/*std::*/</span>=
<span style=3D"color:#000" class=3D"m_-3087687008519716955styled-by-prettif=
y">for_each_tuple_element</span><span style=3D"color:#660" class=3D"m_-3087=
687008519716955styled-by-prettify">(</span><span style=3D"color:#000" class=
=3D"m_-3087687008519716955styled-by-prettify">disp</span><span style=3D"col=
or:#660" class=3D"m_-3087687008519716955styled-by-prettify">,</span><span s=
tyle=3D"color:#000" class=3D"m_-3087687008519716955styled-by-prettify"> </s=
pan><span style=3D"color:#660" class=3D"m_-3087687008519716955styled-by-pre=
ttify">[</span><span style=3D"color:#000" class=3D"m_-3087687008519716955st=
yled-by-prettify">which</span><span style=3D"color:#660" class=3D"m_-308768=
7008519716955styled-by-prettify">](</span><span style=3D"color:#000" class=
=3D"m_-3087687008519716955styled-by-prettify">size_t i</span><span style=3D=
"color:#660" class=3D"m_-3087687008519716955styled-by-prettify">,</span><sp=
an style=3D"color:#000" class=3D"m_-3087687008519716955styled-by-prettify">=
 </span><span style=3D"color:#008" class=3D"m_-3087687008519716955styled-by=
-prettify">auto</span><span style=3D"color:#000" class=3D"m_-30876870085197=
16955styled-by-prettify"> f</span><span style=3D"color:#660" class=3D"m_-30=
87687008519716955styled-by-prettify">)</span><span style=3D"color:#000" cla=
ss=3D"m_-3087687008519716955styled-by-prettify"><br>=C2=A0 =C2=A0 </span><s=
pan style=3D"color:#660" class=3D"m_-3087687008519716955styled-by-prettify"=
>{</span><span style=3D"color:#000" class=3D"m_-3087687008519716955styled-b=
y-prettify"><br>=C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#008" clas=
s=3D"m_-3087687008519716955styled-by-prettify">if</span><span style=3D"colo=
r:#000" class=3D"m_-3087687008519716955styled-by-prettify"> </span><span st=
yle=3D"color:#660" class=3D"m_-3087687008519716955styled-by-prettify">(</sp=
an><span style=3D"color:#000" class=3D"m_-3087687008519716955styled-by-pret=
tify">i </span><span style=3D"color:#660" class=3D"m_-3087687008519716955st=
yled-by-prettify">=3D=3D</span><span style=3D"color:#000" class=3D"m_-30876=
87008519716955styled-by-prettify"> which</span><span style=3D"color:#660" c=
lass=3D"m_-3087687008519716955styled-by-prettify">)</span><span style=3D"co=
lor:#000" class=3D"m_-3087687008519716955styled-by-prettify"> f</span><span=
 style=3D"color:#660" class=3D"m_-3087687008519716955styled-by-prettify">()=
;</span><span style=3D"color:#000" class=3D"m_-3087687008519716955styled-by=
-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#660" class=3D"m_-=
3087687008519716955styled-by-prettify">});</span><span style=3D"color:#000"=
 class=3D"m_-3087687008519716955styled-by-prettify"><br></span></div></code=
></div><span style=3D"font-family:monospace,monospace"><br></span><span sty=
le=3D"font-family:arial,sans-serif">I believe such a function could be writ=
ten using an approach similar to one used in your link and might be worth c=
onsidering for standardization.</span></div></div></blockquote></div></div>=
<div dir=3D"auto"><br></div><div dir=3D"auto">Such a function can be implem=
ented by wrapping an expansion of std::invoke in a lambda called by std::ap=
ply. The problems are:</div><div dir=3D"auto"><br></div><div dir=3D"auto">1=
.. It does not detect the no-match case.</div><div dir=3D"auto">2. Return ty=
pes have to be the same/compatible=C2=A0</div><div dir=3D"auto">3. ** It&#3=
9;s not easy to read **</div><div dir=3D"auto"><br></div><div dir=3D"auto">=
Compile time stuff needs to be childs play to be useful, and c++ is almost =
there.</div><div dir=3D"auto"><br></div><div dir=3D"auto">There&#39;s no re=
ason why compile time meta programs should look any different to runtime pr=
ograms.</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><span style=
=3D"font-family:monospace,monospace"><br></span></div><div><span style=3D"f=
ont-family:monospace,monospace"><br></span></div></div>

<p></p>

-- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org" target=3D"_=
blank" rel=3D"noreferrer">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" rel=3D"noreferrer">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/564ef691-3176-47f9-bf98-c5917c03b3d8%=
40isocpp.org?utm_medium=3Demail&amp;utm_source=3Dfooter" target=3D"_blank" =
rel=3D"noreferrer">https://groups.google.com/a/isocpp.org/d/msgid/std-propo=
sals/564ef691-3176-47f9-bf98-c5917c03b3d8%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&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CALvx3hZJ-S_Ai4BzuCUCKTc72R3oSpfLoJ%3=
DYpFsPsUKst2CS%2BQ%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CALvx3hZJ-S_A=
i4BzuCUCKTc72R3oSpfLoJ%3DYpFsPsUKst2CS%2BQ%40mail.gmail.com</a>.<br />

--000000000000546245057cfd9e21--

.


Author: Jake Arkinstall <jake.arkinstall@gmail.com>
Date: Fri, 14 Dec 2018 16:24:50 +0000
Raw View
--00000000000080dbb8057cfddf11
Content-Type: text/plain; charset="UTF-8"

On Fri, 14 Dec 2018, 16:06 Richard Hodges <hodges.r@gmail.com wrote:

> I agree that this makes a valid and compelling use case for the
>> for-statement. However, in this particular case I believe the problem could
>> also be addressed with a library function able to iterate on the various
>> elements of a tuple. For example:
>>
>>   /*std::*/for_each_tuple_element(disp, [which](size_t i, auto f)
>>     {
>>       if (i == which) f();
>>     });
>>
>> I believe such a function could be written using an approach similar to
>> one used in your link and might be worth considering for standardization.
>>
>
> Such a function can be implemented by wrapping an expansion of std::invoke
> in a lambda called by std::apply. The problems are:
>
> 1. It does not detect the no-match case.
> 2. Return types have to be the same/compatible
> 3. ** It's not easy to read **
>
4. Less control flow - no "break".


> Compile time stuff needs to be childs play to be useful, and c++ is almost
> there.
>

Agreed. I use tuples heavily and I get an unreasonable amount of
satisfaction whenever I implement something that should have been trivial.
It should be easier. The standard library currently provides enough tuple
utilities to be able to cut the code for a trivial operation (e.g. A map
from a tuple to another) from 100 lines to 50, but we're really missing out
on some nice high level features.

The route that the library is going down is never going to be easily usable
by your everyday C++ dev, and that's simply because the language isn't
built for it at the moment. A compile time for loop is something I strongly
support.

I do not support claims that there will be trouble if a type in the tuple
doesn't support an attempted operation - the loop unrolls and should act
like any code that was written sequentially instead (plus jump labels). If
it causes an error, it causes an error. It would be nice if we can have a
type that represents a tuple of types that all share a common concept.


> There's no reason why compile time meta programs should look any different
> to runtime programs.
>

Again, I agree.

--
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/CAC%2B0CCO64OLWVF6eSwXESWCXf0vrjv5Z2zeCX3hRLMsc%2B-C3jg%40mail.gmail.com.

--00000000000080dbb8057cfddf11
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"auto"><div class=3D"gmail_quote" dir=3D"auto"><div dir=3D"ltr">=
On Fri, 14 Dec 2018, 16:06 Richard Hodges &lt;<a href=3D"mailto:hodges.r@gm=
ail.com">hodges.r@gmail.com</a> wrote:<br></div><blockquote class=3D"gmail_=
quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1=
ex"><div dir=3D"auto"><div><div class=3D"gmail_quote"><blockquote class=3D"=
gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-=
left:1ex"><div dir=3D"ltr"><div>I agree that this makes a valid and compell=
ing use case for the for-statement. However, in this particular case I beli=
eve the problem could also be addressed with a library function able to ite=
rate on the various elements of a tuple. For example:</div><div><br></div><=
div><div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,18=
7,187);border-style:solid;border-width:1px" class=3D"m_4057127474006082718m=
_-3087687008519716955prettyprint"><code class=3D"m_4057127474006082718m_-30=
87687008519716955prettyprint"><div class=3D"m_4057127474006082718m_-3087687=
008519716955subprettyprint"><span style=3D"color:#000" class=3D"m_405712747=
4006082718m_-3087687008519716955styled-by-prettify">=C2=A0 </span><span sty=
le=3D"color:#800" class=3D"m_4057127474006082718m_-3087687008519716955style=
d-by-prettify">/*std::*/</span><span style=3D"color:#000" class=3D"m_405712=
7474006082718m_-3087687008519716955styled-by-prettify">for_each_tuple_eleme=
nt</span><span style=3D"color:#660" class=3D"m_4057127474006082718m_-308768=
7008519716955styled-by-prettify">(</span><span style=3D"color:#000" class=
=3D"m_4057127474006082718m_-3087687008519716955styled-by-prettify">disp</sp=
an><span style=3D"color:#660" class=3D"m_4057127474006082718m_-308768700851=
9716955styled-by-prettify">,</span><span style=3D"color:#000" class=3D"m_40=
57127474006082718m_-3087687008519716955styled-by-prettify"> </span><span st=
yle=3D"color:#660" class=3D"m_4057127474006082718m_-3087687008519716955styl=
ed-by-prettify">[</span><span style=3D"color:#000" class=3D"m_4057127474006=
082718m_-3087687008519716955styled-by-prettify">which</span><span style=3D"=
color:#660" class=3D"m_4057127474006082718m_-3087687008519716955styled-by-p=
rettify">](</span><span style=3D"color:#000" class=3D"m_4057127474006082718=
m_-3087687008519716955styled-by-prettify">size_t i</span><span style=3D"col=
or:#660" class=3D"m_4057127474006082718m_-3087687008519716955styled-by-pret=
tify">,</span><span style=3D"color:#000" class=3D"m_4057127474006082718m_-3=
087687008519716955styled-by-prettify"> </span><span style=3D"color:#008" cl=
ass=3D"m_4057127474006082718m_-3087687008519716955styled-by-prettify">auto<=
/span><span style=3D"color:#000" class=3D"m_4057127474006082718m_-308768700=
8519716955styled-by-prettify"> f</span><span style=3D"color:#660" class=3D"=
m_4057127474006082718m_-3087687008519716955styled-by-prettify">)</span><spa=
n style=3D"color:#000" class=3D"m_4057127474006082718m_-3087687008519716955=
styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#660" cla=
ss=3D"m_4057127474006082718m_-3087687008519716955styled-by-prettify">{</spa=
n><span style=3D"color:#000" class=3D"m_4057127474006082718m_-3087687008519=
716955styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 </span><span style=3D"co=
lor:#008" class=3D"m_4057127474006082718m_-3087687008519716955styled-by-pre=
ttify">if</span><span style=3D"color:#000" class=3D"m_4057127474006082718m_=
-3087687008519716955styled-by-prettify"> </span><span style=3D"color:#660" =
class=3D"m_4057127474006082718m_-3087687008519716955styled-by-prettify">(</=
span><span style=3D"color:#000" class=3D"m_4057127474006082718m_-3087687008=
519716955styled-by-prettify">i </span><span style=3D"color:#660" class=3D"m=
_4057127474006082718m_-3087687008519716955styled-by-prettify">=3D=3D</span>=
<span style=3D"color:#000" class=3D"m_4057127474006082718m_-308768700851971=
6955styled-by-prettify"> which</span><span style=3D"color:#660" class=3D"m_=
4057127474006082718m_-3087687008519716955styled-by-prettify">)</span><span =
style=3D"color:#000" class=3D"m_4057127474006082718m_-3087687008519716955st=
yled-by-prettify"> f</span><span style=3D"color:#660" class=3D"m_4057127474=
006082718m_-3087687008519716955styled-by-prettify">();</span><span style=3D=
"color:#000" class=3D"m_4057127474006082718m_-3087687008519716955styled-by-=
prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#660" class=3D"m_40=
57127474006082718m_-3087687008519716955styled-by-prettify">});</span><span =
style=3D"color:#000" class=3D"m_4057127474006082718m_-3087687008519716955st=
yled-by-prettify"><br></span></div></code></div><span style=3D"font-family:=
monospace,monospace"><br></span><span style=3D"font-family:arial,sans-serif=
">I believe such a function could be written using an approach similar to o=
ne used in your link and might be worth considering for standardization.</s=
pan></div></div></blockquote></div></div><div dir=3D"auto"><br></div><div d=
ir=3D"auto">Such a function can be implemented by wrapping an expansion of =
std::invoke in a lambda called by std::apply. The problems are:</div><div d=
ir=3D"auto"><br></div><div dir=3D"auto">1. It does not detect the no-match =
case.</div><div dir=3D"auto">2. Return types have to be the same/compatible=
=C2=A0</div><div dir=3D"auto">3. ** It&#39;s not easy to read **</div></div=
></blockquote></div><div dir=3D"auto">4. Less control flow - no &quot;break=
&quot;.</div><div dir=3D"auto"><br></div><div class=3D"gmail_quote" dir=3D"=
auto"><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-l=
eft:1px #ccc solid;padding-left:1ex"><div dir=3D"auto"><div dir=3D"auto"><b=
r></div><div dir=3D"auto">Compile time stuff needs to be childs play to be =
useful, and c++ is almost there.</div></div></blockquote></div><div dir=3D"=
auto"><br></div><div class=3D"gmail_quote" dir=3D"auto"></div><div dir=3D"a=
uto">Agreed. I use tuples heavily and I get an unreasonable amount of satis=
faction whenever I implement something that should have been trivial. It sh=
ould be easier. The standard library currently provides enough tuple utilit=
ies to be able to cut the code for a trivial operation (e.g. A map from a t=
uple to another) from 100 lines to 50, but we&#39;re really missing out on =
some nice high level features.</div><div dir=3D"auto"><br></div><div dir=3D=
"auto">The route that the library is going down is never going to be easily=
 usable by your everyday C++ dev, and that&#39;s simply because the languag=
e isn&#39;t built for it at the moment. A compile time for loop is somethin=
g I strongly support.</div><div dir=3D"auto"><br></div><div dir=3D"auto">I =
do not support claims that there will be trouble if a type in the tuple doe=
sn&#39;t support an attempted operation - the loop unrolls and should act l=
ike any code that was written sequentially instead (plus jump labels). If i=
t causes an error, it causes an error. It would be nice if we can have a ty=
pe that represents a tuple of types that all share a common concept.</div><=
div dir=3D"auto"><br></div><div class=3D"gmail_quote" dir=3D"auto"><blockqu=
ote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc s=
olid;padding-left:1ex"><div dir=3D"auto"><div dir=3D"auto"><br></div><div d=
ir=3D"auto">There&#39;s no reason why compile time meta programs should loo=
k any different to runtime programs.</div></div></blockquote></div><div dir=
=3D"auto"><br></div><div dir=3D"auto">Again, I agree.</div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAC%2B0CCO64OLWVF6eSwXESWCXf0vrjv5Z2z=
eCX3hRLMsc%2B-C3jg%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAC%2B0CCO64O=
LWVF6eSwXESWCXf0vrjv5Z2zeCX3hRLMsc%2B-C3jg%40mail.gmail.com</a>.<br />

--00000000000080dbb8057cfddf11--

.